Skip to content

Commit

Permalink
utils_test: Add gorm and json test. #1
Browse files Browse the repository at this point in the history
  • Loading branch information
Shelnutt2 committed Jun 6, 2016
1 parent 4a531a0 commit 1064b51
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,47 @@ type testStruct struct {
So(string(bytes), ShouldEqual, expectedStruct)
})
}

func TestMysqlJSONStringGenerate(t *testing.T) {
expectedStruct :=
`package test
type testStruct struct {
NullStringColumn sql.NullString ` + "`json:\"nullStringColumn\"`" + `
StringColumn string ` + "`json:\"stringColumn\"`" + `
}
`

columnMap := map[string]map[string]string{
"stringColumn": {"nullable": "NO", "value": "varchar"},
"nullStringColumn": {"nullable": "YES", "value": "varchar"},
}
bytes, err := Generate(columnMap, "testStruct", "test", true, false)

Convey("Should be able to generate map from string column", t, func() {
So(err, ShouldBeNil)
So(string(bytes), ShouldEqual, expectedStruct)
})
}

func TestMysqlGormStringGenerate(t *testing.T) {
expectedStruct :=
`package test
type testStruct struct {
NullStringColumn sql.NullString ` + "`gorm:\"column:nullStringColumn\"`" + `
StringColumn string ` + "`gorm:\"column:stringColumn\"`" + `
}
`

columnMap := map[string]map[string]string{
"stringColumn": {"nullable": "NO", "value": "varchar"},
"nullStringColumn": {"nullable": "YES", "value": "varchar"},
}
bytes, err := Generate(columnMap, "testStruct", "test", false, true)

Convey("Should be able to generate map from string column", t, func() {
So(err, ShouldBeNil)
So(string(bytes), ShouldEqual, expectedStruct)
})
}

0 comments on commit 1064b51

Please sign in to comment.