diff options
author | Ben Johnson <benbjohnson@yahoo.com> | 2014-07-26 17:17:03 -0600 |
---|---|---|
committer | Ben Johnson <benbjohnson@yahoo.com> | 2014-07-26 17:17:03 -0600 |
commit | 44e6192d2bdecf1336e372686f15417ed98c4b16 (patch) | |
tree | 3a51074bfdd1275706f4d550392280efb93bee18 /cmd | |
parent | Move tests to a test package. (diff) | |
download | dedo-44e6192d2bdecf1336e372686f15417ed98c4b16.tar.gz dedo-44e6192d2bdecf1336e372686f15417ed98c4b16.tar.xz |
Remove testify.
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/bolt/buckets_test.go | 5 | ||||
-rw-r--r-- | cmd/bolt/export_test.go | 5 | ||||
-rw-r--r-- | cmd/bolt/get_test.go | 9 | ||||
-rw-r--r-- | cmd/bolt/import_test.go | 27 | ||||
-rw-r--r-- | cmd/bolt/info_test.go | 5 | ||||
-rw-r--r-- | cmd/bolt/keys_test.go | 7 | ||||
-rw-r--r-- | cmd/bolt/main_test.go | 32 | ||||
-rw-r--r-- | cmd/bolt/stats_test.go | 3 |
8 files changed, 58 insertions, 35 deletions
diff --git a/cmd/bolt/buckets_test.go b/cmd/bolt/buckets_test.go index 27ee619..d5050fd 100644 --- a/cmd/bolt/buckets_test.go +++ b/cmd/bolt/buckets_test.go @@ -5,7 +5,6 @@ import ( "github.com/boltdb/bolt" . "github.com/boltdb/bolt/cmd/bolt" - "github.com/stretchr/testify/assert" ) // Ensure that a list of buckets can be retrieved. @@ -20,7 +19,7 @@ func TestBuckets(t *testing.T) { }) db.Close() output := run("buckets", path) - assert.Equal(t, "whatchits\nwidgets\nwoojits", output) + equals(t, "whatchits\nwidgets\nwoojits", output) }) } @@ -28,5 +27,5 @@ func TestBuckets(t *testing.T) { func TestBucketsDBNotFound(t *testing.T) { SetTestMode(true) output := run("buckets", "no/such/db") - assert.Equal(t, "stat no/such/db: no such file or directory", output) + equals(t, "stat no/such/db: no such file or directory", output) } diff --git a/cmd/bolt/export_test.go b/cmd/bolt/export_test.go index 13f57d1..d98403c 100644 --- a/cmd/bolt/export_test.go +++ b/cmd/bolt/export_test.go @@ -5,7 +5,6 @@ import ( "github.com/boltdb/bolt" . "github.com/boltdb/bolt/cmd/bolt" - "github.com/stretchr/testify/assert" ) // Ensure that a database can be exported. @@ -32,7 +31,7 @@ func TestExport(t *testing.T) { }) db.Close() output := run("export", path) - assert.Equal(t, `[{"type":"bucket","key":"ZW1wdHk=","value":[]},{"type":"bucket","key":"d2lkZ2V0cw==","value":[{"key":"YmFy","value":""},{"key":"Zm9v","value":"MDAwMA=="}]},{"type":"bucket","key":"d29vaml0cw==","value":[{"key":"YmF6","value":"WFhYWA=="},{"type":"bucket","key":"d29vaml0cy9zdWJidWNrZXQ=","value":[{"key":"YmF0","value":"QQ=="}]}]}]`, output) + equals(t, `[{"type":"bucket","key":"ZW1wdHk=","value":[]},{"type":"bucket","key":"d2lkZ2V0cw==","value":[{"key":"YmFy","value":""},{"key":"Zm9v","value":"MDAwMA=="}]},{"type":"bucket","key":"d29vaml0cw==","value":[{"key":"YmF6","value":"WFhYWA=="},{"type":"bucket","key":"d29vaml0cy9zdWJidWNrZXQ=","value":[{"key":"YmF0","value":"QQ=="}]}]}]`, output) }) } @@ -40,5 +39,5 @@ func TestExport(t *testing.T) { func TestExport_NotFound(t *testing.T) { SetTestMode(true) output := run("export", "no/such/db") - assert.Equal(t, "stat no/such/db: no such file or directory", output) + equals(t, "stat no/such/db: no such file or directory", output) } diff --git a/cmd/bolt/get_test.go b/cmd/bolt/get_test.go index 7b7c3a0..8acd0f4 100644 --- a/cmd/bolt/get_test.go +++ b/cmd/bolt/get_test.go @@ -5,7 +5,6 @@ import ( "github.com/boltdb/bolt" . "github.com/boltdb/bolt/cmd/bolt" - "github.com/stretchr/testify/assert" ) // Ensure that a value can be retrieved from the CLI. @@ -19,7 +18,7 @@ func TestGet(t *testing.T) { }) db.Close() output := run("get", path, "widgets", "foo") - assert.Equal(t, "bar", output) + equals(t, "bar", output) }) } @@ -27,7 +26,7 @@ func TestGet(t *testing.T) { func TestGetDBNotFound(t *testing.T) { SetTestMode(true) output := run("get", "no/such/db", "widgets", "foo") - assert.Equal(t, "stat no/such/db: no such file or directory", output) + equals(t, "stat no/such/db: no such file or directory", output) } // Ensure that an error is reported if the bucket is not found. @@ -36,7 +35,7 @@ func TestGetBucketNotFound(t *testing.T) { open(func(db *bolt.DB, path string) { db.Close() output := run("get", path, "widgets", "foo") - assert.Equal(t, "bucket not found: widgets", output) + equals(t, "bucket not found: widgets", output) }) } @@ -50,6 +49,6 @@ func TestGetKeyNotFound(t *testing.T) { }) db.Close() output := run("get", path, "widgets", "foo") - assert.Equal(t, "key not found: foo", output) + equals(t, "key not found: foo", output) }) } diff --git a/cmd/bolt/import_test.go b/cmd/bolt/import_test.go index 3d4f275..086bf03 100644 --- a/cmd/bolt/import_test.go +++ b/cmd/bolt/import_test.go @@ -6,7 +6,6 @@ import ( "github.com/boltdb/bolt" . "github.com/boltdb/bolt/cmd/bolt" - "github.com/stretchr/testify/assert" ) // Ensure that a database can be imported. @@ -15,32 +14,30 @@ func TestImport(t *testing.T) { // Write input file. input := tempfile() - assert.NoError(t, ioutil.WriteFile(input, []byte(`[{"type":"bucket","key":"ZW1wdHk=","value":[]},{"type":"bucket","key":"d2lkZ2V0cw==","value":[{"key":"YmFy","value":""},{"key":"Zm9v","value":"MDAwMA=="}]},{"type":"bucket","key":"d29vaml0cw==","value":[{"key":"YmF6","value":"WFhYWA=="},{"type":"bucket","key":"d29vaml0cy9zdWJidWNrZXQ=","value":[{"key":"YmF0","value":"QQ=="}]}]}]`), 0600)) + ok(t, ioutil.WriteFile(input, []byte(`[{"type":"bucket","key":"ZW1wdHk=","value":[]},{"type":"bucket","key":"d2lkZ2V0cw==","value":[{"key":"YmFy","value":""},{"key":"Zm9v","value":"MDAwMA=="}]},{"type":"bucket","key":"d29vaml0cw==","value":[{"key":"YmF6","value":"WFhYWA=="},{"type":"bucket","key":"d29vaml0cy9zdWJidWNrZXQ=","value":[{"key":"YmF0","value":"QQ=="}]}]}]`), 0600)) // Import database. path := tempfile() output := run("import", path, "--input", input) - assert.Equal(t, ``, output) + equals(t, ``, output) // Open database and verify contents. db, err := bolt.Open(path, 0600, nil) - assert.NoError(t, err) + ok(t, err) db.View(func(tx *bolt.Tx) error { - assert.NotNil(t, tx.Bucket([]byte("empty"))) + assert(t, tx.Bucket([]byte("empty")) != nil, "") b := tx.Bucket([]byte("widgets")) - if assert.NotNil(t, b) { - assert.Equal(t, []byte("0000"), b.Get([]byte("foo"))) - assert.Equal(t, []byte(""), b.Get([]byte("bar"))) - } + assert(t, b != nil, "") + equals(t, []byte("0000"), b.Get([]byte("foo"))) + equals(t, []byte(""), b.Get([]byte("bar"))) b = tx.Bucket([]byte("woojits")) - if assert.NotNil(t, b) { - assert.Equal(t, []byte("XXXX"), b.Get([]byte("baz"))) + assert(t, b != nil, "") + equals(t, []byte("XXXX"), b.Get([]byte("baz"))) - b = b.Bucket([]byte("woojits/subbucket")) - assert.Equal(t, []byte("A"), b.Get([]byte("bat"))) - } + b = b.Bucket([]byte("woojits/subbucket")) + equals(t, []byte("A"), b.Get([]byte("bat"))) return nil }) @@ -51,5 +48,5 @@ func TestImport(t *testing.T) { func TestImport_NotFound(t *testing.T) { SetTestMode(true) output := run("import", "path/to/db", "--input", "no/such/file") - assert.Equal(t, "open no/such/file: no such file or directory", output) + equals(t, "open no/such/file: no such file or directory", output) } diff --git a/cmd/bolt/info_test.go b/cmd/bolt/info_test.go index 668cc61..dab74f6 100644 --- a/cmd/bolt/info_test.go +++ b/cmd/bolt/info_test.go @@ -5,7 +5,6 @@ import ( "github.com/boltdb/bolt" . "github.com/boltdb/bolt/cmd/bolt" - "github.com/stretchr/testify/assert" ) // Ensure that a database info can be printed. @@ -20,7 +19,7 @@ func TestInfo(t *testing.T) { }) db.Close() output := run("info", path) - assert.Equal(t, `Page Size: 4096`, output) + equals(t, `Page Size: 4096`, output) }) } @@ -28,5 +27,5 @@ func TestInfo(t *testing.T) { func TestInfo_NotFound(t *testing.T) { SetTestMode(true) output := run("info", "no/such/db") - assert.Equal(t, "stat no/such/db: no such file or directory", output) + equals(t, "stat no/such/db: no such file or directory", output) } diff --git a/cmd/bolt/keys_test.go b/cmd/bolt/keys_test.go index 2b5a9a0..0cc4e0c 100644 --- a/cmd/bolt/keys_test.go +++ b/cmd/bolt/keys_test.go @@ -5,7 +5,6 @@ import ( "github.com/boltdb/bolt" . "github.com/boltdb/bolt/cmd/bolt" - "github.com/stretchr/testify/assert" ) // Ensure that a list of keys can be retrieved for a given bucket. @@ -21,7 +20,7 @@ func TestKeys(t *testing.T) { }) db.Close() output := run("keys", path, "widgets") - assert.Equal(t, "0001\n0002\n0003", output) + equals(t, "0001\n0002\n0003", output) }) } @@ -29,7 +28,7 @@ func TestKeys(t *testing.T) { func TestKeysDBNotFound(t *testing.T) { SetTestMode(true) output := run("keys", "no/such/db", "widgets") - assert.Equal(t, "stat no/such/db: no such file or directory", output) + equals(t, "stat no/such/db: no such file or directory", output) } // Ensure that an error is reported if the bucket is not found. @@ -38,6 +37,6 @@ func TestKeysBucketNotFound(t *testing.T) { open(func(db *bolt.DB, path string) { db.Close() output := run("keys", path, "widgets") - assert.Equal(t, "bucket not found: widgets", output) + equals(t, "bucket not found: widgets", output) }) } diff --git a/cmd/bolt/main_test.go b/cmd/bolt/main_test.go index 0614d43..4448d6e 100644 --- a/cmd/bolt/main_test.go +++ b/cmd/bolt/main_test.go @@ -1,9 +1,14 @@ package main_test import ( + "fmt" "io/ioutil" "os" + "path/filepath" + "reflect" + "runtime" "strings" + "testing" "github.com/boltdb/bolt" . "github.com/boltdb/bolt/cmd/bolt" @@ -35,3 +40,30 @@ func tempfile() string { os.Remove(f.Name()) return f.Name() } + +// assert fails the test if the condition is false. +func assert(tb testing.TB, condition bool, msg string, v ...interface{}) { + if !condition { + _, file, line, _ := runtime.Caller(1) + fmt.Printf("\033[31m%s:%d: "+msg+"\033[39m\n\n", append([]interface{}{filepath.Base(file), line}, v...)...) + tb.FailNow() + } +} + +// ok fails the test if an err is not nil. +func ok(tb testing.TB, err error) { + if err != nil { + _, file, line, _ := runtime.Caller(1) + fmt.Printf("\033[31m%s:%d: unexpected error: %s\033[39m\n\n", filepath.Base(file), line, err.Error()) + tb.FailNow() + } +} + +// equals fails the test if exp is not equal to act. +func equals(tb testing.TB, exp, act interface{}) { + if !reflect.DeepEqual(exp, act) { + _, file, line, _ := runtime.Caller(1) + fmt.Printf("\033[31m%s:%d:\n\n\texp: %#v\n\n\tgot: %#v\033[39m\n\n", filepath.Base(file), line, exp, act) + tb.FailNow() + } +} diff --git a/cmd/bolt/stats_test.go b/cmd/bolt/stats_test.go index 2ad5d51..44ed434 100644 --- a/cmd/bolt/stats_test.go +++ b/cmd/bolt/stats_test.go @@ -7,7 +7,6 @@ import ( "github.com/boltdb/bolt" . "github.com/boltdb/bolt/cmd/bolt" - "github.com/stretchr/testify/assert" ) func TestStats(t *testing.T) { @@ -40,7 +39,7 @@ func TestStats(t *testing.T) { }) db.Close() output := run("stats", path, "b") - assert.Equal(t, "Aggregate statistics for 2 buckets\n\n"+ + equals(t, "Aggregate statistics for 2 buckets\n\n"+ "Page count statistics\n"+ "\tNumber of logical branch pages: 0\n"+ "\tNumber of physical branch overflow pages: 0\n"+ |