test: refactored

This commit is contained in:
Reinaldy Rafli 2021-07-31 12:03:31 +07:00
parent cb9e7b01c4
commit efa752f2ab
2 changed files with 57 additions and 57 deletions

View File

@ -178,7 +178,7 @@ func main() {
Available placeholder formats:
* `bob.Question` - `INSERT INTO "users" (name) VALUES (?)`
* `bob.Dollar` - `INSERT INTO "users" (name) VALUES ($1)`
* `bob.Colon` - `INSERT INTO "users" (name) VALUES (:1)` (Yes, I know this is kinda wrong. I'm thinking of removing it.)
* `bob.Colon` - `INSERT INTO "users" (name) VALUES (:1)`
* `bob.AtP` - `INSERT INTO "users" (name) VALUES (@p1)`
### With pgx (PostgreSQL)

View File

@ -7,8 +7,7 @@ import (
"github.com/aldy505/bob"
)
func TestHas(t *testing.T) {
t.Run("should be able to create a hasTable query", func(t *testing.T) {
func TestHasTable(t *testing.T) {
sql, args, err := bob.HasTable("users").ToSql()
if err != nil {
t.Fatal(err.Error())
@ -22,8 +21,9 @@ func TestHas(t *testing.T) {
if !reflect.DeepEqual(args, argsResult) {
t.Fatal("args is not equal with argsResult:", args)
}
})
}
func TestHasColumn(t *testing.T) {
t.Run("should be able to create a hasColumn query", func(t *testing.T) {
sql, args, err := bob.HasTable("users").HasColumn("name").ToSql()
if err != nil {
@ -57,8 +57,9 @@ func TestHas(t *testing.T) {
t.Fatal("args is not equal with argsResult:", args)
}
})
}
t.Run("should be able to create a hasTable query with schema", func(t *testing.T) {
func TestHas_Schema(t *testing.T) {
sql, args, err := bob.HasTable("users").WithSchema("private").ToSql()
if err != nil {
t.Fatal(err.Error())
@ -73,9 +74,9 @@ func TestHas(t *testing.T) {
if !reflect.DeepEqual(args, argsResult) {
t.Fatal("args is not equal with argsResult:", args)
}
})
}
t.Run("should be able to have a different placeholder - dollar", func(t *testing.T) {
func TestHas_PlaceholderFormats(t *testing.T) {
sql, args, err := bob.HasTable("users").HasColumn("name").PlaceholderFormat(bob.Dollar).ToSql()
if err != nil {
t.Fatal(err.Error())
@ -90,12 +91,11 @@ func TestHas(t *testing.T) {
if !reflect.DeepEqual(args, argsResult) {
t.Fatal("args is not equal with argsResult:", args)
}
})
}
t.Run("should expect an error for no table name", func(t *testing.T) {
func TestHas_EmitError(t *testing.T) {
_, _, err := bob.HasTable("").ToSql()
if err.Error() != "has statement should have a table name" {
t.Fatal("error is different:", err.Error())
}
})
}