@@ -149,49 +149,50 @@ func TestVersionInWorkspace(t *testing.T) {
149
149
}
150
150
151
151
func TestLoadProject (t * testing.T ) {
152
- tg := test .NewHelper (t )
153
- defer tg .Cleanup ()
152
+ h := test .NewHelper (t )
153
+ defer h .Cleanup ()
154
154
155
- tg .TempDir ("src" )
156
- tg .TempDir ("src/test1" )
157
- tg .TempDir ("src/test1/sub" )
158
- tg .TempFile (filepath .Join ("src/test1" , ManifestName ), "" )
159
- tg .TempFile (filepath .Join ("src/test1" , LockName ), `memo = "cdafe8641b28cd16fe025df278b0a49b9416859345d8b6ba0ace0272b74925ee"` )
160
- tg .TempDir ("src/test2" )
161
- tg .TempDir ("src/test2/sub" )
162
- tg .TempFile (filepath .Join ("src/test2" , ManifestName ), "" )
155
+ h .TempDir (filepath .Join ("src" , "test1" , "sub" ))
156
+ h .TempFile (filepath .Join ("src" , "test1" , ManifestName ), "" )
157
+ h .TempFile (filepath .Join ("src" , "test1" , LockName ), `memo = "cdafe8641b28cd16fe025df278b0a49b9416859345d8b6ba0ace0272b74925ee"` )
158
+ h .TempDir (filepath .Join ("src" , "test2" , "sub" ))
159
+ h .TempFile (filepath .Join ("src" , "test2" , ManifestName ), "" )
163
160
164
161
var testcases = []struct {
165
- lock bool
166
- start string
162
+ name string
163
+ lock bool
164
+ wd string
167
165
}{
168
- {true , filepath .Join ("src" , "test1" )}, //direct
169
- {true , filepath .Join ("src" , "test1" , "sub" )}, //ascending
170
- {false , filepath .Join ("src" , "test2" )}, //repeat without lockfile present
171
- {false , filepath .Join ("src" , "test2" , "sub" )},
166
+ {"direct" , true , filepath .Join ("src" , "test1" )},
167
+ {"ascending" , true , filepath .Join ("src" , "test1" , "sub" )},
168
+ {"without lock" , false , filepath .Join ("src" , "test2" )},
169
+ {"ascending without lock" , false , filepath .Join ("src" , "test2" , "sub" )},
172
170
}
173
171
174
- for _ , testcase := range testcases {
175
- start := testcase .start
172
+ for _ , tc := range testcases {
173
+ t .Run (tc .name , func (t * testing.T ) {
174
+ ctx := & Ctx {
175
+ Out : discardLogger ,
176
+ Err : discardLogger ,
177
+ }
176
178
177
- ctx := & Ctx {
178
- GOPATHs : []string {tg .Path ("." )},
179
- WorkingDir : tg .Path (start ),
180
- Out : discardLogger ,
181
- Err : discardLogger ,
182
- }
179
+ err := ctx .SetPaths (h .Path (tc .wd ), h .Path ("." ))
180
+ if err != nil {
181
+ t .Fatalf ("%+v" , err )
182
+ }
183
183
184
- proj , err := ctx .LoadProject ()
185
- switch {
186
- case err != nil :
187
- t .Errorf ("%s: LoadProject failed: %+v" , start , err )
188
- case proj .Manifest == nil :
189
- t .Errorf ("%s: Manifest file didn't load" , start )
190
- case testcase .lock && proj .Lock == nil :
191
- t .Errorf ("%s: Lock file didn't load" , start )
192
- case ! testcase .lock && proj .Lock != nil :
193
- t .Errorf ("%s: Non-existent Lock file loaded" , start )
194
- }
184
+ p , err := ctx .LoadProject ()
185
+ switch {
186
+ case err != nil :
187
+ t .Fatalf ("%s: LoadProject failed: %+v" , tc .wd , err )
188
+ case p .Manifest == nil :
189
+ t .Fatalf ("%s: Manifest file didn't load" , tc .wd )
190
+ case tc .lock && p .Lock == nil :
191
+ t .Fatalf ("%s: Lock file didn't load" , tc .wd )
192
+ case ! tc .lock && p .Lock != nil :
193
+ t .Fatalf ("%s: Non-existent Lock file loaded" , tc .wd )
194
+ }
195
+ })
195
196
}
196
197
}
197
198
@@ -438,10 +439,10 @@ func TestDetectProjectGOPATH(t *testing.T) {
438
439
}
439
440
440
441
GOPATH , err := ctx .DetectProjectGOPATH (project )
441
- if ! tc .expectErr {
442
- h . Must ( err )
443
- } else if err == nil {
444
- t .Fatal ("expected an error, got nil" )
442
+ if ! tc .expectErr && err != nil {
443
+ t . Fatalf ( "%+v" , err )
444
+ } else if tc . expectErr && err == nil {
445
+ t .Fatalf ("expected an error, got nil and gopath %s" , GOPATH )
445
446
}
446
447
if GOPATH != tc .GOPATH {
447
448
t .Errorf ("expected GOPATH %s, got %s" , tc .GOPATH , GOPATH )
0 commit comments