@@ -65,7 +65,23 @@ func TestNew(t *testing.T) {
65
65
66
66
buf := & bytes.Buffer {}
67
67
68
- cmd := exec .Command ("go" , "mod" , "init" , "github.com/volatiletech/sqlboiler-test" )
68
+ cmd := exec .Command ("go" , "env" , "GOMOD" )
69
+ goModFilePath , err := cmd .Output ()
70
+ if err != nil {
71
+ t .Fatalf ("go env GOMOD cmd execution failed: %s" , err )
72
+ }
73
+
74
+ cmd = exec .Command ("go" , "mod" , "init" , "github.com/volatiletech/sqlboiler-test" )
75
+ cmd .Dir = state .Config .OutFolder
76
+ cmd .Stderr = buf
77
+
78
+ if err = cmd .Run (); err != nil {
79
+ t .Errorf ("go mod init cmd execution failed: %s" , err )
80
+ outputCompileErrors (buf , state .Config .OutFolder )
81
+ fmt .Println ()
82
+ }
83
+
84
+ cmd = exec .Command ("go" , "mod" , "edit" , fmt .Sprintf ("-replace=github.com/volatiletech/sqlboiler/v4=%s" , filepath .Dir (string (goModFilePath ))))
69
85
cmd .Dir = state .Config .OutFolder
70
86
cmd .Stderr = buf
71
87
@@ -192,6 +208,18 @@ func TestProcessTypeReplacements(t *testing.T) {
192
208
},
193
209
},
194
210
},
211
+ {
212
+ Name : "named_table" ,
213
+ Columns : []drivers.Column {
214
+ {
215
+ Name : "id" ,
216
+ Type : "int" ,
217
+ DBType : "serial" ,
218
+ Default : "some db nonsense" ,
219
+ Nullable : false ,
220
+ },
221
+ },
222
+ },
195
223
}
196
224
197
225
s .Config .TypeReplaces = []TypeReplace {
@@ -206,6 +234,18 @@ func TestProcessTypeReplacements(t *testing.T) {
206
234
ThirdParty : []string {`"rock.com/excellent"` },
207
235
},
208
236
},
237
+ {
238
+ Tables : []string {"named_table" },
239
+ Match : drivers.Column {
240
+ DBType : "serial" ,
241
+ },
242
+ Replace : drivers.Column {
243
+ Type : "excellent.NamedType" ,
244
+ },
245
+ Imports : importers.Set {
246
+ ThirdParty : []string {`"rock.com/excellent-name"` },
247
+ },
248
+ },
209
249
{
210
250
Match : drivers.Column {
211
251
Type : "null.String" ,
@@ -255,4 +295,11 @@ func TestProcessTypeReplacements(t *testing.T) {
255
295
if i := s .Config .Imports .BasedOnType ["big.Int" ].Standard [0 ]; i != `"math/big"` {
256
296
t .Error ("imports were not adjusted" )
257
297
}
298
+
299
+ if typ := s .Tables [1 ].Columns [0 ].Type ; typ != "excellent.NamedType" {
300
+ t .Error ("type was wrong:" , typ )
301
+ }
302
+ if i := s .Config .Imports .BasedOnType ["excellent.NamedType" ].ThirdParty [0 ]; i != `"rock.com/excellent-name"` {
303
+ t .Error ("imports were not adjusted" )
304
+ }
258
305
}
0 commit comments