Update TestInsert so its decoupled from the adapters

pull/16/head
Vinícius Garcia 2022-02-19 02:55:59 -03:00
parent eb030b1d76
commit 0b0e3a2901
1 changed files with 306 additions and 292 deletions

View File

@ -684,6 +684,21 @@ func QueryOneTest(
func TestInsert(t *testing.T) {
for _, config := range supportedConfigs {
InsertTest(t,
config,
func(t *testing.T) (DBAdapter, io.Closer) {
db, close := connectDB(t, config)
return db, close
},
)
}
}
func InsertTest(
t *testing.T,
config testConfig,
newDBAdapter func(t *testing.T) (DBAdapter, io.Closer),
) {
t.Run(config.driver, func(t *testing.T) {
t.Run("success cases", func(t *testing.T) {
t.Run("single primary key tables", func(t *testing.T) {
@ -693,7 +708,7 @@ func TestInsert(t *testing.T) {
}
t.Run("should insert one user correctly", func(t *testing.T) {
db, closer := connectDB(t, config)
db, closer := newDBAdapter(t)
defer closer.Close()
ctx := context.Background()
@ -726,7 +741,7 @@ func TestInsert(t *testing.T) {
// Using columns "id" and "name" as IDs:
table := NewTable("users", "id", "name")
db, closer := connectDB(t, config)
db, closer := newDBAdapter(t)
defer closer.Close()
ctx := context.Background()
@ -754,7 +769,7 @@ func TestInsert(t *testing.T) {
})
t.Run("should work with anonymous structs", func(t *testing.T) {
db, closer := connectDB(t, config)
db, closer := newDBAdapter(t)
defer closer.Close()
ctx := context.Background()
@ -768,7 +783,7 @@ func TestInsert(t *testing.T) {
})
t.Run("should work with preset IDs", func(t *testing.T) {
db, closer := connectDB(t, config)
db, closer := newDBAdapter(t)
defer closer.Close()
ctx := context.Background()
@ -796,7 +811,7 @@ func TestInsert(t *testing.T) {
}
t.Run("should insert in composite key tables correctly", func(t *testing.T) {
db, closer := connectDB(t, config)
db, closer := newDBAdapter(t)
defer closer.Close()
ctx := context.Background()
@ -817,7 +832,7 @@ func TestInsert(t *testing.T) {
})
t.Run("should accept partially provided values for composite key tables", func(t *testing.T) {
db, closer := connectDB(t, config)
db, closer := newDBAdapter(t)
defer closer.Close()
ctx := context.Background()
@ -862,7 +877,7 @@ func TestInsert(t *testing.T) {
}
t.Run("should report error for invalid input types", func(t *testing.T) {
db, closer := connectDB(t, config)
db, closer := newDBAdapter(t)
defer closer.Close()
ctx := context.Background()
@ -893,7 +908,7 @@ func TestInsert(t *testing.T) {
})
t.Run("should report error if for some reason the insertMethod is invalid", func(t *testing.T) {
db, closer := connectDB(t, config)
db, closer := newDBAdapter(t)
defer closer.Close()
ctx := context.Background()
@ -907,7 +922,7 @@ func TestInsert(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()
@ -919,7 +934,7 @@ func TestInsert(t *testing.T) {
})
t.Run("should report error if table contains an empty ID name", func(t *testing.T) {
db, closer := connectDB(t, config)
db, closer := newDBAdapter(t)
defer closer.Close()
ctx := context.Background()
@ -930,7 +945,7 @@ func TestInsert(t *testing.T) {
})
t.Run("should report error if ksql.Table.name is empty", func(t *testing.T) {
db, closer := connectDB(t, config)
db, closer := newDBAdapter(t)
defer closer.Close()
ctx := context.Background()
@ -941,7 +956,7 @@ func TestInsert(t *testing.T) {
})
t.Run("should not panic if a column doesn't exist in the database", func(t *testing.T) {
db, closer := connectDB(t, config)
db, closer := newDBAdapter(t)
defer closer.Close()
ctx := context.Background()
@ -959,7 +974,7 @@ func TestInsert(t *testing.T) {
})
t.Run("should not panic if the ID column doesn't exist in the database", func(t *testing.T) {
db, closer := connectDB(t, config)
db, closer := newDBAdapter(t)
defer closer.Close()
ctx := context.Background()
@ -975,7 +990,7 @@ func TestInsert(t *testing.T) {
})
t.Run("should not panic if the ID column is missing in the struct", func(t *testing.T) {
db, closer := connectDB(t, config)
db, closer := newDBAdapter(t)
defer closer.Close()
ctx := context.Background()
@ -996,7 +1011,6 @@ func TestInsert(t *testing.T) {
})
})
}
}
type brokenDialect struct{}