From d2b9240c43d1767a225662a4f7983c66d42da9e2 Mon Sep 17 00:00:00 2001 From: Tyler Yahn Date: Mon, 27 Sep 2021 11:44:31 -0700 Subject: [PATCH] Add test for error return from Open --- .../github.com/jinzhu/gorm/splunkgorm/sql_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/instrumentation/github.com/jinzhu/gorm/splunkgorm/sql_test.go b/instrumentation/github.com/jinzhu/gorm/splunkgorm/sql_test.go index 0990df010..7293b1298 100644 --- a/instrumentation/github.com/jinzhu/gorm/splunkgorm/sql_test.go +++ b/instrumentation/github.com/jinzhu/gorm/splunkgorm/sql_test.go @@ -18,6 +18,7 @@ import ( "context" "database/sql" "database/sql/driver" + "errors" "testing" "github.com/jinzhu/gorm" @@ -67,3 +68,16 @@ func TestOpen(t *testing.T) { assert.Equal(t, dsn, m.dataSourceName) assert.Equal(t, options, m.options) } + +func TestOpenError(t *testing.T) { + want := errors.New("test error") + origOpen := openFunc + openFunc = func(string, string, ...splunksql.Option) (*sql.DB, error) { + return nil, want + } + defer func() { openFunc = origOpen }() + + // Ensure Open returns any underlying error. + _, got := Open("", "") + assert.ErrorIs(t, got, want) +}