Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions generators/dbtest/faker.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ func (ff FakeFiller) ByNameAndType(columnName, gotype string, maxFiledLen int) (
case model.TypeInt:
return fakeIntRange.assign(columnName).Tmpl(), true
case model.TypeInt32:
return fakeIntRange.assign(columnName).toInt32().Tmpl(), true
return fakeIntRange.toInt32().assign(columnName).Tmpl(), true
case model.TypeInt64:
return fakeIntRange.assign(columnName).toInt64().Tmpl(), true
return fakeIntRange.toInt64().assign(columnName).Tmpl(), true
case model.TypeFloat32:
return fakeFloat32Range.assign(columnName).Tmpl(), true
case model.TypeFloat64:
Expand Down Expand Up @@ -157,9 +157,9 @@ func (ff FakeFiller) ByType(colName, goType, dbType string, isArray bool, maxFil
case model.TypeInt:
return fakeIntRange.assign(colName).Tmpl(), true
case model.TypeInt32:
return fakeIntRange.assign(colName).toInt32().Tmpl(), true
return fakeIntRange.toInt32().assign(colName).Tmpl(), true
case model.TypeInt64:
return fakeIntRange.assign(colName).toInt64().Tmpl(), true
return fakeIntRange.toInt64().assign(colName).Tmpl(), true
case model.TypeFloat32:
return fakeFloat32Range.assign(colName).Tmpl(), true
case model.TypeFloat64:
Expand Down
44 changes: 44 additions & 0 deletions generators/dbtest/faker_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package dbtest

import (
"go/parser"
"testing"

"github.com/dizzyfool/genna/model"
. "github.com/smartystreets/goconvey/convey"
)

func TestFakeFiller_IntCast(t *testing.T) {
Convey("int32 and int64 columns are cast before assignment", t, func() {
ff := NewFakeFiller()

cases := []struct {
name, goType, want string
byName bool
}{
{"Count", model.TypeInt32, "in.Count = int32(gofakeit.IntRange(1, 10))", false},
{"Count", model.TypeInt64, "in.Count = int64(gofakeit.IntRange(1, 10))", false},
{"Login", model.TypeInt32, "in.Login = int32(gofakeit.IntRange(1, 10))", true},
{"Login", model.TypeInt64, "in.Login = int64(gofakeit.IntRange(1, 10))", true},
}
for _, c := range cases {
var (
got string
found bool
)
if c.byName {
res, ok := ff.ByNameAndType(c.name, c.goType, 0)
got, found = string(res), ok
} else {
res, ok := ff.ByType(c.name, c.goType, model.TypePGInt8, false, 0)
got, found = string(res), ok
}

So(found, ShouldBeTrue)
So(got, ShouldEqual, c.want)

_, err := parser.ParseExpr("func() { " + got + " }")
So(err, ShouldBeNil)
}
})
}
Loading