mirror of https://github.com/aldy505/bob.git
test: refactor & running fmt
This commit is contained in:
parent
4a022225f2
commit
b5df4ae1f0
2
bob.go
2
bob.go
|
@ -8,8 +8,10 @@ import (
|
||||||
|
|
||||||
// ErrEmptyTable is a common database/sql error if a table is empty or no rows is returned by the query.
|
// ErrEmptyTable is a common database/sql error if a table is empty or no rows is returned by the query.
|
||||||
var ErrEmptyTable = errors.New("sql: no rows in result set")
|
var ErrEmptyTable = errors.New("sql: no rows in result set")
|
||||||
|
|
||||||
// ErrEmptyTable is a common pgx error if a table is empty or no rows is returned by the query.
|
// ErrEmptyTable is a common pgx error if a table is empty or no rows is returned by the query.
|
||||||
var ErrEmptyTablePgx = errors.New("no rows in result set")
|
var ErrEmptyTablePgx = errors.New("no rows in result set")
|
||||||
|
|
||||||
// ErrDialectNotSupported tells you whether the dialect is supported or not.
|
// ErrDialectNotSupported tells you whether the dialect is supported or not.
|
||||||
var ErrDialectNotSupported = errors.New("provided database dialect is not supported")
|
var ErrDialectNotSupported = errors.New("provided database dialect is not supported")
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,6 @@ import (
|
||||||
"github.com/aldy505/bob"
|
"github.com/aldy505/bob"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO - do more test
|
|
||||||
|
|
||||||
func TestHas(t *testing.T) {
|
func TestHas(t *testing.T) {
|
||||||
t.Run("should be able to create a hasTable query", func(t *testing.T) {
|
t.Run("should be able to create a hasTable query", func(t *testing.T) {
|
||||||
sql, args, err := bob.HasTable("users").ToSql()
|
sql, args, err := bob.HasTable("users").ToSql()
|
||||||
|
|
|
@ -7,8 +7,7 @@ import (
|
||||||
"github.com/aldy505/bob"
|
"github.com/aldy505/bob"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUpsert(t *testing.T) {
|
func TestUpsert_MySQL(t *testing.T) {
|
||||||
t.Run("should be able to generate upsert query for mysql", func(t *testing.T) {
|
|
||||||
sql, args, err := bob.
|
sql, args, err := bob.
|
||||||
Upsert("users", bob.MySQL).
|
Upsert("users", bob.MySQL).
|
||||||
Columns("name", "email").
|
Columns("name", "email").
|
||||||
|
@ -28,9 +27,9 @@ func TestUpsert(t *testing.T) {
|
||||||
if !reflect.DeepEqual(args, desiredArgs) {
|
if !reflect.DeepEqual(args, desiredArgs) {
|
||||||
t.Error("args is not the same as result: ", args)
|
t.Error("args is not the same as result: ", args)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
t.Run("should be able to generate upsert query for postgres", func(t *testing.T) {
|
func TestUpsert_PostgreSQL(t *testing.T) {
|
||||||
sql, args, err := bob.
|
sql, args, err := bob.
|
||||||
Upsert("users", bob.PostgreSQL).
|
Upsert("users", bob.PostgreSQL).
|
||||||
Columns("name", "email").
|
Columns("name", "email").
|
||||||
|
@ -52,9 +51,9 @@ func TestUpsert(t *testing.T) {
|
||||||
if !reflect.DeepEqual(args, desiredArgs) {
|
if !reflect.DeepEqual(args, desiredArgs) {
|
||||||
t.Error("args is not the same as result: ", args)
|
t.Error("args is not the same as result: ", args)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
t.Run("should be able to generate upsert query for sqlite", func(t *testing.T) {
|
func TestUpsert_SQLite(t *testing.T) {
|
||||||
sql, args, err := bob.
|
sql, args, err := bob.
|
||||||
Upsert("users", bob.SQLite).
|
Upsert("users", bob.SQLite).
|
||||||
Columns("name", "email").
|
Columns("name", "email").
|
||||||
|
@ -76,9 +75,9 @@ func TestUpsert(t *testing.T) {
|
||||||
if !reflect.DeepEqual(args, desiredArgs) {
|
if !reflect.DeepEqual(args, desiredArgs) {
|
||||||
t.Error("args is not the same as result: ", args)
|
t.Error("args is not the same as result: ", args)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
t.Run("should be able to generate upsert query for mssql", func(t *testing.T) {
|
func TestUpsert_MSSQL(t *testing.T) {
|
||||||
sql, args, err := bob.
|
sql, args, err := bob.
|
||||||
Upsert("users", bob.MSSQL).
|
Upsert("users", bob.MSSQL).
|
||||||
Columns("name", "email").
|
Columns("name", "email").
|
||||||
|
@ -100,8 +99,9 @@ func TestUpsert(t *testing.T) {
|
||||||
if !reflect.DeepEqual(args, desiredArgs) {
|
if !reflect.DeepEqual(args, desiredArgs) {
|
||||||
t.Error("args is not the same as result: ", args)
|
t.Error("args is not the same as result: ", args)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
|
func TestUpsert_EmitErrors(t *testing.T) {
|
||||||
t.Run("should emit error without table name", func(t *testing.T) {
|
t.Run("should emit error without table name", func(t *testing.T) {
|
||||||
_, _, err := bob.Upsert("", bob.MySQL).ToSql()
|
_, _, err := bob.Upsert("", bob.MySQL).ToSql()
|
||||||
if err == nil && err.Error() != "upsert statement must specify a table" {
|
if err == nil && err.Error() != "upsert statement must specify a table" {
|
||||||
|
|
Loading…
Reference in New Issue