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

Side by Side Diff: client/cmd/isolate/exp_archive_test.go

Issue 2981223003: Reuse blacklisting code in exp_archive. (Closed)
Patch Set: address review comments Created 3 years, 5 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/cmd/isolate/exp_archive.go ('k') | client/internal/common/filesystem_view.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 2017 The LUCI Authors. 1 // Copyright 2017 The LUCI Authors.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 package main 15 package main
16 16
17 import ( 17 import (
18 "errors" 18 "errors"
19 "os" 19 "os"
20 "reflect" 20 "reflect"
21 "testing" 21 "testing"
22
23 "github.com/luci/luci-go/client/internal/common"
22 ) 24 )
23 25
24 // basicFileInfo implements some of os.FileInfo, and panics if unexpected parts 26 // basicFileInfo implements some of os.FileInfo, and panics if unexpected parts
25 // of that interface are called. 27 // of that interface are called.
26 type basicFileInfo struct { 28 type basicFileInfo struct {
27 size int64 29 size int64
28 mode os.FileMode 30 mode os.FileMode
29 isDir bool 31 isDir bool
30 32
31 os.FileInfo 33 os.FileInfo
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 bfi: basicFileInfo{ 70 bfi: basicFileInfo{
69 size: 0, 71 size: 0,
70 mode: os.ModeDir, 72 mode: os.ModeDir,
71 isDir: true, 73 isDir: true,
72 }, 74 },
73 } 75 }
74 } 76 }
75 77
76 var errBang = errors.New("bang") 78 var errBang = errors.New("bang")
77 79
80 // fsView constructs a FilesystemView with no blacklist.
81 func fsView(root string) common.FilesystemView {
82 fsView, err := common.NewFilesystemView("/rootDir", nil)
83 if err != nil {
84 // NewFilesystemView only fails due to bad blacklists. So this s hould never occur.
85 panic("unexpected failure to construct FilesytemView")
86 }
87 return fsView
88 }
89
78 func TestWalkFn(t *testing.T) { 90 func TestWalkFn(t *testing.T) {
79 type testCase struct { 91 type testCase struct {
80 name string 92 name string
81 files []file 93 files []file
82 walkFnErr error 94 walkFnErr error
83 want partitionedDeps 95 want partitionedDeps
84 } 96 }
85 97
86 testCases := []testCase{ 98 testCases := []testCase{
87 { 99 {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 }, 245 },
234 }, 246 },
235 totalSize: 1024 + 2048, 247 totalSize: 1024 + 2048,
236 }, 248 },
237 }, 249 },
238 }, 250 },
239 } 251 }
240 252
241 TestCases: 253 TestCases:
242 for _, tc := range testCases { 254 for _, tc := range testCases {
243 » » pw := partitioningWalker{rootDir: "/rootDir"} 255 » » pw := partitioningWalker{fsView: fsView("/rootDir")}
244 for _, f := range tc.files { 256 for _, f := range tc.files {
245 if err := pw.walkFn(f.path, f.bfi, tc.walkFnErr); err != nil { 257 if err := pw.walkFn(f.path, f.bfi, tc.walkFnErr); err != nil {
246 t.Errorf("partitioning deps(%s): walkFn got err %v; want nil", tc.name, err) 258 t.Errorf("partitioning deps(%s): walkFn got err %v; want nil", tc.name, err)
247 continue TestCases 259 continue TestCases
248 } 260 }
249 } 261 }
250 if got, want := pw.parts, tc.want; !reflect.DeepEqual(got, want) { 262 if got, want := pw.parts, tc.want; !reflect.DeepEqual(got, want) {
251 t.Errorf("partitioning deps(%s): got %#v; want %#v", tc. name, got, want) 263 t.Errorf("partitioning deps(%s): got %#v; want %#v", tc. name, got, want)
252 } 264 }
253 } 265 }
254 266
255 } 267 }
256 268
257 func TestWalkFn_BadRelpath(t *testing.T) { 269 func TestWalkFn_BadRelpath(t *testing.T) {
258 » pw := partitioningWalker{rootDir: "/rootDir"} 270 » pw := partitioningWalker{fsView: fsView("/rootDir")}
259 f := regularFile("./patha", 1) 271 f := regularFile("./patha", 1)
260 if err := pw.walkFn(f.path, f.bfi, nil); err == nil { 272 if err := pw.walkFn(f.path, f.bfi, nil); err == nil {
261 t.Errorf("testing bad relpath: walkFn returned nil err; want non -nil err") 273 t.Errorf("testing bad relpath: walkFn returned nil err; want non -nil err")
262 } 274 }
263 } 275 }
264 276
265 func TestWalkFn_ReturnsErrorsUnchanged(t *testing.T) { 277 func TestWalkFn_ReturnsErrorsUnchanged(t *testing.T) {
266 » pw := partitioningWalker{rootDir: "/rootDir"} 278 » pw := partitioningWalker{fsView: fsView("/rootDir")}
267 f := regularFile("/rootDir/patha", 1) 279 f := regularFile("/rootDir/patha", 1)
268 if err := pw.walkFn(f.path, f.bfi, errBang); err != errBang { 280 if err := pw.walkFn(f.path, f.bfi, errBang); err != errBang {
269 t.Errorf("walkFn err: got: %v; want %v", err, errBang) 281 t.Errorf("walkFn err: got: %v; want %v", err, errBang)
270 } 282 }
271 } 283 }
272 284
273 func TestWalkFn_DoesNothingForDirectories(t *testing.T) { 285 func TestWalkFn_DoesNothingForDirectories(t *testing.T) {
274 » pw := partitioningWalker{rootDir: "/rootDir"} 286 » pw := partitioningWalker{fsView: fsView("/rootDir")}
275 f := directory("/rootDir/patha") 287 f := directory("/rootDir/patha")
276 if err := pw.walkFn(f.path, f.bfi, nil); err != nil { 288 if err := pw.walkFn(f.path, f.bfi, nil); err != nil {
277 t.Errorf("walkFn err: got: %v; want nil", err) 289 t.Errorf("walkFn err: got: %v; want nil", err)
278 } 290 }
279 } 291 }
OLDNEW
« no previous file with comments | « client/cmd/isolate/exp_archive.go ('k') | client/internal/common/filesystem_view.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698