mirror of https://github.com/VinGarcia/ksql.git
Update TestQueryOne() to work with postgres
parent
0cdaf00aaf
commit
ed8f0550aa
|
@ -121,13 +121,15 @@ func TestQuery(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestQueryOne(t *testing.T) {
|
func TestQueryOne(t *testing.T) {
|
||||||
err := createTable("sqlite3")
|
for _, driver := range []string{"sqlite3", "postgres"} {
|
||||||
|
t.Run(driver, func(t *testing.T) {
|
||||||
|
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())
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("should return RecordNotFoundErr when there are no results", func(t *testing.T) {
|
t.Run("should return RecordNotFoundErr when there are no results", func(t *testing.T) {
|
||||||
db := connectDB(t, "sqlite3")
|
db := connectDB(t, driver)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
@ -138,7 +140,7 @@ func TestQueryOne(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("should return a user correctly", func(t *testing.T) {
|
t.Run("should return a user correctly", func(t *testing.T) {
|
||||||
db := connectDB(t, "sqlite3")
|
db := connectDB(t, driver)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
db.Create(&User{
|
db.Create(&User{
|
||||||
|
@ -148,7 +150,7 @@ func TestQueryOne(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
c := newTestClient(db, "postgres", "users")
|
c := newTestClient(db, "postgres", "users")
|
||||||
u := User{}
|
u := User{}
|
||||||
err = c.QueryOne(ctx, &u, `SELECT * FROM users WHERE name=?;`, "Bia")
|
err = c.QueryOne(ctx, &u, `SELECT * FROM users WHERE name=`+c.dialect.Placeholder(0), "Bia")
|
||||||
|
|
||||||
assert.Equal(t, nil, err)
|
assert.Equal(t, nil, err)
|
||||||
assert.Equal(t, "Bia", u.Name)
|
assert.Equal(t, "Bia", u.Name)
|
||||||
|
@ -156,7 +158,7 @@ func TestQueryOne(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("should report error if input is not a pointer to struct", func(t *testing.T) {
|
t.Run("should report error if input is not a pointer to struct", func(t *testing.T) {
|
||||||
db := connectDB(t, "sqlite3")
|
db := connectDB(t, driver)
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
db.Create(&User{
|
db.Create(&User{
|
||||||
|
@ -170,12 +172,14 @@ func TestQueryOne(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
c := newTestClient(db, "postgres", "users")
|
c := newTestClient(db, "postgres", "users")
|
||||||
|
|
||||||
err = c.QueryOne(ctx, &[]User{}, `SELECT * FROM users WHERE name like ?;`, "% Sá")
|
err = c.QueryOne(ctx, &[]User{}, `SELECT * FROM users WHERE name like `+c.dialect.Placeholder(0), "% Sá")
|
||||||
assert.NotEqual(t, nil, err)
|
assert.NotEqual(t, nil, err)
|
||||||
|
|
||||||
err = c.QueryOne(ctx, User{}, `SELECT * FROM users WHERE name like ?;`, "% Sá")
|
err = c.QueryOne(ctx, User{}, `SELECT * FROM users WHERE name like `+c.dialect.Placeholder(0), "% Sá")
|
||||||
assert.NotEqual(t, nil, err)
|
assert.NotEqual(t, nil, err)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInsert(t *testing.T) {
|
func TestInsert(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue