| Index: buildbucket/swarmbucket/subst/subst_test.go
|
| diff --git a/buildbucket/swarmbucket/subst/subst_test.go b/buildbucket/swarmbucket/subst/subst_test.go
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..5c3eeb3d7ae6125cd650b428b831d0f22b4674da
|
| --- /dev/null
|
| +++ b/buildbucket/swarmbucket/subst/subst_test.go
|
| @@ -0,0 +1,50 @@
|
| +// 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 subst
|
| +
|
| +import (
|
| + "testing"
|
| +
|
| + . "github.com/luci/luci-go/common/testing/assertions"
|
| + . "github.com/smartystreets/goconvey/convey"
|
| +)
|
| +
|
| +func TestResolve(t *testing.T) {
|
| + t.Parallel()
|
| +
|
| + Convey(`Testing substitution resolution`, t, func() {
|
| + var s Subst
|
| +
|
| + shouldResolve := func(v string) string {
|
| + val, err := s.Resolve(v)
|
| + So(err, ShouldBeNil)
|
| + return val
|
| + }
|
| +
|
| + Convey(`Can resolve a string without any substitutions.`, func() {
|
| + So(shouldResolve(""), ShouldEqual, "")
|
| + So(shouldResolve("foo"), ShouldEqual, "foo")
|
| + So(shouldResolve(`\${foo}`), ShouldEqual, `\${foo}`)
|
| + So(shouldResolve(`\${foo`), ShouldEqual, `\${foo`)
|
| + })
|
| +
|
| + Convey(`Will error if there is an incomplete substitution.`, func() {
|
| + _, err := s.Resolve("foo-${bar")
|
| + So(err, ShouldErrLike, "incomplete template")
|
| + })
|
| +
|
| + Convey(`With substitutions defined, can apply.`, func() {
|
| + s.SwarmingRunID = "12345"
|
| +
|
| + So(shouldResolve(""), ShouldEqual, "")
|
| + So(shouldResolve("${swarming_run_id}"), ShouldEqual, "12345")
|
| + So(shouldResolve("foo/${swarming_run_id}"), ShouldEqual, "foo/12345")
|
| + So(shouldResolve("foo/${swarming_run_id}/bar"), ShouldEqual, "foo/12345/bar")
|
| + So(shouldResolve("${swarming_run_id}/bar"), ShouldEqual, "12345/bar")
|
| + So(shouldResolve("foo/${swarming_run_id}/bar/${swarming_run_id}/baz"), ShouldEqual, "foo/12345/bar/12345/baz")
|
| + So(shouldResolve(`foo/${swarming_run_id}/bar/\${swarming_run_id}/baz`), ShouldEqual, `foo/12345/bar/\${swarming_run_id}/baz`)
|
| + })
|
| + })
|
| +}
|
|
|