From dd2de2882f707d84be0b7b8f4b47b49ce5b0e2d3 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sat, 5 Feb 2022 03:03:43 -0500 Subject: dbstore: add Open failure tests --- dbstore/dbstore_test.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/dbstore/dbstore_test.go b/dbstore/dbstore_test.go index f957146..a64b149 100644 --- a/dbstore/dbstore_test.go +++ b/dbstore/dbstore_test.go @@ -208,12 +208,24 @@ func seedTestDb(ctx context.Context, db DbStore) error { } func TestOpen(t *testing.T) { - path := "./testdata/test-new.db" - ctx := context.Background() + tests := []struct { + name string + path string + exp bool + } { + { "pass", "./testdata/test-new.db", true }, + { "fail", "/dev/null/does/not/exist", false }, + } - if _, err := createTestDb(ctx, path); err != nil { - t.Error(err) - return + for _, test := range(tests) { + t.Run(test.name, func(t *testing.T) { + got, err := createTestDb(context.Background(), test.path) + if test.exp && err != nil { + t.Error(err) + } else if !test.exp && err == nil { + t.Errorf("got %v, exp error", got) + } + }) } } -- cgit v1.2.3