Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(338)

Side by Side Diff: go/src/infra/tools/cipd/local/builder_test.go

Issue 1129043003: cipd: Refactor client to make it more readable. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « go/src/infra/tools/cipd/local/builder.go ('k') | go/src/infra/tools/cipd/local/deployer.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "archive/zip" 8 "archive/zip"
9 "bytes" 9 "bytes"
10 "crypto/sha1" 10 "crypto/sha1"
11 "encoding/hex" 11 "encoding/hex"
12 "fmt"
13 "io"
14 "io/ioutil" 12 "io/ioutil"
15 "os" 13 "os"
16 "runtime" 14 "runtime"
17 "testing" 15 "testing"
18 16
19 . "github.com/smartystreets/goconvey/convey" 17 . "github.com/smartystreets/goconvey/convey"
20 ) 18 )
21 19
22 func TestGoVersion(t *testing.T) { 20 func TestGoVersion(t *testing.T) {
23 Convey("Make sure using pinned Go version", t, func() { 21 Convey("Make sure using pinned Go version", t, func() {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 mode: 0600, 54 mode: 0600,
57 body: []byte(goodManifest), 55 body: []byte(goodManifest),
58 }, 56 },
59 }) 57 })
60 }) 58 })
61 59
62 Convey("Building package with a bunch of files", t, func() { 60 Convey("Building package with a bunch of files", t, func() {
63 out := bytes.Buffer{} 61 out := bytes.Buffer{}
64 err := BuildInstance(BuildInstanceOptions{ 62 err := BuildInstance(BuildInstanceOptions{
65 Input: []File{ 63 Input: []File{
66 » » » » makeTestFile("testing/qwerty", "12345", false), 64 » » » » NewTestFile("testing/qwerty", "12345", false),
67 » » » » makeTestFile("abc", "duh", true), 65 » » » » NewTestFile("abc", "duh", true),
68 » » » » makeTestSymlink("rel_symlink", "abc"), 66 » » » » NewTestSymlink("rel_symlink", "abc"),
69 » » » » makeTestSymlink("abs_symlink", "/abc/def"), 67 » » » » NewTestSymlink("abs_symlink", "/abc/def"),
70 }, 68 },
71 Output: &out, 69 Output: &out,
72 PackageName: "testing", 70 PackageName: "testing",
73 }) 71 })
74 So(err, ShouldBeNil) 72 So(err, ShouldBeNil)
75 73
76 // The manifest and all added files. 74 // The manifest and all added files.
77 files := readZip(out.Bytes()) 75 files := readZip(out.Bytes())
78 So(files, ShouldResemble, []zippedFile{ 76 So(files, ShouldResemble, []zippedFile{
79 zippedFile{ 77 zippedFile{
(...skipping 26 matching lines...) Expand all
106 size: uint64(len(goodManifest)), 104 size: uint64(len(goodManifest)),
107 mode: 0600, 105 mode: 0600,
108 body: []byte(goodManifest), 106 body: []byte(goodManifest),
109 }, 107 },
110 }) 108 })
111 }) 109 })
112 110
113 Convey("Duplicate files fail", t, func() { 111 Convey("Duplicate files fail", t, func() {
114 err := BuildInstance(BuildInstanceOptions{ 112 err := BuildInstance(BuildInstanceOptions{
115 Input: []File{ 113 Input: []File{
116 » » » » makeTestFile("a", "12345", false), 114 » » » » NewTestFile("a", "12345", false),
117 » » » » makeTestFile("a", "12345", false), 115 » » » » NewTestFile("a", "12345", false),
118 }, 116 },
119 Output: &bytes.Buffer{}, 117 Output: &bytes.Buffer{},
120 PackageName: "testing", 118 PackageName: "testing",
121 }) 119 })
122 So(err, ShouldNotBeNil) 120 So(err, ShouldNotBeNil)
123 }) 121 })
124 122
125 Convey("Writing to service dir fails", t, func() { 123 Convey("Writing to service dir fails", t, func() {
126 err := BuildInstance(BuildInstanceOptions{ 124 err := BuildInstance(BuildInstanceOptions{
127 Input: []File{ 125 Input: []File{
128 » » » » makeTestFile(".cipdpkg/stuff", "12345", false), 126 » » » » NewTestFile(".cipdpkg/stuff", "12345", false),
129 }, 127 },
130 Output: &bytes.Buffer{}, 128 Output: &bytes.Buffer{},
131 PackageName: "testing", 129 PackageName: "testing",
132 }) 130 })
133 So(err, ShouldNotBeNil) 131 So(err, ShouldNotBeNil)
134 }) 132 })
135 133
136 Convey("Bad name fails", t, func() { 134 Convey("Bad name fails", t, func() {
137 err := BuildInstance(BuildInstanceOptions{ 135 err := BuildInstance(BuildInstanceOptions{
138 Output: &bytes.Buffer{}, 136 Output: &bytes.Buffer{},
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } 177 }
180 files[i] = zippedFile{ 178 files[i] = zippedFile{
181 name: zf.Name, 179 name: zf.Name,
182 size: zf.FileHeader.UncompressedSize64, 180 size: zf.FileHeader.UncompressedSize64,
183 mode: zf.Mode(), 181 mode: zf.Mode(),
184 body: body, 182 body: body,
185 } 183 }
186 } 184 }
187 return files 185 return files
188 } 186 }
189
190 ////////////////////////////////////////////////////////////////////////////////
191
192 type testFile struct {
193 name string
194 data string
195 executable bool
196 symlinkTarget string
197 }
198
199 func (f *testFile) Name() string { return f.name }
200 func (f *testFile) Size() uint64 { return uint64(len(f.data)) }
201 func (f *testFile) Executable() bool { return f.executable }
202 func (f *testFile) Symlink() bool { return f.symlinkTarget != "" }
203
204 func (f *testFile) SymlinkTarget() (string, error) {
205 if f.symlinkTarget == "" {
206 return "", fmt.Errorf("Not a symlink: %s", f.Name())
207 }
208 return f.symlinkTarget, nil
209 }
210
211 func (f *testFile) Open() (io.ReadCloser, error) {
212 if f.Symlink() {
213 return nil, fmt.Errorf("Can't open symlink: %s", f.Name())
214 }
215 r := bytes.NewReader([]byte(f.data))
216 return ioutil.NopCloser(r), nil
217 }
218
219 func makeTestFile(name string, data string, executable bool) File {
220 return &testFile{
221 name: name,
222 data: data,
223 executable: executable,
224 }
225 }
226
227 func makeTestSymlink(name string, target string) File {
228 return &testFile{
229 name: name,
230 symlinkTarget: target,
231 }
232 }
OLDNEW
« no previous file with comments | « go/src/infra/tools/cipd/local/builder.go ('k') | go/src/infra/tools/cipd/local/deployer.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698