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

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

Issue 2655903002: [cipd/common] Add various pinslice types. (Closed)
Patch Set: rebase 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') | no next file » | 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 f099bf6695b59fcd351a79cb0c23ca2068cec47f..d26f300196f56ae0aa80e62a6121d27ba572ec1c 100644
--- a/cipd/client/cipd/common/common_test.go
+++ b/cipd/client/cipd/common/common_test.go
@@ -158,3 +158,90 @@ func TestGetInstanceTagKey(t *testing.T) {
So(GetInstanceTagKey(""), ShouldEqual, "")
})
}
+
+func TestPinSliceAndMap(t *testing.T) {
+ t.Parallel()
+
+ Convey("PinSlice", t, func() {
+ ps := PinSlice{{"pkg2", "vers"}, {"pkg", "vers"}}
+
+ Convey("can convert to a map", func() {
+ pm := ps.ToMap()
+ So(pm, ShouldResemble, PinMap{
+ "pkg": "vers",
+ "pkg2": "vers",
+ })
+
+ pm["new/pkg"] = "some:tag"
+
+ Convey("and back to a slice", func() {
+ So(pm.ToSlice(), ShouldResemble, PinSlice{
+ {"new/pkg", "some:tag"},
+ {"pkg", "vers"},
+ {"pkg2", "vers"},
+ })
+ })
+ })
+ })
+
+ Convey("PinSliceByRoot", t, func() {
+ id := func(letter rune) string {
+ return strings.Repeat(string(letter), 40)
+ }
+
+ pmr := PinSliceByRoot{
+ "": PinSlice{
+ {"pkg2", id('1')},
+ {"pkg", id('0')},
+ },
+ "other": PinSlice{
+ {"something", id('2')},
+ },
+ }
+
+ Convey("Can validate", func() {
+ So(pmr.Validate(), ShouldErrLike, nil)
+
+ Convey("can see bad roots", func() {
+ pmr["/"] = PinSlice{{"something", "version"}}
+ So(pmr.Validate(), ShouldErrLike, "bad root path")
+ })
+
+ Convey("can see duplicate packages", func() {
+ pmr[""] = append(pmr[""], Pin{"pkg", strings.Repeat("2", 40)})
+ So(pmr.Validate(), ShouldErrLike, `root "": duplicate package "pkg"`)
+ })
+
+ Convey("can see bad pins", func() {
+ pmr[""] = append(pmr[""], Pin{"quxxly", "nurbs"})
+ So(pmr.Validate(), ShouldErrLike, `root "": not a valid package instance ID`)
+ })
+ })
+
+ Convey("can convert to ByMap", func() {
+ pmm := pmr.ToMap()
+ So(pmm, ShouldResemble, PinMapByRoot{
+ "": PinMap{
+ "pkg": id('0'),
+ "pkg2": id('1'),
+ },
+ "other": PinMap{
+ "something": id('2'),
+ },
+ })
+
+ Convey("and back", func() {
+ So(pmm.ToSlice(), ShouldResemble, PinSliceByRoot{
+ "": PinSlice{
+ {"pkg", id('0')},
+ {"pkg2", id('1')},
+ },
+ "other": PinSlice{
+ {"something", id('2')},
+ },
+ })
+ })
+ })
+
+ })
+}
« no previous file with comments | « cipd/client/cipd/common/common.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698