OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package cipd | 5 package local |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "fmt" | 9 "fmt" |
10 "io" | 10 "io" |
11 "io/ioutil" | 11 "io/ioutil" |
12 "os" | 12 "os" |
13 "path/filepath" | 13 "path/filepath" |
14 "sort" | 14 "sort" |
15 "testing" | 15 "testing" |
16 | 16 |
17 . "github.com/smartystreets/goconvey/convey" | 17 . "github.com/smartystreets/goconvey/convey" |
| 18 |
| 19 . "infra/tools/cipd/common" |
18 ) | 20 ) |
19 | 21 |
20 func TestUtilities(t *testing.T) { | 22 func TestUtilities(t *testing.T) { |
21 Convey("Given a temp directory", t, func() { | 23 Convey("Given a temp directory", t, func() { |
22 tempDir, err := ioutil.TempDir("", "cipd_test") | 24 tempDir, err := ioutil.TempDir("", "cipd_test") |
23 So(err, ShouldBeNil) | 25 So(err, ShouldBeNil) |
24 Reset(func() { os.RemoveAll(tempDir) }) | 26 Reset(func() { os.RemoveAll(tempDir) }) |
25 | 27 |
26 // Wrappers that accept paths relative to tempDir. | 28 // Wrappers that accept paths relative to tempDir. |
27 touch := func(rel string) { | 29 touch := func(rel string) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 func TestDeployInstance(t *testing.T) { | 128 func TestDeployInstance(t *testing.T) { |
127 Convey("Given a temp directory", t, func() { | 129 Convey("Given a temp directory", t, func() { |
128 tempDir, err := ioutil.TempDir("", "cipd_test") | 130 tempDir, err := ioutil.TempDir("", "cipd_test") |
129 So(err, ShouldBeNil) | 131 So(err, ShouldBeNil) |
130 Reset(func() { os.RemoveAll(tempDir) }) | 132 Reset(func() { os.RemoveAll(tempDir) }) |
131 | 133 |
132 Convey("DeployInstance new empty package instance", func() { | 134 Convey("DeployInstance new empty package instance", func() { |
133 inst := makeTestInstance("test/package", nil) | 135 inst := makeTestInstance("test/package", nil) |
134 info, err := DeployInstance(tempDir, inst) | 136 info, err := DeployInstance(tempDir, inst) |
135 So(err, ShouldBeNil) | 137 So(err, ShouldBeNil) |
136 » » » So(info, ShouldResemble, PackageState{ | 138 » » » So(info, ShouldResemble, inst.Pin()) |
137 » » » » PackageName: "test/package", | |
138 » » » » InstanceID: inst.InstanceID(), | |
139 » » » }) | |
140 So(scanDir(tempDir), ShouldResemble, []string{ | 139 So(scanDir(tempDir), ShouldResemble, []string{ |
141 ".cipd/pkgs/test_package_B6R4ErK5ko/0123456789ab
cdef00000123456789abcdef0000/.cipdpkg/manifest.json", | 140 ".cipd/pkgs/test_package_B6R4ErK5ko/0123456789ab
cdef00000123456789abcdef0000/.cipdpkg/manifest.json", |
142 ".cipd/pkgs/test_package_B6R4ErK5ko/_current:012
3456789abcdef00000123456789abcdef0000", | 141 ".cipd/pkgs/test_package_B6R4ErK5ko/_current:012
3456789abcdef00000123456789abcdef0000", |
143 }) | 142 }) |
144 }) | 143 }) |
145 | 144 |
146 Convey("DeployInstance new non-empty package instance", func() { | 145 Convey("DeployInstance new non-empty package instance", func() { |
147 inst := makeTestInstance("test/package", []File{ | 146 inst := makeTestInstance("test/package", []File{ |
148 » » » » makeTestFile("some/file/path", "data a", false), | 147 » » » » NewTestFile("some/file/path", "data a", false), |
149 » » » » makeTestFile("some/executable", "data b", true), | 148 » » » » NewTestFile("some/executable", "data b", true), |
150 » » » » makeTestSymlink("some/symlink", "executable"), | 149 » » » » NewTestSymlink("some/symlink", "executable"), |
151 }) | 150 }) |
152 _, err := DeployInstance(tempDir, inst) | 151 _, err := DeployInstance(tempDir, inst) |
153 So(err, ShouldBeNil) | 152 So(err, ShouldBeNil) |
154 So(scanDir(tempDir), ShouldResemble, []string{ | 153 So(scanDir(tempDir), ShouldResemble, []string{ |
155 ".cipd/pkgs/test_package_B6R4ErK5ko/0123456789ab
cdef00000123456789abcdef0000/.cipdpkg/manifest.json", | 154 ".cipd/pkgs/test_package_B6R4ErK5ko/0123456789ab
cdef00000123456789abcdef0000/.cipdpkg/manifest.json", |
156 ".cipd/pkgs/test_package_B6R4ErK5ko/0123456789ab
cdef00000123456789abcdef0000/some/executable*", | 155 ".cipd/pkgs/test_package_B6R4ErK5ko/0123456789ab
cdef00000123456789abcdef0000/some/executable*", |
157 ".cipd/pkgs/test_package_B6R4ErK5ko/0123456789ab
cdef00000123456789abcdef0000/some/file/path", | 156 ".cipd/pkgs/test_package_B6R4ErK5ko/0123456789ab
cdef00000123456789abcdef0000/some/file/path", |
158 ".cipd/pkgs/test_package_B6R4ErK5ko/0123456789ab
cdef00000123456789abcdef0000/some/symlink:executable", | 157 ".cipd/pkgs/test_package_B6R4ErK5ko/0123456789ab
cdef00000123456789abcdef0000/some/symlink:executable", |
159 ".cipd/pkgs/test_package_B6R4ErK5ko/_current:012
3456789abcdef00000123456789abcdef0000", | 158 ".cipd/pkgs/test_package_B6R4ErK5ko/_current:012
3456789abcdef00000123456789abcdef0000", |
160 "some/executable:../.cipd/pkgs/test_package_B6R4
ErK5ko/_current/some/executable", | 159 "some/executable:../.cipd/pkgs/test_package_B6R4
ErK5ko/_current/some/executable", |
161 "some/file/path:../../.cipd/pkgs/test_package_B6
R4ErK5ko/_current/some/file/path", | 160 "some/file/path:../../.cipd/pkgs/test_package_B6
R4ErK5ko/_current/some/file/path", |
162 "some/symlink:../.cipd/pkgs/test_package_B6R4ErK
5ko/_current/some/symlink", | 161 "some/symlink:../.cipd/pkgs/test_package_B6R4ErK
5ko/_current/some/symlink", |
163 }) | 162 }) |
164 // Ensure symlinks are actually traversable. | 163 // Ensure symlinks are actually traversable. |
165 body, err := ioutil.ReadFile(filepath.Join(tempDir, "som
e", "file", "path")) | 164 body, err := ioutil.ReadFile(filepath.Join(tempDir, "som
e", "file", "path")) |
166 So(err, ShouldBeNil) | 165 So(err, ShouldBeNil) |
167 So(string(body), ShouldEqual, "data a") | 166 So(string(body), ShouldEqual, "data a") |
168 // Symlink to symlink is traversable too. | 167 // Symlink to symlink is traversable too. |
169 body, err = ioutil.ReadFile(filepath.Join(tempDir, "some
", "symlink")) | 168 body, err = ioutil.ReadFile(filepath.Join(tempDir, "some
", "symlink")) |
170 So(err, ShouldBeNil) | 169 So(err, ShouldBeNil) |
171 So(string(body), ShouldEqual, "data b") | 170 So(string(body), ShouldEqual, "data b") |
172 }) | 171 }) |
173 | 172 |
174 Convey("Redeploy same package instance", func() { | 173 Convey("Redeploy same package instance", func() { |
175 inst := makeTestInstance("test/package", []File{ | 174 inst := makeTestInstance("test/package", []File{ |
176 » » » » makeTestFile("some/file/path", "data a", false), | 175 » » » » NewTestFile("some/file/path", "data a", false), |
177 » » » » makeTestFile("some/executable", "data b", true), | 176 » » » » NewTestFile("some/executable", "data b", true), |
178 » » » » makeTestSymlink("some/symlink", "executable"), | 177 » » » » NewTestSymlink("some/symlink", "executable"), |
179 }) | 178 }) |
180 _, err := DeployInstance(tempDir, inst) | 179 _, err := DeployInstance(tempDir, inst) |
181 So(err, ShouldBeNil) | 180 So(err, ShouldBeNil) |
182 _, err = DeployInstance(tempDir, inst) | 181 _, err = DeployInstance(tempDir, inst) |
183 So(err, ShouldBeNil) | 182 So(err, ShouldBeNil) |
184 So(scanDir(tempDir), ShouldResemble, []string{ | 183 So(scanDir(tempDir), ShouldResemble, []string{ |
185 ".cipd/pkgs/test_package_B6R4ErK5ko/0123456789ab
cdef00000123456789abcdef0000/.cipdpkg/manifest.json", | 184 ".cipd/pkgs/test_package_B6R4ErK5ko/0123456789ab
cdef00000123456789abcdef0000/.cipdpkg/manifest.json", |
186 ".cipd/pkgs/test_package_B6R4ErK5ko/0123456789ab
cdef00000123456789abcdef0000/some/executable*", | 185 ".cipd/pkgs/test_package_B6R4ErK5ko/0123456789ab
cdef00000123456789abcdef0000/some/executable*", |
187 ".cipd/pkgs/test_package_B6R4ErK5ko/0123456789ab
cdef00000123456789abcdef0000/some/file/path", | 186 ".cipd/pkgs/test_package_B6R4ErK5ko/0123456789ab
cdef00000123456789abcdef0000/some/file/path", |
188 ".cipd/pkgs/test_package_B6R4ErK5ko/0123456789ab
cdef00000123456789abcdef0000/some/symlink:executable", | 187 ".cipd/pkgs/test_package_B6R4ErK5ko/0123456789ab
cdef00000123456789abcdef0000/some/symlink:executable", |
189 ".cipd/pkgs/test_package_B6R4ErK5ko/_current:012
3456789abcdef00000123456789abcdef0000", | 188 ".cipd/pkgs/test_package_B6R4ErK5ko/_current:012
3456789abcdef00000123456789abcdef0000", |
190 "some/executable:../.cipd/pkgs/test_package_B6R4
ErK5ko/_current/some/executable", | 189 "some/executable:../.cipd/pkgs/test_package_B6R4
ErK5ko/_current/some/executable", |
191 "some/file/path:../../.cipd/pkgs/test_package_B6
R4ErK5ko/_current/some/file/path", | 190 "some/file/path:../../.cipd/pkgs/test_package_B6
R4ErK5ko/_current/some/file/path", |
192 "some/symlink:../.cipd/pkgs/test_package_B6R4ErK
5ko/_current/some/symlink", | 191 "some/symlink:../.cipd/pkgs/test_package_B6R4ErK
5ko/_current/some/symlink", |
193 }) | 192 }) |
194 }) | 193 }) |
195 | 194 |
196 Convey("DeployInstance package update", func() { | 195 Convey("DeployInstance package update", func() { |
197 oldPkg := makeTestInstance("test/package", []File{ | 196 oldPkg := makeTestInstance("test/package", []File{ |
198 » » » » makeTestFile("some/file/path", "data a old", fal
se), | 197 » » » » NewTestFile("some/file/path", "data a old", fals
e), |
199 » » » » makeTestFile("some/executable", "data b old", tr
ue), | 198 » » » » NewTestFile("some/executable", "data b old", tru
e), |
200 » » » » makeTestFile("old only", "data c old", true), | 199 » » » » NewTestFile("old only", "data c old", true), |
201 » » » » makeTestFile("mode change 1", "data d", true), | 200 » » » » NewTestFile("mode change 1", "data d", true), |
202 » » » » makeTestFile("mode change 2", "data e", false), | 201 » » » » NewTestFile("mode change 2", "data e", false), |
203 » » » » makeTestSymlink("symlink unchanged", "target"), | 202 » » » » NewTestSymlink("symlink unchanged", "target"), |
204 » » » » makeTestSymlink("symlink changed", "old target")
, | 203 » » » » NewTestSymlink("symlink changed", "old target"), |
205 » » » » makeTestSymlink("symlink removed", "target"), | 204 » » » » NewTestSymlink("symlink removed", "target"), |
206 }) | 205 }) |
207 oldPkg.instanceID = "00000000000000000000000000000000000
00000" | 206 oldPkg.instanceID = "00000000000000000000000000000000000
00000" |
208 | 207 |
209 newPkg := makeTestInstance("test/package", []File{ | 208 newPkg := makeTestInstance("test/package", []File{ |
210 » » » » makeTestFile("some/file/path", "data a new", fal
se), | 209 » » » » NewTestFile("some/file/path", "data a new", fals
e), |
211 » » » » makeTestFile("some/executable", "data b new", tr
ue), | 210 » » » » NewTestFile("some/executable", "data b new", tru
e), |
212 » » » » makeTestFile("mode change 1", "data d", false), | 211 » » » » NewTestFile("mode change 1", "data d", false), |
213 » » » » makeTestFile("mode change 2", "data d", true), | 212 » » » » NewTestFile("mode change 2", "data d", true), |
214 » » » » makeTestSymlink("symlink unchanged", "target"), | 213 » » » » NewTestSymlink("symlink unchanged", "target"), |
215 » » » » makeTestSymlink("symlink changed", "new target")
, | 214 » » » » NewTestSymlink("symlink changed", "new target"), |
216 }) | 215 }) |
217 newPkg.instanceID = "11111111111111111111111111111111111
11111" | 216 newPkg.instanceID = "11111111111111111111111111111111111
11111" |
218 | 217 |
219 _, err := DeployInstance(tempDir, oldPkg) | 218 _, err := DeployInstance(tempDir, oldPkg) |
220 So(err, ShouldBeNil) | 219 So(err, ShouldBeNil) |
221 _, err = DeployInstance(tempDir, newPkg) | 220 _, err = DeployInstance(tempDir, newPkg) |
222 So(err, ShouldBeNil) | 221 So(err, ShouldBeNil) |
223 | 222 |
224 So(scanDir(tempDir), ShouldResemble, []string{ | 223 So(scanDir(tempDir), ShouldResemble, []string{ |
225 ".cipd/pkgs/test_package_B6R4ErK5ko/111111111111
1111111111111111111111111111/.cipdpkg/manifest.json", | 224 ".cipd/pkgs/test_package_B6R4ErK5ko/111111111111
1111111111111111111111111111/.cipdpkg/manifest.json", |
226 ".cipd/pkgs/test_package_B6R4ErK5ko/111111111111
1111111111111111111111111111/mode change 1", | 225 ".cipd/pkgs/test_package_B6R4ErK5ko/111111111111
1111111111111111111111111111/mode change 1", |
227 ".cipd/pkgs/test_package_B6R4ErK5ko/111111111111
1111111111111111111111111111/mode change 2*", | 226 ".cipd/pkgs/test_package_B6R4ErK5ko/111111111111
1111111111111111111111111111/mode change 2*", |
228 ".cipd/pkgs/test_package_B6R4ErK5ko/111111111111
1111111111111111111111111111/some/executable*", | 227 ".cipd/pkgs/test_package_B6R4ErK5ko/111111111111
1111111111111111111111111111/some/executable*", |
229 ".cipd/pkgs/test_package_B6R4ErK5ko/111111111111
1111111111111111111111111111/some/file/path", | 228 ".cipd/pkgs/test_package_B6R4ErK5ko/111111111111
1111111111111111111111111111/some/file/path", |
230 ".cipd/pkgs/test_package_B6R4ErK5ko/111111111111
1111111111111111111111111111/symlink changed:new target", | 229 ".cipd/pkgs/test_package_B6R4ErK5ko/111111111111
1111111111111111111111111111/symlink changed:new target", |
231 ".cipd/pkgs/test_package_B6R4ErK5ko/111111111111
1111111111111111111111111111/symlink unchanged:target", | 230 ".cipd/pkgs/test_package_B6R4ErK5ko/111111111111
1111111111111111111111111111/symlink unchanged:target", |
232 ".cipd/pkgs/test_package_B6R4ErK5ko/_current:111
1111111111111111111111111111111111111", | 231 ".cipd/pkgs/test_package_B6R4ErK5ko/_current:111
1111111111111111111111111111111111111", |
233 "mode change 1:.cipd/pkgs/test_package_B6R4ErK5k
o/_current/mode change 1", | 232 "mode change 1:.cipd/pkgs/test_package_B6R4ErK5k
o/_current/mode change 1", |
234 "mode change 2:.cipd/pkgs/test_package_B6R4ErK5k
o/_current/mode change 2", | 233 "mode change 2:.cipd/pkgs/test_package_B6R4ErK5k
o/_current/mode change 2", |
235 "some/executable:../.cipd/pkgs/test_package_B6R4
ErK5ko/_current/some/executable", | 234 "some/executable:../.cipd/pkgs/test_package_B6R4
ErK5ko/_current/some/executable", |
236 "some/file/path:../../.cipd/pkgs/test_package_B6
R4ErK5ko/_current/some/file/path", | 235 "some/file/path:../../.cipd/pkgs/test_package_B6
R4ErK5ko/_current/some/file/path", |
237 "symlink changed:.cipd/pkgs/test_package_B6R4ErK
5ko/_current/symlink changed", | 236 "symlink changed:.cipd/pkgs/test_package_B6R4ErK
5ko/_current/symlink changed", |
238 "symlink unchanged:.cipd/pkgs/test_package_B6R4E
rK5ko/_current/symlink unchanged", | 237 "symlink unchanged:.cipd/pkgs/test_package_B6R4E
rK5ko/_current/symlink unchanged", |
239 }) | 238 }) |
240 }) | 239 }) |
241 | 240 |
242 Convey("DeployInstance two different packages", func() { | 241 Convey("DeployInstance two different packages", func() { |
243 pkg1 := makeTestInstance("test/package", []File{ | 242 pkg1 := makeTestInstance("test/package", []File{ |
244 » » » » makeTestFile("some/file/path", "data a old", fal
se), | 243 » » » » NewTestFile("some/file/path", "data a old", fals
e), |
245 » » » » makeTestFile("some/executable", "data b old", tr
ue), | 244 » » » » NewTestFile("some/executable", "data b old", tru
e), |
246 » » » » makeTestFile("pkg1 file", "data c", false), | 245 » » » » NewTestFile("pkg1 file", "data c", false), |
247 }) | 246 }) |
248 pkg1.instanceID = "0000000000000000000000000000000000000
000" | 247 pkg1.instanceID = "0000000000000000000000000000000000000
000" |
249 | 248 |
250 // Nesting in package names is allowed. | 249 // Nesting in package names is allowed. |
251 pkg2 := makeTestInstance("test/package/another", []File{ | 250 pkg2 := makeTestInstance("test/package/another", []File{ |
252 » » » » makeTestFile("some/file/path", "data a new", fal
se), | 251 » » » » NewTestFile("some/file/path", "data a new", fals
e), |
253 » » » » makeTestFile("some/executable", "data b new", tr
ue), | 252 » » » » NewTestFile("some/executable", "data b new", tru
e), |
254 » » » » makeTestFile("pkg2 file", "data d", false), | 253 » » » » NewTestFile("pkg2 file", "data d", false), |
255 }) | 254 }) |
256 pkg2.instanceID = "1111111111111111111111111111111111111
111" | 255 pkg2.instanceID = "1111111111111111111111111111111111111
111" |
257 | 256 |
258 _, err := DeployInstance(tempDir, pkg1) | 257 _, err := DeployInstance(tempDir, pkg1) |
259 So(err, ShouldBeNil) | 258 So(err, ShouldBeNil) |
260 _, err = DeployInstance(tempDir, pkg2) | 259 _, err = DeployInstance(tempDir, pkg2) |
261 So(err, ShouldBeNil) | 260 So(err, ShouldBeNil) |
262 | 261 |
263 // TODO: Conflicting symlinks point to last installed pa
ckage, it is not | 262 // TODO: Conflicting symlinks point to last installed pa
ckage, it is not |
264 // very deterministic. | 263 // very deterministic. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 _, err = DeployInstance(tempDir, makeTestInstance("test/
pkg/456", nil)) | 312 _, err = DeployInstance(tempDir, makeTestInstance("test/
pkg/456", nil)) |
314 So(err, ShouldBeNil) | 313 So(err, ShouldBeNil) |
315 _, err = DeployInstance(tempDir, makeTestInstance("test/
pkg", nil)) | 314 _, err = DeployInstance(tempDir, makeTestInstance("test/
pkg", nil)) |
316 So(err, ShouldBeNil) | 315 So(err, ShouldBeNil) |
317 _, err = DeployInstance(tempDir, makeTestInstance("test"
, nil)) | 316 _, err = DeployInstance(tempDir, makeTestInstance("test"
, nil)) |
318 So(err, ShouldBeNil) | 317 So(err, ShouldBeNil) |
319 | 318 |
320 // Verify it is discoverable. | 319 // Verify it is discoverable. |
321 out, err := FindDeployed(tempDir) | 320 out, err := FindDeployed(tempDir) |
322 So(err, ShouldBeNil) | 321 So(err, ShouldBeNil) |
323 » » » So(out, ShouldResemble, []PackageState{ | 322 » » » So(out, ShouldResemble, []Pin{ |
324 » » » » PackageState{ | 323 » » » » {"test", "0123456789abcdef00000123456789abcdef00
00"}, |
325 » » » » » PackageName: "test", | 324 » » » » {"test/pkg", "0123456789abcdef00000123456789abcd
ef0000"}, |
326 » » » » » InstanceID: "0123456789abcdef0000012345
6789abcdef0000", | 325 » » » » {"test/pkg/123", "0123456789abcdef00000123456789
abcdef0000"}, |
327 » » » » }, | 326 » » » » {"test/pkg/456", "0123456789abcdef00000123456789
abcdef0000"}, |
328 » » » » PackageState{ | |
329 » » » » » PackageName: "test/pkg", | |
330 » » » » » InstanceID: "0123456789abcdef0000012345
6789abcdef0000", | |
331 » » » » }, | |
332 » » » » PackageState{ | |
333 » » » » » PackageName: "test/pkg/123", | |
334 » » » » » InstanceID: "0123456789abcdef0000012345
6789abcdef0000", | |
335 » » » » }, | |
336 » » » » PackageState{ | |
337 » » » » » PackageName: "test/pkg/456", | |
338 » » » » » InstanceID: "0123456789abcdef0000012345
6789abcdef0000", | |
339 » » » » }, | |
340 }) | 327 }) |
341 }) | 328 }) |
342 }) | 329 }) |
343 } | 330 } |
344 | 331 |
345 func TestRemoveDeployed(t *testing.T) { | 332 func TestRemoveDeployed(t *testing.T) { |
346 Convey("Given a temp directory", t, func() { | 333 Convey("Given a temp directory", t, func() { |
347 tempDir, err := ioutil.TempDir("", "cipd_test") | 334 tempDir, err := ioutil.TempDir("", "cipd_test") |
348 So(err, ShouldBeNil) | 335 So(err, ShouldBeNil) |
349 Reset(func() { os.RemoveAll(tempDir) }) | 336 Reset(func() { os.RemoveAll(tempDir) }) |
350 | 337 |
351 Convey("RemoveDeployed works with missing package", func() { | 338 Convey("RemoveDeployed works with missing package", func() { |
352 err := RemoveDeployed(tempDir, "package/path") | 339 err := RemoveDeployed(tempDir, "package/path") |
353 So(err, ShouldBeNil) | 340 So(err, ShouldBeNil) |
354 }) | 341 }) |
355 | 342 |
356 Convey("RemoveDeployed works", func() { | 343 Convey("RemoveDeployed works", func() { |
357 // Deploy some instance (to keep it). | 344 // Deploy some instance (to keep it). |
358 inst := makeTestInstance("test/package/123", []File{ | 345 inst := makeTestInstance("test/package/123", []File{ |
359 » » » » makeTestFile("some/file/path1", "data a", false)
, | 346 » » » » NewTestFile("some/file/path1", "data a", false), |
360 » » » » makeTestFile("some/executable1", "data b", true)
, | 347 » » » » NewTestFile("some/executable1", "data b", true), |
361 }) | 348 }) |
362 _, err := DeployInstance(tempDir, inst) | 349 _, err := DeployInstance(tempDir, inst) |
363 So(err, ShouldBeNil) | 350 So(err, ShouldBeNil) |
364 | 351 |
365 // Deploy another instance (to remove it). | 352 // Deploy another instance (to remove it). |
366 inst = makeTestInstance("test/package", []File{ | 353 inst = makeTestInstance("test/package", []File{ |
367 » » » » makeTestFile("some/file/path2", "data a", false)
, | 354 » » » » NewTestFile("some/file/path2", "data a", false), |
368 » » » » makeTestFile("some/executable2", "data b", true)
, | 355 » » » » NewTestFile("some/executable2", "data b", true), |
369 » » » » makeTestSymlink("some/symlink", "executable"), | 356 » » » » NewTestSymlink("some/symlink", "executable"), |
370 }) | 357 }) |
371 _, err = DeployInstance(tempDir, inst) | 358 _, err = DeployInstance(tempDir, inst) |
372 So(err, ShouldBeNil) | 359 So(err, ShouldBeNil) |
373 | 360 |
374 // Now remove the second package. | 361 // Now remove the second package. |
375 err = RemoveDeployed(tempDir, "test/package") | 362 err = RemoveDeployed(tempDir, "test/package") |
376 So(err, ShouldBeNil) | 363 So(err, ShouldBeNil) |
377 | 364 |
378 // Verify the final state (only first package should sur
vive). | 365 // Verify the final state (only first package should sur
vive). |
379 So(scanDir(tempDir), ShouldResemble, []string{ | 366 So(scanDir(tempDir), ShouldResemble, []string{ |
(...skipping 20 matching lines...) Expand all Loading... |
400 func makeTestInstance(name string, files []File) *testPackageInstance { | 387 func makeTestInstance(name string, files []File) *testPackageInstance { |
401 // Generate and append manifest file. | 388 // Generate and append manifest file. |
402 out := bytes.Buffer{} | 389 out := bytes.Buffer{} |
403 err := writeManifest(&Manifest{ | 390 err := writeManifest(&Manifest{ |
404 FormatVersion: manifestFormatVersion, | 391 FormatVersion: manifestFormatVersion, |
405 PackageName: name, | 392 PackageName: name, |
406 }, &out) | 393 }, &out) |
407 if err != nil { | 394 if err != nil { |
408 panic("Failed to write a manifest") | 395 panic("Failed to write a manifest") |
409 } | 396 } |
410 » files = append(files, makeTestFile(manifestName, string(out.Bytes()), fa
lse)) | 397 » files = append(files, NewTestFile(manifestName, string(out.Bytes()), fal
se)) |
411 return &testPackageInstance{ | 398 return &testPackageInstance{ |
412 packageName: name, | 399 packageName: name, |
413 instanceID: "0123456789abcdef00000123456789abcdef0000", | 400 instanceID: "0123456789abcdef00000123456789abcdef0000", |
414 files: files, | 401 files: files, |
415 } | 402 } |
416 } | 403 } |
417 | 404 |
418 func (f *testPackageInstance) Close() error { return nil } | 405 func (f *testPackageInstance) Close() error { return nil } |
419 func (f *testPackageInstance) PackageName() string { return f.packageName
} | 406 func (f *testPackageInstance) Pin() Pin { return Pin{f.packageN
ame, f.instanceID} } |
420 func (f *testPackageInstance) InstanceID() string { return f.instanceID } | |
421 func (f *testPackageInstance) Files() []File { return f.files } | 407 func (f *testPackageInstance) Files() []File { return f.files } |
422 func (f *testPackageInstance) DataReader() io.ReadSeeker { panic("Not implemente
d") } | 408 func (f *testPackageInstance) DataReader() io.ReadSeeker { panic("Not implemente
d") } |
423 | 409 |
424 //////////////////////////////////////////////////////////////////////////////// | 410 //////////////////////////////////////////////////////////////////////////////// |
425 | 411 |
426 // scanDir returns list of files (regular and symlinks) it finds in a directory. | 412 // scanDir returns list of files (regular and symlinks) it finds in a directory. |
427 // Symlinks are returned as "path:target". Regular executable files are suffixed | 413 // Symlinks are returned as "path:target". Regular executable files are suffixed |
428 // with '*'. All paths are relative to the scanned directory and slash | 414 // with '*'. All paths are relative to the scanned directory and slash |
429 // separated. Symlink targets are slash separated too, but otherwise not | 415 // separated. Symlink targets are slash separated too, but otherwise not |
430 // modified. Does not look inside symlinked directories. | 416 // modified. Does not look inside symlinked directories. |
(...skipping 29 matching lines...) Expand all Loading... |
460 } | 446 } |
461 | 447 |
462 out = append(out, item+suffix) | 448 out = append(out, item+suffix) |
463 return nil | 449 return nil |
464 }) | 450 }) |
465 if err != nil { | 451 if err != nil { |
466 panic("Failed to walk a directory") | 452 panic("Failed to walk a directory") |
467 } | 453 } |
468 return | 454 return |
469 } | 455 } |
OLD | NEW |