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

Unified Diff: cipd/client/cipd/common/common_test.go

Issue 2651173003: [cipd] Move ValidateRoot to common package (Closed)
Patch Set: Add test Created 3 years, 11 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
« no previous file with comments | « cipd/client/cipd/common/common.go ('k') | cipd/client/cipd/ensure/file.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cipd/client/cipd/common/common_test.go
diff --git a/cipd/client/cipd/common/common_test.go b/cipd/client/cipd/common/common_test.go
index 174c4332e597c3d81a9f4fcab1f16fe642adc36f..59069209a78c66350850cf4a17af57a154e197a3 100644
--- a/cipd/client/cipd/common/common_test.go
+++ b/cipd/client/cipd/common/common_test.go
@@ -9,6 +9,7 @@ import (
"strings"
"testing"
+ . "github.com/luci/luci-go/common/testing/assertions"
. "github.com/smartystreets/goconvey/convey"
)
@@ -80,6 +81,50 @@ func TestValidateInstanceVersion(t *testing.T) {
})
}
+func TestValidateRoot(t *testing.T) {
+ badRoots := []struct {
+ name string
+ root string
+ err string
+ }{
+ {"windows", "folder\\thing", "backslashes not allowed"},
+ {"windows drive", "c:/foo/bar", `colons are not allowed`},
+ {"messy", "some/../thing", `"some/../thing" (should be "thing")`},
+ {"relative", "../something", `invalid "."`},
+ {"single relative", "./something", `"./something" (should be "something")`},
+ {"absolute", "/etc", `absolute paths not allowed`},
+ {"extra slashes", "//foo/bar", `bad root path`},
+ }
+
+ goodRoots := []struct {
+ name string
+ root string
+ }{
+ {"empty", ""},
+ {"simple path", "some/path"},
+ {"single path", "something"},
+ {"spaces", "some path/with/ spaces"},
+ }
+
+ Convey("ValidtateRoot", t, func() {
+ Convey("rejects bad roots", func() {
+ for _, tc := range badRoots {
+ Convey(tc.name, func() {
+ So(ValidateRoot(tc.root), ShouldErrLike, tc.err)
+ })
+ }
+ })
+
+ Convey("accepts good roots", func() {
+ for _, tc := range goodRoots {
+ Convey(tc.name, func() {
+ So(ValidateRoot(tc.root), ShouldErrLike, nil)
+ })
+ }
+ })
+ })
+}
+
func TestPinToString(t *testing.T) {
Convey("Pin.String works", t, func() {
So(
« no previous file with comments | « cipd/client/cipd/common/common.go ('k') | cipd/client/cipd/ensure/file.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698