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

Side by Side Diff: client/isolate/isolate_test.go

Issue 2937663002: Sever isolate package's dependency on client/internal. (Closed)
Patch Set: Created 3 years, 6 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 | « client/isolate/isolate.go ('k') | client/isolate/utils.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 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 package isolate 5 package isolate
6 6
7 import ( 7 import (
8 "encoding/json" 8 "encoding/json"
9 "io/ioutil" 9 "io/ioutil"
10 "log" 10 "log"
11 "net/http/httptest" 11 "net/http/httptest"
12 "os" 12 "os"
13 "path/filepath" 13 "path/filepath"
14 "strings" 14 "strings"
15 "testing" 15 "testing"
16 16
17 "golang.org/x/net/context" 17 "golang.org/x/net/context"
18 18
19 "github.com/luci/luci-go/client/archiver" 19 "github.com/luci/luci-go/client/archiver"
20 "github.com/luci/luci-go/client/internal/common"
21 isolateservice "github.com/luci/luci-go/common/api/isolate/isolateservic e/v1" 20 isolateservice "github.com/luci/luci-go/common/api/isolate/isolateservic e/v1"
22 "github.com/luci/luci-go/common/data/text/units" 21 "github.com/luci/luci-go/common/data/text/units"
22 "github.com/luci/luci-go/common/flag/stringlistflag"
23 "github.com/luci/luci-go/common/isolated" 23 "github.com/luci/luci-go/common/isolated"
24 "github.com/luci/luci-go/common/isolatedclient" 24 "github.com/luci/luci-go/common/isolatedclient"
25 "github.com/luci/luci-go/common/isolatedclient/isolatedfake" 25 "github.com/luci/luci-go/common/isolatedclient/isolatedfake"
26 26
27 . "github.com/smartystreets/goconvey/convey" 27 . "github.com/smartystreets/goconvey/convey"
28 ) 28 )
29 29
30 func init() { 30 func init() {
31 log.SetOutput(ioutil.Discard) 31 log.SetOutput(ioutil.Discard)
32 } 32 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 }], 104 }],
105 ['OS=="win"', { 105 ['OS=="win"', {
106 'variables': { 106 'variables': {
107 'command': ['win'], 107 'command': ['win'],
108 }, 108 },
109 }], 109 }],
110 ], 110 ],
111 }` 111 }`
112 isolatePath := filepath.Join(fooDir, "baz.isolate") 112 isolatePath := filepath.Join(fooDir, "baz.isolate")
113 So(ioutil.WriteFile(isolatePath, []byte(isolate), 0600), ShouldB eNil) 113 So(ioutil.WriteFile(isolatePath, []byte(isolate), 0600), ShouldB eNil)
114 » » if !common.IsWindows() { 114 » » if !IsWindows() {
115 So(os.Symlink(filepath.Join("base", "bar"), filepath.Joi n(tmpDir, "link")), ShouldBeNil) 115 So(os.Symlink(filepath.Join("base", "bar"), filepath.Joi n(tmpDir, "link")), ShouldBeNil)
116 } else { 116 } else {
117 So(ioutil.WriteFile(filepath.Join(tmpDir, "link"), []byt e("no link on Windows"), 0600), ShouldBeNil) 117 So(ioutil.WriteFile(filepath.Join(tmpDir, "link"), []byt e("no link on Windows"), 0600), ShouldBeNil)
118 } 118 }
119 opts := &ArchiveOptions{ 119 opts := &ArchiveOptions{
120 Isolate: isolatePath, 120 Isolate: isolatePath,
121 Isolated: filepath.Join(tmpDir, "baz.isolated"), 121 Isolated: filepath.Join(tmpDir, "baz.isolated"),
122 » » » Blacklist: common.Strings{"ignored", "*.isolate"}, 122 » » » Blacklist: stringlistflag.Flag{"ignored", "*.isola te"},
123 PathVariables: map[string]string{"VAR": "wonderful"}, 123 PathVariables: map[string]string{"VAR": "wonderful"},
124 ExtraVariables: map[string]string{"EXTRA": "really"}, 124 ExtraVariables: map[string]string{"EXTRA": "really"},
125 ConfigVariables: map[string]string{"OS": "amiga"}, 125 ConfigVariables: map[string]string{"OS": "amiga"},
126 } 126 }
127 item := Archive(a, opts) 127 item := Archive(a, opts)
128 So(item.DisplayName, ShouldResemble, "baz.isolated") 128 So(item.DisplayName, ShouldResemble, "baz.isolated")
129 item.WaitForHashed() 129 item.WaitForHashed()
130 So(item.Error(), ShouldBeNil) 130 So(item.Error(), ShouldBeNil)
131 So(a.Close(), ShouldBeNil) 131 So(a.Close(), ShouldBeNil)
132 132
133 mode := 0600 133 mode := 0600
134 » » if common.IsWindows() { 134 » » if IsWindows() {
135 mode = 0666 135 mode = 0666
136 } 136 }
137 137
138 // /base/ 138 // /base/
139 baseIsolatedData := isolated.Isolated{ 139 baseIsolatedData := isolated.Isolated{
140 Algo: "sha-1", 140 Algo: "sha-1",
141 Files: map[string]isolated.File{ 141 Files: map[string]isolated.File{
142 filepath.Join("base", "bar"): isolated.BasicFile ("0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33", mode, 3), 142 filepath.Join("base", "bar"): isolated.BasicFile ("0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33", mode, 3),
143 }, 143 },
144 Version: isolated.IsolatedFormatVersion, 144 Version: isolated.IsolatedFormatVersion,
(...skipping 18 matching lines...) Expand all
163 163
164 isolatedData := isolated.Isolated{ 164 isolatedData := isolated.Isolated{
165 Algo: "sha-1", 165 Algo: "sha-1",
166 Command: []string{"amiga", "really"}, 166 Command: []string{"amiga", "really"},
167 Files: map[string]isolated.File{}, 167 Files: map[string]isolated.File{},
168 // This list must be in deterministic order. 168 // This list must be in deterministic order.
169 Includes: isolated.HexDigests{baseIsolatedHash, secon dIsolatedHash}, 169 Includes: isolated.HexDigests{baseIsolatedHash, secon dIsolatedHash},
170 RelativeCwd: "foo", 170 RelativeCwd: "foo",
171 Version: isolated.IsolatedFormatVersion, 171 Version: isolated.IsolatedFormatVersion,
172 } 172 }
173 » » if !common.IsWindows() { 173 » » if !IsWindows() {
174 isolatedData.Files["link"] = isolated.SymLink(filepath.J oin("base", "bar")) 174 isolatedData.Files["link"] = isolated.SymLink(filepath.J oin("base", "bar"))
175 } else { 175 } else {
176 isolatedData.Files["link"] = isolated.BasicFile("12339b9 756c2994f85c310d560bc8c142a6b79a1", 0666, 18) 176 isolatedData.Files["link"] = isolated.BasicFile("12339b9 756c2994f85c310d560bc8c142a6b79a1", 0666, 18)
177 } 177 }
178 encoded, err = json.Marshal(isolatedData) 178 encoded, err = json.Marshal(isolatedData)
179 So(err, ShouldBeNil) 179 So(err, ShouldBeNil)
180 isolatedEncoded := string(encoded) + "\n" 180 isolatedEncoded := string(encoded) + "\n"
181 isolatedHash := isolated.HashBytes([]byte(isolatedEncoded)) 181 isolatedHash := isolated.HashBytes([]byte(isolatedEncoded))
182 182
183 expected := map[string]string{ 183 expected := map[string]string{
184 "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33": "foo", 184 "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33": "foo",
185 "aaadd94977b8fbf3f6fb09fc3bbbc9edbdfa8427": "foo2", 185 "aaadd94977b8fbf3f6fb09fc3bbbc9edbdfa8427": "foo2",
186 string(baseIsolatedHash): baseIsolated Encoded, 186 string(baseIsolatedHash): baseIsolated Encoded,
187 string(isolatedHash): isolatedEnco ded, 187 string(isolatedHash): isolatedEnco ded,
188 string(secondIsolatedHash): secondIsolat edEncoded, 188 string(secondIsolatedHash): secondIsolat edEncoded,
189 } 189 }
190 » » if common.IsWindows() { 190 » » if IsWindows() {
191 expected["12339b9756c2994f85c310d560bc8c142a6b79a1"] = " no link on Windows" 191 expected["12339b9756c2994f85c310d560bc8c142a6b79a1"] = " no link on Windows"
192 } 192 }
193 actual := map[string]string{} 193 actual := map[string]string{}
194 for k, v := range server.Contents() { 194 for k, v := range server.Contents() {
195 actual[string(k)] = string(v) 195 actual[string(k)] = string(v)
196 So(actual[string(k)], ShouldResemble, expected[string(k) ]) 196 So(actual[string(k)], ShouldResemble, expected[string(k) ])
197 } 197 }
198 So(actual, ShouldResemble, expected) 198 So(actual, ShouldResemble, expected)
199 So(item.Digest(), ShouldResemble, isolatedHash) 199 So(item.Digest(), ShouldResemble, isolatedHash)
200 200
201 stats := a.Stats() 201 stats := a.Stats()
202 So(stats.TotalHits(), ShouldBeZeroValue) 202 So(stats.TotalHits(), ShouldBeZeroValue)
203 So(stats.TotalBytesHits(), ShouldResemble, units.Size(0)) 203 So(stats.TotalBytesHits(), ShouldResemble, units.Size(0))
204 size := 3 + 4 + len(baseIsolatedEncoded) + len(isolatedEncoded) + len(secondIsolatedEncoded) 204 size := 3 + 4 + len(baseIsolatedEncoded) + len(isolatedEncoded) + len(secondIsolatedEncoded)
205 » » if !common.IsWindows() { 205 » » if !IsWindows() {
206 So(stats.TotalMisses(), ShouldEqual, 5) 206 So(stats.TotalMisses(), ShouldEqual, 5)
207 So(stats.TotalBytesPushed(), ShouldResemble, units.Size( size)) 207 So(stats.TotalBytesPushed(), ShouldResemble, units.Size( size))
208 } else { 208 } else {
209 So(stats.TotalMisses(), ShouldEqual, 6) 209 So(stats.TotalMisses(), ShouldEqual, 6)
210 // Includes the duplicate due to lack of symlink. 210 // Includes the duplicate due to lack of symlink.
211 So(stats.TotalBytesPushed(), ShouldResemble, units.Size( size+18)) 211 So(stats.TotalBytesPushed(), ShouldResemble, units.Size( size+18))
212 } 212 }
213 213
214 So(server.Error(), ShouldBeNil) 214 So(server.Error(), ShouldBeNil)
215 digest, err := isolated.HashFile(filepath.Join(tmpDir, "baz.isol ated")) 215 digest, err := isolated.HashFile(filepath.Join(tmpDir, "baz.isol ated"))
(...skipping 15 matching lines...) Expand all
231 } 231 }
232 item := Archive(a, opts) 232 item := Archive(a, opts)
233 item.WaitForHashed() 233 item.WaitForHashed()
234 err := item.Error() 234 err := item.Error()
235 So(strings.HasPrefix(err.Error(), "open /this-file-does-not-exis t: "), ShouldBeTrue) 235 So(strings.HasPrefix(err.Error(), "open /this-file-does-not-exis t: "), ShouldBeTrue)
236 closeErr := a.Close() 236 closeErr := a.Close()
237 So(closeErr, ShouldNotBeNil) 237 So(closeErr, ShouldNotBeNil)
238 So(strings.HasPrefix(closeErr.Error(), "open /this-file-does-not -exist: "), ShouldBeTrue) 238 So(strings.HasPrefix(closeErr.Error(), "open /this-file-does-not -exist: "), ShouldBeTrue)
239 }) 239 })
240 } 240 }
OLDNEW
« no previous file with comments | « client/isolate/isolate.go ('k') | client/isolate/utils.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698