mirror of https://github.com/aldy505/bob.git
refactor: clean up test create table
This commit is contained in:
parent
8f6a475880
commit
5af711e253
|
@ -6,8 +6,7 @@ import (
|
||||||
"github.com/aldy505/bob"
|
"github.com/aldy505/bob"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCreate(t *testing.T) {
|
func TestCreateTable(t *testing.T) {
|
||||||
t.Run("should return correct sql string with all columns and types", func(t *testing.T) {
|
|
||||||
sql, _, err := bob.
|
sql, _, err := bob.
|
||||||
CreateTable("users").
|
CreateTable("users").
|
||||||
UUIDColumn("uuid").
|
UUIDColumn("uuid").
|
||||||
|
@ -35,9 +34,9 @@ func TestCreate(t *testing.T) {
|
||||||
if sql != result {
|
if sql != result {
|
||||||
t.Fatal("sql is not equal to result:", sql)
|
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").
|
sql, _, err := bob.CreateTable("users").
|
||||||
UUIDColumn("id", "PRIMARY KEY").
|
UUIDColumn("id", "PRIMARY KEY").
|
||||||
StringColumn("email", "NOT NULL", "UNIQUE").
|
StringColumn("email", "NOT NULL", "UNIQUE").
|
||||||
|
@ -50,9 +49,9 @@ func TestCreate(t *testing.T) {
|
||||||
if sql != result {
|
if sql != result {
|
||||||
t.Fatal("sql is not equal to result:", sql)
|
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.
|
sql, _, err := bob.
|
||||||
CreateTable("users").
|
CreateTable("users").
|
||||||
WithSchema("private").
|
WithSchema("private").
|
||||||
|
@ -65,8 +64,9 @@ func TestCreate(t *testing.T) {
|
||||||
if sql != result {
|
if sql != result {
|
||||||
t.Fatal("sql is not equal to result:", sql)
|
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) {
|
t.Run("should emit error on empty table name", func(t *testing.T) {
|
||||||
_, _, err := bob.
|
_, _, err := bob.
|
||||||
CreateTable("").
|
CreateTable("").
|
||||||
|
@ -85,8 +85,9 @@ func TestCreate(t *testing.T) {
|
||||||
t.Fatal("should throw an error, it didn't:", err.Error())
|
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.
|
sql, _, err := bob.
|
||||||
CreateTableIfNotExists("users").
|
CreateTableIfNotExists("users").
|
||||||
TextColumn("name").
|
TextColumn("name").
|
||||||
|
@ -98,5 +99,4 @@ func TestCreate(t *testing.T) {
|
||||||
if sql != result {
|
if sql != result {
|
||||||
t.Fatal("sql is not equal to result: ", sql)
|
t.Fatal("sql is not equal to result: ", sql)
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue