@@ -89,113 +89,3 @@ func TestInvalidConfig(t *testing.T) {
8989 t .Errorf ("expected err; got nil" )
9090 }
9191}
92-
93- func TestTypeOverrides (t * testing.T ) {
94- for _ , test := range []struct {
95- override Override
96- pkg string
97- typeName string
98- basic bool
99- }{
100- {
101- Override {
102- DBType : "uuid" ,
103- GoType : GoType {Spec : "github.com/segmentio/ksuid.KSUID" },
104- },
105- "github.com/segmentio/ksuid" ,
106- "ksuid.KSUID" ,
107- false ,
108- },
109- // TODO: Add test for struct pointers
110- //
111- // {
112- // Override{
113- // DBType: "uuid",
114- // GoType: "github.com/segmentio/*ksuid.KSUID",
115- // },
116- // "github.com/segmentio/ksuid",
117- // "*ksuid.KSUID",
118- // false,
119- // },
120- {
121- Override {
122- DBType : "citext" ,
123- GoType : GoType {Spec : "string" },
124- },
125- "" ,
126- "string" ,
127- true ,
128- },
129- {
130- Override {
131- DBType : "timestamp" ,
132- GoType : GoType {Spec : "time.Time" },
133- },
134- "time" ,
135- "time.Time" ,
136- false ,
137- },
138- } {
139- tt := test
140- t .Run (tt .override .GoType .Spec , func (t * testing.T ) {
141- if err := tt .override .Parse (); err != nil {
142- t .Fatalf ("override parsing failed; %s" , err )
143- }
144- if diff := cmp .Diff (tt .pkg , tt .override .GoImportPath ); diff != "" {
145- t .Errorf ("package mismatch;\n %s" , diff )
146- }
147- if diff := cmp .Diff (tt .typeName , tt .override .GoTypeName ); diff != "" {
148- t .Errorf ("type name mismatch;\n %s" , diff )
149- }
150- if diff := cmp .Diff (tt .basic , tt .override .GoBasicType ); diff != "" {
151- t .Errorf ("basic mismatch;\n %s" , diff )
152- }
153- })
154- }
155- for _ , test := range []struct {
156- override Override
157- err string
158- }{
159- {
160- Override {
161- DBType : "uuid" ,
162- GoType : GoType {Spec : "Pointer" },
163- },
164- "Package override `go_type` specifier \" Pointer\" is not a Go basic type e.g. 'string'" ,
165- },
166- {
167- Override {
168- DBType : "uuid" ,
169- GoType : GoType {Spec : "untyped rune" },
170- },
171- "Package override `go_type` specifier \" untyped rune\" is not a Go basic type e.g. 'string'" ,
172- },
173- } {
174- tt := test
175- t .Run (tt .override .GoType .Spec , func (t * testing.T ) {
176- err := tt .override .Parse ()
177- if err == nil {
178- t .Fatalf ("expected parse to fail; got nil" )
179- }
180- if diff := cmp .Diff (tt .err , err .Error ()); diff != "" {
181- t .Errorf ("error mismatch;\n %s" , diff )
182- }
183- })
184- }
185- }
186-
187- func FuzzOverride (f * testing.F ) {
188- for _ , spec := range []string {
189- "string" ,
190- "github.com/gofrs/uuid.UUID" ,
191- "github.com/segmentio/ksuid.KSUID" ,
192- } {
193- f .Add (spec )
194- }
195- f .Fuzz (func (t * testing.T , s string ) {
196- o := Override {
197- GoType : GoType {Spec : s },
198- }
199- o .Parse ()
200- })
201- }
0 commit comments