| OLD | NEW |
| 1 // Copyright 2014 The LUCI Authors. All rights reserved. | 1 // Copyright 2014 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package common | 5 package common |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "strings" | 9 "strings" |
| 10 "testing" | 10 "testing" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 func TestGetInstanceTagKey(t *testing.T) { | 151 func TestGetInstanceTagKey(t *testing.T) { |
| 152 t.Parallel() | 152 t.Parallel() |
| 153 | 153 |
| 154 Convey("GetInstanceTagKey works", t, func() { | 154 Convey("GetInstanceTagKey works", t, func() { |
| 155 So(GetInstanceTagKey("a:b"), ShouldEqual, "a") | 155 So(GetInstanceTagKey("a:b"), ShouldEqual, "a") |
| 156 So(GetInstanceTagKey("a:b:c"), ShouldEqual, "a") | 156 So(GetInstanceTagKey("a:b:c"), ShouldEqual, "a") |
| 157 So(GetInstanceTagKey(":b"), ShouldEqual, "") | 157 So(GetInstanceTagKey(":b"), ShouldEqual, "") |
| 158 So(GetInstanceTagKey(""), ShouldEqual, "") | 158 So(GetInstanceTagKey(""), ShouldEqual, "") |
| 159 }) | 159 }) |
| 160 } | 160 } |
| 161 |
| 162 func TestPinSliceAndMap(t *testing.T) { |
| 163 t.Parallel() |
| 164 |
| 165 Convey("PinSlice", t, func() { |
| 166 ps := PinSlice{{"pkg2", "vers"}, {"pkg", "vers"}} |
| 167 |
| 168 Convey("can convert to a map", func() { |
| 169 pm := ps.ToMap() |
| 170 So(pm, ShouldResemble, PinMap{ |
| 171 "pkg": "vers", |
| 172 "pkg2": "vers", |
| 173 }) |
| 174 |
| 175 pm["new/pkg"] = "some:tag" |
| 176 |
| 177 Convey("and back to a slice", func() { |
| 178 So(pm.ToSlice(), ShouldResemble, PinSlice{ |
| 179 {"new/pkg", "some:tag"}, |
| 180 {"pkg", "vers"}, |
| 181 {"pkg2", "vers"}, |
| 182 }) |
| 183 }) |
| 184 }) |
| 185 }) |
| 186 |
| 187 Convey("PinSliceByRoot", t, func() { |
| 188 id := func(letter rune) string { |
| 189 return strings.Repeat(string(letter), 40) |
| 190 } |
| 191 |
| 192 pmr := PinSliceByRoot{ |
| 193 "": PinSlice{ |
| 194 {"pkg2", id('1')}, |
| 195 {"pkg", id('0')}, |
| 196 }, |
| 197 "other": PinSlice{ |
| 198 {"something", id('2')}, |
| 199 }, |
| 200 } |
| 201 |
| 202 Convey("Can validate", func() { |
| 203 So(pmr.Validate(), ShouldErrLike, nil) |
| 204 |
| 205 Convey("can see bad roots", func() { |
| 206 pmr["/"] = PinSlice{{"something", "version"}} |
| 207 So(pmr.Validate(), ShouldErrLike, "bad root path
") |
| 208 }) |
| 209 |
| 210 Convey("can see duplicate packages", func() { |
| 211 pmr[""] = append(pmr[""], Pin{"pkg", strings.Rep
eat("2", 40)}) |
| 212 So(pmr.Validate(), ShouldErrLike, `root "": dupl
icate package "pkg"`) |
| 213 }) |
| 214 |
| 215 Convey("can see bad pins", func() { |
| 216 pmr[""] = append(pmr[""], Pin{"quxxly", "nurbs"}
) |
| 217 So(pmr.Validate(), ShouldErrLike, `root "": not
a valid package instance ID`) |
| 218 }) |
| 219 }) |
| 220 |
| 221 Convey("can convert to ByMap", func() { |
| 222 pmm := pmr.ToMap() |
| 223 So(pmm, ShouldResemble, PinMapByRoot{ |
| 224 "": PinMap{ |
| 225 "pkg": id('0'), |
| 226 "pkg2": id('1'), |
| 227 }, |
| 228 "other": PinMap{ |
| 229 "something": id('2'), |
| 230 }, |
| 231 }) |
| 232 |
| 233 Convey("and back", func() { |
| 234 So(pmm.ToSlice(), ShouldResemble, PinSliceByRoot
{ |
| 235 "": PinSlice{ |
| 236 {"pkg", id('0')}, |
| 237 {"pkg2", id('1')}, |
| 238 }, |
| 239 "other": PinSlice{ |
| 240 {"something", id('2')}, |
| 241 }, |
| 242 }) |
| 243 }) |
| 244 }) |
| 245 |
| 246 }) |
| 247 } |
| OLD | NEW |