5
5
package main
6
6
7
7
import (
8
+ "path/filepath"
8
9
"testing"
9
10
10
11
"github.com/golang/dep/test"
@@ -65,7 +66,7 @@ func TestInit(t *testing.T) {
65
66
goldenLock : "lock.golden.json" ,
66
67
},
67
68
68
- // One dependency previously retrieved by version. Both will show up in lock, but only retrieved one in manifest.
69
+ // One dependency previously retrieved by version. Both will show up in lock, but only retrieved one in manifest?
69
70
{
70
71
dataRoot : "init/case2" ,
71
72
importPaths : map [string ]string {
@@ -79,7 +80,7 @@ func TestInit(t *testing.T) {
79
80
goldenLock : "lock.golden.json" ,
80
81
},
81
82
82
- // One dependency previously retrieved by sha. Both will show up in lock and manifest?
83
+ // One dependency previously retrieved by sha. Both will show up in lock and manifest
83
84
{
84
85
dataRoot : "init/case3" ,
85
86
importPaths : map [string ]string {
@@ -94,63 +95,63 @@ func TestInit(t *testing.T) {
94
95
},
95
96
}
96
97
97
- runTest := func (t * testing.T , testCase initTestCase ) {
98
- test .NeedsExternalNetwork (t )
99
- test .NeedsGit (t )
98
+ test .NeedsExternalNetwork (t )
99
+ test .NeedsGit (t )
100
100
101
- h := test .NewHelper (t )
102
- defer h .Cleanup ()
103
-
104
- h .TempDir ("src" )
105
- h .Setenv ("GOPATH" , h .Path ("." ))
106
-
107
- // checkout the specified revisions
108
- for ip , rev := range testCase .importPaths {
109
- h .RunGo ("get" , ip )
110
- repoDir := h .Path ("src/" + ip )
111
- h .RunGit (repoDir , "checkout" , rev )
112
- }
113
-
114
- // Build a fake consumer of these packages.
115
- root := "src/github.com/golang/notexist"
116
- for src , dest := range testCase .sourceFiles {
117
- h .TempCopy (root + "/" + dest , testCase .dataRoot + "/" + src )
118
- }
101
+ for _ , testCase := range tests {
102
+ t .Run (testCase .dataRoot , func (t * testing.T ) {
103
+ h := test .NewHelper (t )
104
+ defer h .Cleanup ()
105
+
106
+ h .TempDir ("src" )
107
+ h .Setenv ("GOPATH" , h .Path ("." ))
108
+
109
+ // checkout the specified revisions
110
+ for ip , rev := range testCase .importPaths {
111
+ h .RunGo ("get" , ip )
112
+ repoDir := h .Path (filepath .Join ("src" , ip ))
113
+ h .RunGit (repoDir , "checkout" , rev )
114
+ }
119
115
120
- h .Cd (h .Path (root ))
121
- h .Run ("init" )
116
+ // Build a fake consumer of these packages.
117
+ root := "src/github.com/golang/notexist"
118
+ for src , dest := range testCase .sourceFiles {
119
+ h .TempCopy (filepath .Join (root , dest ), filepath .Join (testCase .dataRoot , src ))
120
+ }
122
121
123
- wantManifest := h .GetTestFileString (testCase .dataRoot + "/" + testCase .goldenManifest )
124
- gotManifest := h .ReadManifest ()
125
- if wantManifest != gotManifest {
126
- if * test .UpdateGolden {
127
- if err := h .WriteTestFile (testCase .dataRoot + "/" + testCase .goldenManifest , gotManifest ); err != nil {
128
- t .Fatal (err )
122
+ h .Cd (h .Path (root ))
123
+ h .Run ("init" )
124
+
125
+ wantPath := filepath .Join (testCase .dataRoot , testCase .goldenManifest )
126
+ wantManifest := h .GetTestFileString (wantPath )
127
+ gotManifest := h .ReadManifest ()
128
+ if wantManifest != gotManifest {
129
+ if * test .UpdateGolden {
130
+ if err := h .WriteTestFile (wantPath , gotManifest ); err != nil {
131
+ t .Fatal (err )
132
+ }
133
+ } else {
134
+ t .Errorf ("expected %s, got %s" , wantManifest , gotManifest )
129
135
}
130
- } else {
131
- t .Errorf ("expected %s, got %s" , wantManifest , gotManifest )
132
136
}
133
- }
134
137
135
- wantLock := h .GetTestFileString (testCase .dataRoot + "/" + testCase .goldenLock )
136
- gotLock := h .ReadLock ()
137
- if wantLock != gotLock {
138
- if * test .UpdateGolden {
139
- if err := h .WriteTestFile (testCase .dataRoot + "/" + testCase .goldenLock , gotLock ); err != nil {
140
- t .Fatal (err )
138
+ wantPath = filepath .Join (testCase .dataRoot , testCase .goldenLock )
139
+ wantLock := h .GetTestFileString (wantPath )
140
+ gotLock := h .ReadLock ()
141
+ if wantLock != gotLock {
142
+ if * test .UpdateGolden {
143
+ if err := h .WriteTestFile (wantPath , gotLock ); err != nil {
144
+ t .Fatal (err )
145
+ }
146
+ } else {
147
+ t .Errorf ("expected %s, got %s" , wantLock , gotLock )
141
148
}
142
- } else {
143
- t .Errorf ("expected %s, got %s" , wantLock , gotLock )
144
149
}
145
- }
146
150
147
- // vendor should have been created & populated
148
- for ip := range testCase .importPaths {
149
- h .MustExist (h .Path (root + "/vendor/" + ip ))
150
- }
151
- }
152
-
153
- for _ , testCase := range tests {
154
- runTest (t , testCase )
151
+ // vendor should have been created & populated
152
+ for ip := range testCase .importPaths {
153
+ h .MustExist (h .Path (filepath .Join (root , "vendor" , ip )))
154
+ }
155
+ })
155
156
}
156
157
}
0 commit comments