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 "io" | 9 "io" |
10 "io/ioutil" | 10 "io/ioutil" |
11 "os" | 11 "os" |
12 "testing" | 12 "testing" |
13 | 13 |
14 . "github.com/smartystreets/goconvey/convey" | 14 . "github.com/smartystreets/goconvey/convey" |
| 15 |
| 16 . "infra/tools/cipd/common" |
15 ) | 17 ) |
16 | 18 |
17 func TestPackageReading(t *testing.T) { | 19 func TestPackageReading(t *testing.T) { |
18 goodManifest := `{ | 20 goodManifest := `{ |
19 "format_version": "1", | 21 "format_version": "1", |
20 "package_name": "testing" | 22 "package_name": "testing" |
21 }` | 23 }` |
22 | 24 |
23 Convey("Open empty package works", t, func() { | 25 Convey("Open empty package works", t, func() { |
24 // Build an empty package. | 26 // Build an empty package. |
25 out := bytes.Buffer{} | 27 out := bytes.Buffer{} |
26 err := BuildInstance(BuildInstanceOptions{ | 28 err := BuildInstance(BuildInstanceOptions{ |
27 Output: &out, | 29 Output: &out, |
28 PackageName: "testing", | 30 PackageName: "testing", |
29 }) | 31 }) |
30 So(err, ShouldBeNil) | 32 So(err, ShouldBeNil) |
31 | 33 |
32 // Open it. | 34 // Open it. |
33 inst, err := OpenInstance(bytes.NewReader(out.Bytes()), "") | 35 inst, err := OpenInstance(bytes.NewReader(out.Bytes()), "") |
34 if inst != nil { | 36 if inst != nil { |
35 defer inst.Close() | 37 defer inst.Close() |
36 } | 38 } |
37 So(inst, ShouldNotBeNil) | 39 So(inst, ShouldNotBeNil) |
38 So(err, ShouldBeNil) | 40 So(err, ShouldBeNil) |
39 » » So(inst.PackageName(), ShouldEqual, "testing") | 41 » » So(inst.Pin(), ShouldResemble, Pin{"testing", "23f2c4900785ac8fa
a2f38e473925b840e574ccc"}) |
40 » » So(inst.InstanceID(), ShouldEqual, "23f2c4900785ac8faa2f38e47392
5b840e574ccc") | |
41 So(len(inst.Files()), ShouldEqual, 1) | 42 So(len(inst.Files()), ShouldEqual, 1) |
42 | 43 |
43 // Contains single manifest file. | 44 // Contains single manifest file. |
44 f := inst.Files()[0] | 45 f := inst.Files()[0] |
45 So(f.Name(), ShouldEqual, ".cipdpkg/manifest.json") | 46 So(f.Name(), ShouldEqual, ".cipdpkg/manifest.json") |
46 So(f.Size(), ShouldEqual, uint64(len(goodManifest))) | 47 So(f.Size(), ShouldEqual, uint64(len(goodManifest))) |
47 So(f.Executable(), ShouldBeFalse) | 48 So(f.Executable(), ShouldBeFalse) |
48 r, err := f.Open() | 49 r, err := f.Open() |
49 if r != nil { | 50 if r != nil { |
50 defer r.Close() | 51 defer r.Close() |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 } | 100 } |
100 So(inst, ShouldNotBeNil) | 101 So(inst, ShouldNotBeNil) |
101 So(err, ShouldBeNil) | 102 So(err, ShouldBeNil) |
102 }) | 103 }) |
103 | 104 |
104 Convey("ExtractInstance works", t, func() { | 105 Convey("ExtractInstance works", t, func() { |
105 // Add a bunch of files to a package. | 106 // Add a bunch of files to a package. |
106 out := bytes.Buffer{} | 107 out := bytes.Buffer{} |
107 err := BuildInstance(BuildInstanceOptions{ | 108 err := BuildInstance(BuildInstanceOptions{ |
108 Input: []File{ | 109 Input: []File{ |
109 » » » » makeTestFile("testing/qwerty", "12345", false), | 110 » » » » NewTestFile("testing/qwerty", "12345", false), |
110 » » » » makeTestFile("abc", "duh", true), | 111 » » » » NewTestFile("abc", "duh", true), |
111 » » » » makeTestSymlink("rel_symlink", "abc"), | 112 » » » » NewTestSymlink("rel_symlink", "abc"), |
112 » » » » makeTestSymlink("abs_symlink", "/abc/def"), | 113 » » » » NewTestSymlink("abs_symlink", "/abc/def"), |
113 }, | 114 }, |
114 Output: &out, | 115 Output: &out, |
115 PackageName: "testing", | 116 PackageName: "testing", |
116 }) | 117 }) |
117 So(err, ShouldBeNil) | 118 So(err, ShouldBeNil) |
118 | 119 |
119 // Extract files. | 120 // Extract files. |
120 inst, err := OpenInstance(bytes.NewReader(out.Bytes()), "") | 121 inst, err := OpenInstance(bytes.NewReader(out.Bytes()), "") |
121 if inst != nil { | 122 if inst != nil { |
122 defer inst.Close() | 123 defer inst.Close() |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 symlinkTarget: target, | 185 symlinkTarget: target, |
185 } | 186 } |
186 d.files = append(d.files, f) | 187 d.files = append(d.files, f) |
187 return nil | 188 return nil |
188 } | 189 } |
189 | 190 |
190 func (d *testDestination) End(success bool) error { | 191 func (d *testDestination) End(success bool) error { |
191 d.endCalls++ | 192 d.endCalls++ |
192 return nil | 193 return nil |
193 } | 194 } |
OLD | NEW |