Skip to content

Commit

Permalink
Fix mock driver
Browse files Browse the repository at this point in the history
  • Loading branch information
aarondl committed Nov 12, 2017
1 parent 1e525df commit 7e329b9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
7 changes: 4 additions & 3 deletions boilingcore/text_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (

"github.com/davecgh/go-spew/spew"
"github.com/volatiletech/sqlboiler/drivers"
"github.com/volatiletech/sqlboiler/drivers/mocks"
)

func TestTxtsFromOne(t *testing.T) {
t.Parallel()

tables, err := drivers.Tables(&drivers.MockDriver{}, "public", nil, nil)
tables, err := drivers.Tables(&mocks.MockDriver{}, "public", nil, nil)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -70,7 +71,7 @@ func TestTxtsFromOne(t *testing.T) {
func TestTxtsFromOneToOne(t *testing.T) {
t.Parallel()

tables, err := drivers.Tables(&drivers.MockDriver{}, "public", nil, nil)
tables, err := drivers.Tables(&mocks.MockDriver{}, "public", nil, nil)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -115,7 +116,7 @@ func TestTxtsFromOneToOne(t *testing.T) {
func TestTxtsFromMany(t *testing.T) {
t.Parallel()

tables, err := drivers.Tables(&drivers.MockDriver{}, "public", nil, nil)
tables, err := drivers.Tables(&mocks.MockDriver{}, "public", nil, nil)
if err != nil {
t.Fatal(err)
}
Expand Down
49 changes: 46 additions & 3 deletions drivers/mocks/mock.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package drivers
package mocks

import (
"github.com/volatiletech/sqlboiler/drivers"
Expand Down Expand Up @@ -77,8 +77,51 @@ func (m *MockDriver) ForeignKeyInfo(schema, tableName string) ([]drivers.Foreign

// TranslateColumnType converts a column to its "null." form if it is nullable
func (m *MockDriver) TranslateColumnType(c drivers.Column) drivers.Column {
p := &PostgresDriver{}
return p.TranslateColumnType(c)
if c.Nullable {
switch c.DBType {
case "bigint", "bigserial":
c.Type = "null.Int64"
case "integer", "serial":
c.Type = "null.Int"
case "smallint", "smallserial":
c.Type = "null.Int16"
case "decimal", "numeric", "double precision":
c.Type = "null.Float64"
case `"char"`:
c.Type = "null.Byte"
case "bytea":
c.Type = "null.Bytes"
case "boolean":
c.Type = "null.Bool"
case "date", "time", "timestamp without time zone", "timestamp with time zone":
c.Type = "null.Time"
default:
c.Type = "null.String"
}
} else {
switch c.DBType {
case "bigint", "bigserial":
c.Type = "int64"
case "integer", "serial":
c.Type = "int"
case "smallint", "smallserial":
c.Type = "int16"
case "decimal", "numeric", "double precision":
c.Type = "float64"
case `"char"`:
c.Type = "types.Byte"
case "bytea":
c.Type = "[]byte"
case "boolean":
c.Type = "bool"
case "date", "time", "timestamp without time zone", "timestamp with time zone":
c.Type = "time.Time"
default:
c.Type = "string"
}
}

return c
}

// PrimaryKeyInfo returns mock primary key info for the passed in table name
Expand Down

0 comments on commit 7e329b9

Please sign in to comment.