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

Unified Diff: buildbucket/swarmbucket/subst/subst_test.go

Issue 2701033003: milo: Add SwarmBucket templating. (Closed)
Patch Set: Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
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`)
+ })
+ })
+}

Powered by Google App Engine
This is Rietveld 408576698