| OLD | NEW | 
|---|
| 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 main | 5 package main | 
| 6 | 6 | 
| 7 import ( | 7 import ( | 
| 8         "path/filepath" | 8         "path/filepath" | 
| 9         "strings" | 9         "strings" | 
| 10         "testing" | 10         "testing" | 
| 11 | 11 | 
| 12 »       "github.com/luci/luci-go/client/internal/common" | 12 »       "github.com/luci/luci-go/client/isolate" | 
| 13         "github.com/luci/luci-go/common/flag/stringmapflag" | 13         "github.com/luci/luci-go/common/flag/stringmapflag" | 
| 14 | 14 | 
| 15         . "github.com/smartystreets/goconvey/convey" | 15         . "github.com/smartystreets/goconvey/convey" | 
| 16 ) | 16 ) | 
| 17 | 17 | 
| 18 func TestConvertPyToGoArchiveCMDArgs(t *testing.T) { | 18 func TestConvertPyToGoArchiveCMDArgs(t *testing.T) { | 
| 19         t.Parallel() | 19         t.Parallel() | 
| 20         Convey(`Archive command line arguments should be converted properly for 
     Go.`, t, func() { | 20         Convey(`Archive command line arguments should be converted properly for 
     Go.`, t, func() { | 
| 21                 data := []struct { | 21                 data := []struct { | 
| 22                         input    []string | 22                         input    []string | 
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 84                         "--extra-variable", "version_full=42.0.2284.0", | 84                         "--extra-variable", "version_full=42.0.2284.0", | 
| 85                         "--config-variable", "OS=linux", | 85                         "--config-variable", "OS=linux", | 
| 86                 } | 86                 } | 
| 87                 root := absToOS("e:", "/tmp/bar") | 87                 root := absToOS("e:", "/tmp/bar") | 
| 88                 opts, err := parseArchiveCMD(args, root) | 88                 opts, err := parseArchiveCMD(args, root) | 
| 89                 base := filepath.Dir(root) | 89                 base := filepath.Dir(root) | 
| 90                 So(opts.Isolate, ShouldResemble, filepath.Join(base, "boz", "bar
     .isolate")) | 90                 So(opts.Isolate, ShouldResemble, filepath.Join(base, "boz", "bar
     .isolate")) | 
| 91                 So(opts.Isolated, ShouldResemble, filepath.Join(base, "biz", "ba
     r.isolated")) | 91                 So(opts.Isolated, ShouldResemble, filepath.Join(base, "biz", "ba
     r.isolated")) | 
| 92                 So(err, ShouldBeNil) | 92                 So(err, ShouldBeNil) | 
| 93                 So(stringmapflag.Value{"OS": "linux"}, ShouldResemble, opts.Conf
     igVariables) | 93                 So(stringmapflag.Value{"OS": "linux"}, ShouldResemble, opts.Conf
     igVariables) | 
| 94 »       »       if common.IsWindows() { | 94 »       »       if isolate.IsWindows() { | 
| 95                         So(stringmapflag.Value{"PRODUCT_DIR": "../../out/Release
     ", "EXECUTABLE_SUFFIX": ".exe", "DEPTH": "../.."}, ShouldResemble, opts.PathVari
     ables) | 95                         So(stringmapflag.Value{"PRODUCT_DIR": "../../out/Release
     ", "EXECUTABLE_SUFFIX": ".exe", "DEPTH": "../.."}, ShouldResemble, opts.PathVari
     ables) | 
| 96                 } else { | 96                 } else { | 
| 97                         So(stringmapflag.Value{"PRODUCT_DIR": "../../out/Release
     ", "EXECUTABLE_SUFFIX": "", "DEPTH": "../.."}, ShouldResemble, opts.PathVariable
     s) | 97                         So(stringmapflag.Value{"PRODUCT_DIR": "../../out/Release
     ", "EXECUTABLE_SUFFIX": "", "DEPTH": "../.."}, ShouldResemble, opts.PathVariable
     s) | 
| 98                 } | 98                 } | 
| 99                 So(stringmapflag.Value{"version_full": "42.0.2284.0"}, ShouldRes
     emble, opts.ExtraVariables) | 99                 So(stringmapflag.Value{"version_full": "42.0.2284.0"}, ShouldRes
     emble, opts.ExtraVariables) | 
| 100         }) | 100         }) | 
| 101 } | 101 } | 
| 102 | 102 | 
| 103 // Verify that if the isolate/isolated paths are absolute, we don't | 103 // Verify that if the isolate/isolated paths are absolute, we don't | 
| 104 // accidentally interpret them as relative to the cwd. | 104 // accidentally interpret them as relative to the cwd. | 
| 105 func TestArchiveAbsolutePaths(t *testing.T) { | 105 func TestArchiveAbsolutePaths(t *testing.T) { | 
| 106         t.Parallel() | 106         t.Parallel() | 
| 107         Convey(`Archive command line should correctly handle absolute paths.`, t
     , func() { | 107         Convey(`Archive command line should correctly handle absolute paths.`, t
     , func() { | 
| 108                 root := absToOS("e:", "/tmp/bar/") | 108                 root := absToOS("e:", "/tmp/bar/") | 
| 109                 args := []string{ | 109                 args := []string{ | 
| 110                         "--isolated", root + "foo.isolated", | 110                         "--isolated", root + "foo.isolated", | 
| 111                         "--isolate", root + "foo.isolate", | 111                         "--isolate", root + "foo.isolate", | 
| 112                 } | 112                 } | 
| 113                 opts, err := parseArchiveCMD(args, absToOS("x:", "/var/lib")) | 113                 opts, err := parseArchiveCMD(args, absToOS("x:", "/var/lib")) | 
| 114                 So(err, ShouldBeNil) | 114                 So(err, ShouldBeNil) | 
| 115                 So(opts.Isolate, ShouldResemble, root+"foo.isolate") | 115                 So(opts.Isolate, ShouldResemble, root+"foo.isolate") | 
| 116                 So(opts.Isolated, ShouldResemble, root+"foo.isolated") | 116                 So(opts.Isolated, ShouldResemble, root+"foo.isolated") | 
| 117         }) | 117         }) | 
| 118 } | 118 } | 
| 119 | 119 | 
| 120 // Private stuff. | 120 // Private stuff. | 
| 121 | 121 | 
| 122 // absToOS converts a POSIX path to OS specific format. | 122 // absToOS converts a POSIX path to OS specific format. | 
| 123 func absToOS(drive, p string) string { | 123 func absToOS(drive, p string) string { | 
| 124 »       if common.IsWindows() { | 124 »       if isolate.IsWindows() { | 
| 125                 return drive + strings.Replace(p, "/", "\\", -1) | 125                 return drive + strings.Replace(p, "/", "\\", -1) | 
| 126         } | 126         } | 
| 127         return p | 127         return p | 
| 128 } | 128 } | 
| OLD | NEW | 
|---|