@@ -78,19 +78,39 @@ func TestColumnsToStruct(t *testing.T) {
7878
7979func TestInnerType (t * testing.T ) {
8080 r := Result {}
81- for _ , tc := range []struct {
82- col pg.Column
83- expected string
84- }{
85- {
86- pg.Column {Name : "created" , DataType : "timestamptz" , NotNull : true },
87- "time.Time" ,
88- },
89- } {
90- tt := tc
91- t .Run (tt .col .Name + "-" + tt .col .DataType , func (t * testing.T ) {
92- if diff := cmp .Diff (tt .expected , r .goType (tt .col )); diff != "" {
93- t .Errorf ("struct mismatch: \n %s" , diff )
81+ types := map [string ]string {
82+ "timestamptz" : "time.Time" ,
83+ "integer" : "int32" ,
84+ "int" : "int32" ,
85+ "pg_catalog.int4" : "int32" ,
86+ }
87+ for k , v := range types {
88+ dbType := k
89+ goType := v
90+ t .Run (k + "-" + v , func (t * testing.T ) {
91+ col := pg.Column {DataType : dbType , NotNull : true }
92+ if goType != r .goType (col ) {
93+ t .Errorf ("expected Go type for %s to be %s, not %s" , dbType , goType , r .goType (col ))
94+ }
95+ })
96+ }
97+ }
98+
99+ func TestNullInnerType (t * testing.T ) {
100+ r := Result {}
101+ types := map [string ]string {
102+ "timestamptz" : "sql.NullTime" ,
103+ "integer" : "sql.NullInt32" ,
104+ "int" : "sql.NullInt32" ,
105+ "pg_catalog.int4" : "sql.NullInt32" ,
106+ }
107+ for k , v := range types {
108+ dbType := k
109+ goType := v
110+ t .Run (k + "-" + v , func (t * testing.T ) {
111+ col := pg.Column {DataType : dbType , NotNull : false }
112+ if goType != r .goType (col ) {
113+ t .Errorf ("expected Go type for %s to be %s, not %s" , dbType , goType , r .goType (col ))
94114 }
95115 })
96116 }
0 commit comments