| Index: cipd/client/cipd/ensure/good_test.go
|
| diff --git a/cipd/client/cipd/ensure/good_test.go b/cipd/client/cipd/ensure/good_test.go
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..80b8f7e938f00bd5b1ecd49cb9aafdfba0136208
|
| --- /dev/null
|
| +++ b/cipd/client/cipd/ensure/good_test.go
|
| @@ -0,0 +1,145 @@
|
| +// Copyright 2017 The LUCI Authors. All rights reserved.
|
| +// Use of this source code is governed under the Apache License, Version 2.0
|
| +// that can be found in the LICENSE file.
|
| +
|
| +package ensure
|
| +
|
| +import (
|
| + "bytes"
|
| + "errors"
|
| + "strings"
|
| + "testing"
|
| +
|
| + "github.com/luci/luci-go/cipd/client/cipd/common"
|
| + . "github.com/smartystreets/goconvey/convey"
|
| +)
|
| +
|
| +func f(lines ...string) string {
|
| + return strings.Join(lines, "\n")
|
| +}
|
| +
|
| +func p(pkg, ver string) common.Pin {
|
| + return common.Pin{PackageName: pkg, InstanceID: ver}
|
| +}
|
| +
|
| +var goodEnsureFiles = []struct {
|
| + name string
|
| + file string
|
| + expect *ResolvedFile
|
| +}{
|
| + {
|
| + "old_style",
|
| + f(
|
| + "# comment",
|
| + "",
|
| + "path/to/package deadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
|
| + "path/to/other_package some_tag:version",
|
| + "path/to/yet_another a_ref",
|
| + ),
|
| + &ResolvedFile{"", map[string][]common.Pin{
|
| + "": {
|
| + p("path/to/package", "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"),
|
| + p("path/to/other_package", "some_tag:version"),
|
| + p("path/to/yet_another", "a_ref"),
|
| + },
|
| + }},
|
| + },
|
| +
|
| + {
|
| + "templates",
|
| + f(
|
| + "path/to/package/${platform}-${arch} latest",
|
| + ),
|
| + &ResolvedFile{"", map[string][]common.Pin{
|
| + "": {
|
| + p("path/to/package/test_plat-test_arch", "latest"),
|
| + },
|
| + }},
|
| + },
|
| +
|
| + {
|
| + "optional_templates",
|
| + f(
|
| + "path/to/package/${platform}-${arch=neep,test_arch} latest",
|
| + ),
|
| + &ResolvedFile{"", map[string][]common.Pin{
|
| + "": {p("path/to/package/test_plat-test_arch", "latest")},
|
| + }},
|
| + },
|
| +
|
| + {
|
| + "optional_templates_no_match",
|
| + f(
|
| + "path/to/package/${platform=spaz}-${arch=neep,test_arch} latest",
|
| + ),
|
| + &ResolvedFile{"", map[string][]common.Pin{}},
|
| + },
|
| +
|
| + {
|
| + "Root directives",
|
| + f(
|
| + "some/package latest",
|
| + "",
|
| + "@Root a/subdir with spaces",
|
| + "some/package canary",
|
| + "some/other/package tag:value",
|
| + "",
|
| + "@Root", // reset back to empty
|
| + "cool/package beef",
|
| + ),
|
| + &ResolvedFile{"", map[string][]common.Pin{
|
| + "": {
|
| + p("some/package", "latest"),
|
| + p("cool/package", "beef"),
|
| + },
|
| + "a/subdir with spaces": {
|
| + p("some/package", "canary"),
|
| + p("some/other/package", "tag:value"),
|
| + },
|
| + }},
|
| + },
|
| +
|
| + {
|
| + "ServiceURL setting",
|
| + f(
|
| + "$ServiceURL https://cipd.example.com/path/to/thing",
|
| + "",
|
| + "some/package version",
|
| + ),
|
| + &ResolvedFile{"https://cipd.example.com/path/to/thing", map[string][]common.Pin{
|
| + "": {
|
| + p("some/package", "version"),
|
| + },
|
| + }},
|
| + },
|
| +
|
| + {
|
| + "empty",
|
| + "",
|
| + &ResolvedFile{},
|
| + },
|
| +}
|
| +
|
| +func testResolver(pkg, vers string) (common.Pin, error) {
|
| + if strings.Contains(vers, "error") {
|
| + return p("", ""), errors.New("testResolver returned error")
|
| + }
|
| + return p(pkg, vers), nil
|
| +}
|
| +
|
| +func TestGoodEnsureFiles(t *testing.T) {
|
| + t.Parallel()
|
| +
|
| + Convey("good ensure files", t, func() {
|
| + for _, tc := range goodEnsureFiles {
|
| + Convey(tc.name, func() {
|
| + buf := bytes.NewBufferString(tc.file)
|
| + f, err := ParseFile(buf)
|
| + So(err, ShouldBeNil)
|
| + rf, err := f.ResolveWith("test_arch", "test_plat", testResolver)
|
| + So(err, ShouldBeNil)
|
| + So(rf, ShouldResemble, tc.expect)
|
| + })
|
| + }
|
| + })
|
| +}
|
|
|