refactor: clean up test create table

This commit is contained in:
Reinaldy Rafli 2021-11-09 12:23:45 +07:00
parent 8f6a475880
commit 5af711e253
No known key found for this signature in database
GPG Key ID: CFDB9400255D8CB6
1 changed files with 71 additions and 71 deletions

View File

@ -6,8 +6,7 @@ import (
"github.com/aldy505/bob"
)
func TestCreate(t *testing.T) {
t.Run("should return correct sql string with all columns and types", func(t *testing.T) {
func TestCreateTable(t *testing.T) {
sql, _, err := bob.
CreateTable("users").
UUIDColumn("uuid").
@ -35,9 +34,9 @@ func TestCreate(t *testing.T) {
if sql != result {
t.Fatal("sql is not equal to result:", sql)
}
})
}
t.Run("should return correct sql with extras", func(t *testing.T) {
func TestCreateTable_Extras(t *testing.T) {
sql, _, err := bob.CreateTable("users").
UUIDColumn("id", "PRIMARY KEY").
StringColumn("email", "NOT NULL", "UNIQUE").
@ -50,9 +49,9 @@ func TestCreate(t *testing.T) {
if sql != result {
t.Fatal("sql is not equal to result:", sql)
}
})
}
t.Run("should be able to have a schema name", func(t *testing.T) {
func TestCreateTable_Schema(t *testing.T) {
sql, _, err := bob.
CreateTable("users").
WithSchema("private").
@ -65,8 +64,9 @@ func TestCreate(t *testing.T) {
if sql != result {
t.Fatal("sql is not equal to result:", sql)
}
})
}
func TestCreateTable_Error(t *testing.T) {
t.Run("should emit error on empty table name", func(t *testing.T) {
_, _, err := bob.
CreateTable("").
@ -85,8 +85,9 @@ func TestCreate(t *testing.T) {
t.Fatal("should throw an error, it didn't:", err.Error())
}
})
}
t.Run("should emit create if not exists", func(t *testing.T) {
func TestCreateTable_IfNotExists(t *testing.T) {
sql, _, err := bob.
CreateTableIfNotExists("users").
TextColumn("name").
@ -98,5 +99,4 @@ func TestCreate(t *testing.T) {
if sql != result {
t.Fatal("sql is not equal to result: ", sql)
}
})
}