| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. |
| 4 |
| 5 package subst |
| 6 |
| 7 import ( |
| 8 "testing" |
| 9 |
| 10 . "github.com/luci/luci-go/common/testing/assertions" |
| 11 . "github.com/smartystreets/goconvey/convey" |
| 12 ) |
| 13 |
| 14 func TestResolve(t *testing.T) { |
| 15 t.Parallel() |
| 16 |
| 17 Convey(`Testing substitution resolution`, t, func() { |
| 18 var s Subst |
| 19 |
| 20 shouldResolve := func(v string) string { |
| 21 val, err := s.Resolve(v) |
| 22 So(err, ShouldBeNil) |
| 23 return val |
| 24 } |
| 25 |
| 26 Convey(`Can resolve a string without any substitutions.`, func()
{ |
| 27 So(shouldResolve(""), ShouldEqual, "") |
| 28 So(shouldResolve("foo"), ShouldEqual, "foo") |
| 29 So(shouldResolve(`\${foo}`), ShouldEqual, `\${foo}`) |
| 30 So(shouldResolve(`\${foo`), ShouldEqual, `\${foo`) |
| 31 }) |
| 32 |
| 33 Convey(`Will error if there is an incomplete substitution.`, fun
c() { |
| 34 _, err := s.Resolve("foo-${bar") |
| 35 So(err, ShouldErrLike, "incomplete template") |
| 36 }) |
| 37 |
| 38 Convey(`With substitutions defined, can apply.`, func() { |
| 39 s.SwarmingRunID = "12345" |
| 40 |
| 41 So(shouldResolve(""), ShouldEqual, "") |
| 42 So(shouldResolve("${swarming_run_id}"), ShouldEqual, "12
345") |
| 43 So(shouldResolve("foo/${swarming_run_id}"), ShouldEqual,
"foo/12345") |
| 44 So(shouldResolve("foo/${swarming_run_id}/bar"), ShouldEq
ual, "foo/12345/bar") |
| 45 So(shouldResolve("${swarming_run_id}/bar"), ShouldEqual,
"12345/bar") |
| 46 So(shouldResolve("foo/${swarming_run_id}/bar/${swarming_
run_id}/baz"), ShouldEqual, "foo/12345/bar/12345/baz") |
| 47 So(shouldResolve(`foo/${swarming_run_id}/bar/\${swarming
_run_id}/baz`), ShouldEqual, `foo/12345/bar/\${swarming_run_id}/baz`) |
| 48 }) |
| 49 }) |
| 50 } |
| OLD | NEW |