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

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

Issue 1258673004: cipd: Make it work on Windows. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 5 years, 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 local 5 package local
6 6
7 import ( 7 import (
8 "io/ioutil" 8 "io/ioutil"
9 "os" 9 "os"
10 "path/filepath" 10 "path/filepath"
11 "runtime"
11 "strings" 12 "strings"
12 "testing" 13 "testing"
13 14
14 . "github.com/smartystreets/goconvey/convey" 15 . "github.com/smartystreets/goconvey/convey"
15 ) 16 )
16 17
17 func TestLoadPackageDef(t *testing.T) { 18 func TestLoadPackageDef(t *testing.T) {
18 Convey("LoadPackageDef empty works", t, func() { 19 Convey("LoadPackageDef empty works", t, func() {
19 body := strings.NewReader(`{"package": "package/name"}`) 20 body := strings.NewReader(`{"package": "package/name"}`)
20 def, err := LoadPackageDef(body, nil) 21 def, err := LoadPackageDef(body, nil)
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 mkD := func(path string) { mkDir(tempDir, path) } 218 mkD := func(path string) { mkDir(tempDir, path) }
218 mkL := func(path, target string) { writeSymlink(tempDir, path, t arget) } 219 mkL := func(path, target string) { writeSymlink(tempDir, path, t arget) }
219 220
220 Convey("FindFiles works", func() { 221 Convey("FindFiles works", func() {
221 mkF("ENV/abc.py") 222 mkF("ENV/abc.py")
222 mkF("ENV/abc.pyc") // excluded via "exclude: '.*\.pyc'" 223 mkF("ENV/abc.pyc") // excluded via "exclude: '.*\.pyc'"
223 mkF("ENV/abc.pyo") 224 mkF("ENV/abc.pyo")
224 mkF("ENV/dir/def.py") 225 mkF("ENV/dir/def.py")
225 mkD("ENV/empty") // will be skipped 226 mkD("ENV/empty") // will be skipped
226 mkF("ENV/exclude_me") // excluded via "exclude: 'exclude _me'" 227 mkF("ENV/exclude_me") // excluded via "exclude: 'exclude _me'"
227 » » » mkL("ENV/abs_link", filepath.Dir(tempDir)) 228
228 » » » mkL("ENV/rel_link", "abc.py") 229 » » » // Symlinks do not work on Windows.
229 » » » mkL("ENV/abs_in_root", filepath.Join(tempDir, "ENV", "di r", "def.py")) 230 » » » if runtime.GOOS != "windows" {
231 » » » » mkL("ENV/abs_link", filepath.Dir(tempDir))
232 » » » » mkL("ENV/rel_link", "abc.py")
233 » » » » mkL("ENV/abs_in_root", filepath.Join(tempDir, "E NV", "dir", "def.py"))
234 » » » }
230 235
231 mkF("infra/xyz.py") 236 mkF("infra/xyz.py")
232 mkF("infra/zzz.pyo") 237 mkF("infra/zzz.pyo")
233 mkF("infra/excluded.py") 238 mkF("infra/excluded.py")
234 mkF("infra/excluded_dir/a") 239 mkF("infra/excluded_dir/a")
235 mkF("infra/excluded_dir/b") 240 mkF("infra/excluded_dir/b")
236 241
237 mkF("file1.py") 242 mkF("file1.py")
238 mkF("dir/file2.py") 243 mkF("dir/file2.py")
239 244
(...skipping 24 matching lines...) Expand all
264 } 269 }
265 270
266 files, err := pkgDef.FindFiles(filepath.Join(tempDir, "a ", "b")) 271 files, err := pkgDef.FindFiles(filepath.Join(tempDir, "a ", "b"))
267 So(err, ShouldBeNil) 272 So(err, ShouldBeNil)
268 names := []string{} 273 names := []string{}
269 byName := make(map[string]File, len(files)) 274 byName := make(map[string]File, len(files))
270 for _, f := range files { 275 for _, f := range files {
271 names = append(names, f.Name()) 276 names = append(names, f.Name())
272 byName[f.Name()] = f 277 byName[f.Name()] = f
273 } 278 }
274 So(names, ShouldResemble, []string{
275 "ENV/abc.py",
276 "ENV/abc.pyo",
277 "ENV/abs_in_root",
278 "ENV/abs_link",
279 "ENV/dir/def.py",
280 "ENV/rel_link",
281 "dir/file2.py",
282 "file1.py",
283 "infra/xyz.py",
284 })
285 279
286 » » » // Separately check symlinks. 280 » » » if runtime.GOOS == "windows" {
287 » » » ensureSymlinkTarget(byName["ENV/abs_in_root"], "dir/def. py") 281 » » » » So(names, ShouldResemble, []string{
288 » » » ensureSymlinkTarget(byName["ENV/abs_link"], filepath.ToS lash(filepath.Dir(tempDir))) 282 » » » » » "ENV/abc.py",
289 » » » ensureSymlinkTarget(byName["ENV/rel_link"], "abc.py") 283 » » » » » "ENV/abc.pyo",
284 » » » » » "ENV/dir/def.py",
285 » » » » » "dir/file2.py",
286 » » » » » "file1.py",
287 » » » » » "infra/xyz.py",
288 » » » » })
289 » » » } else {
290 » » » » So(names, ShouldResemble, []string{
291 » » » » » "ENV/abc.py",
292 » » » » » "ENV/abc.pyo",
293 » » » » » "ENV/abs_in_root",
294 » » » » » "ENV/abs_link",
295 » » » » » "ENV/dir/def.py",
296 » » » » » "ENV/rel_link",
297 » » » » » "dir/file2.py",
298 » » » » » "file1.py",
299 » » » » » "infra/xyz.py",
300 » » » » })
301 » » » » // Separately check symlinks.
302 » » » » ensureSymlinkTarget(byName["ENV/abs_in_root"], " dir/def.py")
303 » » » » ensureSymlinkTarget(byName["ENV/abs_link"], file path.ToSlash(filepath.Dir(tempDir)))
304 » » » » ensureSymlinkTarget(byName["ENV/rel_link"], "abc .py")
305 » » » }
290 }) 306 })
291 }) 307 })
292 } 308 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698