mirror of https://github.com/VinGarcia/ksql.git
Update TestQueryChunks() to work with postgres
parent
995ccd680c
commit
45380718f5
|
@ -623,24 +623,26 @@ func TestStructToMap(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestQueryChunks(t *testing.T) {
|
func TestQueryChunks(t *testing.T) {
|
||||||
|
for _, driver := range []string{"sqlite3", "postgres"} {
|
||||||
|
t.Run(driver, func(t *testing.T) {
|
||||||
t.Run("should query a single row correctly", func(t *testing.T) {
|
t.Run("should query a single row correctly", func(t *testing.T) {
|
||||||
err := createTable("sqlite3")
|
err := createTable(driver)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("could not create test table!, reason:", err.Error())
|
t.Fatal("could not create test table!, reason:", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
db := connectDB(t, "sqlite3")
|
db := connectDB(t, driver)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
c := newTestClient(db, "sqlite3", "users")
|
c := newTestClient(db, driver, "users")
|
||||||
|
|
||||||
_ = c.Insert(ctx, &User{Name: "User1"})
|
_ = c.Insert(ctx, &User{Name: "User1"})
|
||||||
|
|
||||||
var length int
|
var length int
|
||||||
var u User
|
var u User
|
||||||
err = c.QueryChunks(ctx, ChunkParser{
|
err = c.QueryChunks(ctx, ChunkParser{
|
||||||
Query: `select * from users where name = ?;`,
|
Query: `select * from users where name = ` + c.dialect.Placeholder(0),
|
||||||
Params: []interface{}{"User1"},
|
Params: []interface{}{"User1"},
|
||||||
|
|
||||||
ChunkSize: 100,
|
ChunkSize: 100,
|
||||||
|
@ -660,16 +662,16 @@ func TestQueryChunks(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("should query one chunk correctly", func(t *testing.T) {
|
t.Run("should query one chunk correctly", func(t *testing.T) {
|
||||||
err := createTable("sqlite3")
|
err := createTable(driver)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("could not create test table!, reason:", err.Error())
|
t.Fatal("could not create test table!, reason:", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
db := connectDB(t, "sqlite3")
|
db := connectDB(t, driver)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
c := newTestClient(db, "sqlite3", "users")
|
c := newTestClient(db, driver, "users")
|
||||||
|
|
||||||
_ = c.Insert(ctx, &User{Name: "User1"})
|
_ = c.Insert(ctx, &User{Name: "User1"})
|
||||||
_ = c.Insert(ctx, &User{Name: "User2"})
|
_ = c.Insert(ctx, &User{Name: "User2"})
|
||||||
|
@ -677,7 +679,7 @@ func TestQueryChunks(t *testing.T) {
|
||||||
var lengths []int
|
var lengths []int
|
||||||
var users []User
|
var users []User
|
||||||
err = c.QueryChunks(ctx, ChunkParser{
|
err = c.QueryChunks(ctx, ChunkParser{
|
||||||
Query: `select * from users where name like ? order by name asc;`,
|
Query: `select * from users where name like ` + c.dialect.Placeholder(0) + ` order by name asc;`,
|
||||||
Params: []interface{}{"User%"},
|
Params: []interface{}{"User%"},
|
||||||
|
|
||||||
ChunkSize: 2,
|
ChunkSize: 2,
|
||||||
|
@ -698,16 +700,16 @@ func TestQueryChunks(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("should query chunks of 1 correctly", func(t *testing.T) {
|
t.Run("should query chunks of 1 correctly", func(t *testing.T) {
|
||||||
err := createTable("sqlite3")
|
err := createTable(driver)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("could not create test table!, reason:", err.Error())
|
t.Fatal("could not create test table!, reason:", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
db := connectDB(t, "sqlite3")
|
db := connectDB(t, driver)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
c := newTestClient(db, "sqlite3", "users")
|
c := newTestClient(db, driver, "users")
|
||||||
|
|
||||||
_ = c.Insert(ctx, &User{Name: "User1"})
|
_ = c.Insert(ctx, &User{Name: "User1"})
|
||||||
_ = c.Insert(ctx, &User{Name: "User2"})
|
_ = c.Insert(ctx, &User{Name: "User2"})
|
||||||
|
@ -715,7 +717,7 @@ func TestQueryChunks(t *testing.T) {
|
||||||
var lengths []int
|
var lengths []int
|
||||||
var users []User
|
var users []User
|
||||||
err = c.QueryChunks(ctx, ChunkParser{
|
err = c.QueryChunks(ctx, ChunkParser{
|
||||||
Query: `select * from users where name like ? order by name asc;`,
|
Query: `select * from users where name like ` + c.dialect.Placeholder(0) + ` order by name asc;`,
|
||||||
Params: []interface{}{"User%"},
|
Params: []interface{}{"User%"},
|
||||||
|
|
||||||
ChunkSize: 1,
|
ChunkSize: 1,
|
||||||
|
@ -736,16 +738,16 @@ func TestQueryChunks(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("should load partially filled chunks correctly", func(t *testing.T) {
|
t.Run("should load partially filled chunks correctly", func(t *testing.T) {
|
||||||
err := createTable("sqlite3")
|
err := createTable(driver)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("could not create test table!, reason:", err.Error())
|
t.Fatal("could not create test table!, reason:", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
db := connectDB(t, "sqlite3")
|
db := connectDB(t, driver)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
c := newTestClient(db, "sqlite3", "users")
|
c := newTestClient(db, driver, "users")
|
||||||
|
|
||||||
_ = c.Insert(ctx, &User{Name: "User1"})
|
_ = c.Insert(ctx, &User{Name: "User1"})
|
||||||
_ = c.Insert(ctx, &User{Name: "User2"})
|
_ = c.Insert(ctx, &User{Name: "User2"})
|
||||||
|
@ -754,7 +756,7 @@ func TestQueryChunks(t *testing.T) {
|
||||||
var lengths []int
|
var lengths []int
|
||||||
var users []User
|
var users []User
|
||||||
err = c.QueryChunks(ctx, ChunkParser{
|
err = c.QueryChunks(ctx, ChunkParser{
|
||||||
Query: `select * from users where name like ? order by name asc;`,
|
Query: `select * from users where name like ` + c.dialect.Placeholder(0) + ` order by name asc;`,
|
||||||
Params: []interface{}{"User%"},
|
Params: []interface{}{"User%"},
|
||||||
|
|
||||||
ChunkSize: 2,
|
ChunkSize: 2,
|
||||||
|
@ -777,16 +779,16 @@ func TestQueryChunks(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("should abort the first iteration when the callback returns an ErrAbortIteration", func(t *testing.T) {
|
t.Run("should abort the first iteration when the callback returns an ErrAbortIteration", func(t *testing.T) {
|
||||||
err := createTable("sqlite3")
|
err := createTable(driver)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("could not create test table!, reason:", err.Error())
|
t.Fatal("could not create test table!, reason:", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
db := connectDB(t, "sqlite3")
|
db := connectDB(t, driver)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
c := newTestClient(db, "sqlite3", "users")
|
c := newTestClient(db, driver, "users")
|
||||||
|
|
||||||
_ = c.Insert(ctx, &User{Name: "User1"})
|
_ = c.Insert(ctx, &User{Name: "User1"})
|
||||||
_ = c.Insert(ctx, &User{Name: "User2"})
|
_ = c.Insert(ctx, &User{Name: "User2"})
|
||||||
|
@ -795,7 +797,7 @@ func TestQueryChunks(t *testing.T) {
|
||||||
var lengths []int
|
var lengths []int
|
||||||
var users []User
|
var users []User
|
||||||
err = c.QueryChunks(ctx, ChunkParser{
|
err = c.QueryChunks(ctx, ChunkParser{
|
||||||
Query: `select * from users where name like ? order by name asc;`,
|
Query: `select * from users where name like ` + c.dialect.Placeholder(0) + ` order by name asc;`,
|
||||||
Params: []interface{}{"User%"},
|
Params: []interface{}{"User%"},
|
||||||
|
|
||||||
ChunkSize: 2,
|
ChunkSize: 2,
|
||||||
|
@ -816,16 +818,16 @@ func TestQueryChunks(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("should abort the last iteration when the callback returns an ErrAbortIteration", func(t *testing.T) {
|
t.Run("should abort the last iteration when the callback returns an ErrAbortIteration", func(t *testing.T) {
|
||||||
err := createTable("sqlite3")
|
err := createTable(driver)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("could not create test table!, reason:", err.Error())
|
t.Fatal("could not create test table!, reason:", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
db := connectDB(t, "sqlite3")
|
db := connectDB(t, driver)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
c := newTestClient(db, "sqlite3", "users")
|
c := newTestClient(db, driver, "users")
|
||||||
|
|
||||||
_ = c.Insert(ctx, &User{Name: "User1"})
|
_ = c.Insert(ctx, &User{Name: "User1"})
|
||||||
_ = c.Insert(ctx, &User{Name: "User2"})
|
_ = c.Insert(ctx, &User{Name: "User2"})
|
||||||
|
@ -835,7 +837,7 @@ func TestQueryChunks(t *testing.T) {
|
||||||
var lengths []int
|
var lengths []int
|
||||||
var users []User
|
var users []User
|
||||||
err = c.QueryChunks(ctx, ChunkParser{
|
err = c.QueryChunks(ctx, ChunkParser{
|
||||||
Query: `select * from users where name like ? order by name asc;`,
|
Query: `select * from users where name like ` + c.dialect.Placeholder(0) + ` order by name asc;`,
|
||||||
Params: []interface{}{"User%"},
|
Params: []interface{}{"User%"},
|
||||||
|
|
||||||
ChunkSize: 2,
|
ChunkSize: 2,
|
||||||
|
@ -857,6 +859,8 @@ func TestQueryChunks(t *testing.T) {
|
||||||
assert.Equal(t, "User3", users[2].Name)
|
assert.Equal(t, "User3", users[2].Name)
|
||||||
assert.Equal(t, []int{2, 1}, lengths)
|
assert.Equal(t, []int{2, 1}, lengths)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFillSliceWith(t *testing.T) {
|
func TestFillSliceWith(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue