Update TestQueryOne() so its decoupled from the adapters

pull/16/head
Vinícius Garcia 2022-02-19 02:10:38 -03:00
parent 488f5ba71d
commit 9fd5bab3c4
1 changed files with 188 additions and 174 deletions

View File

@ -503,6 +503,21 @@ func QueryTest(
func TestQueryOne(t *testing.T) {
for _, config := range supportedConfigs {
QueryOneTest(t,
config,
func(t *testing.T) (DBAdapter, io.Closer) {
db, close := connectDB(t, config)
return db, close
},
)
}
}
func QueryOneTest(
t *testing.T,
config testConfig,
newDBAdapter func(t *testing.T) (DBAdapter, io.Closer),
) {
t.Run(config.driver, func(t *testing.T) {
variations := []struct {
desc string
@ -525,7 +540,7 @@ func TestQueryOne(t *testing.T) {
t.Run(variation.desc, func(t *testing.T) {
t.Run("should return RecordNotFoundErr when there are no results", func(t *testing.T) {
db, closer := connectDB(t, config)
db, closer := newDBAdapter(t)
defer closer.Close()
ctx := context.Background()
@ -536,7 +551,7 @@ func TestQueryOne(t *testing.T) {
})
t.Run("should return a user correctly", func(t *testing.T) {
db, closer := connectDB(t, config)
db, closer := newDBAdapter(t)
defer closer.Close()
ctx := context.Background()
@ -557,7 +572,7 @@ func TestQueryOne(t *testing.T) {
})
t.Run("should return only the first result on multiples matches", func(t *testing.T) {
db, closer := connectDB(t, config)
db, closer := newDBAdapter(t)
defer closer.Close()
ctx := context.Background()
@ -586,7 +601,7 @@ func TestQueryOne(t *testing.T) {
return
}
db, closer := connectDB(t, config)
db, closer := newDBAdapter(t)
defer closer.Close()
ctx := context.Background()
@ -619,7 +634,7 @@ func TestQueryOne(t *testing.T) {
}
t.Run("should report error if input is not a pointer to struct", func(t *testing.T) {
db, closer := connectDB(t, config)
db, closer := newDBAdapter(t)
defer closer.Close()
ctx := context.Background()
@ -640,7 +655,7 @@ func TestQueryOne(t *testing.T) {
})
t.Run("should report error if it receives a nil pointer to a struct", func(t *testing.T) {
db, closer := connectDB(t, config)
db, closer := newDBAdapter(t)
defer closer.Close()
ctx := context.Background()
@ -651,7 +666,7 @@ func TestQueryOne(t *testing.T) {
})
t.Run("should report error if the query is not valid", func(t *testing.T) {
db, closer := connectDB(t, config)
db, closer := newDBAdapter(t)
defer closer.Close()
ctx := context.Background()
@ -662,7 +677,7 @@ func TestQueryOne(t *testing.T) {
})
t.Run("should report error if using nested struct and the query starts with SELECT", func(t *testing.T) {
db, closer := connectDB(t, config)
db, closer := newDBAdapter(t)
defer closer.Close()
ctx := context.Background()
@ -677,7 +692,6 @@ func TestQueryOne(t *testing.T) {
assert.Equal(t, true, strings.Contains(err.Error(), "feature"), "unexpected error msg: "+err.Error())
})
})
}
}
func TestInsert(t *testing.T) {