| OLD | NEW |
| (Empty) |
| 1 // Copyright 2016 The LUCI Authors. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 | |
| 15 package hierarchy | |
| 16 | |
| 17 import ( | |
| 18 "fmt" | |
| 19 "testing" | |
| 20 | |
| 21 "github.com/luci/luci-go/logdog/common/types" | |
| 22 . "github.com/smartystreets/goconvey/convey" | |
| 23 ) | |
| 24 | |
| 25 func TestComponents(t *testing.T) { | |
| 26 t.Parallel() | |
| 27 | |
| 28 tests := []struct { | |
| 29 path types.StreamPath | |
| 30 full bool | |
| 31 comp []*Component | |
| 32 }{ | |
| 33 {path: "", full: false, comp: nil}, | |
| 34 {path: "foo/bar/+/baz", full: true, comp: []*Component{ | |
| 35 {"foo/bar/+", "baz", true}, | |
| 36 {"foo/bar", "+", false}, | |
| 37 {"foo", "bar", false}, | |
| 38 {"", "foo", false}, | |
| 39 }}, | |
| 40 {path: "foo/bar/+", full: false, comp: []*Component{ | |
| 41 {"foo/bar", "+", false}, | |
| 42 {"foo", "bar", false}, | |
| 43 {"", "foo", false}, | |
| 44 }}, | |
| 45 } | |
| 46 | |
| 47 Convey(`Testing MakeComponents`, t, func() { | |
| 48 for _, tc := range tests { | |
| 49 Convey(fmt.Sprintf(`Path %q yields %d component(s)`, tc.
path, len(tc.comp)), func() { | |
| 50 So(Components(tc.path, tc.full), ShouldResemble,
tc.comp) | |
| 51 }) | |
| 52 } | |
| 53 }) | |
| 54 } | |
| 55 | |
| 56 func TestComponentID(t *testing.T) { | |
| 57 t.Parallel() | |
| 58 | |
| 59 encodingTestCases := []struct { | |
| 60 cid componentID | |
| 61 encoded string | |
| 62 }{ | |
| 63 {componentID{"foo", "0", false}, "y~8000~foo"}, | |
| 64 {componentID{"foo", "0", true}, "n~8000~foo"}, | |
| 65 {componentID{"foo", "00", true}, "n~8000:8080~foo"}, | |
| 66 {componentID{"foo", "003", true}, "n~81c0:8180~foo"}, | |
| 67 {componentID{"foo", "bar", true}, "s~bar~foo"}, | |
| 68 } | |
| 69 Convey(`Component ID Encoding`, t, func() { | |
| 70 for _, tc := range encodingTestCases { | |
| 71 Convey(fmt.Sprintf(`%+v encodes to %q`, tc.cid, tc.encod
ed), func() { | |
| 72 So(tc.cid.key(), ShouldResemble, tc.encoded) | |
| 73 | |
| 74 var cid componentID | |
| 75 cid.setID(tc.encoded) | |
| 76 So(cid, ShouldResemble, tc.cid) | |
| 77 }) | |
| 78 } | |
| 79 }) | |
| 80 | |
| 81 decodingTestCases := []struct { | |
| 82 encoded string | |
| 83 cid componentID | |
| 84 }{ | |
| 85 {"y~8000:8000~foo", componentID{"foo", "0", false}}, | |
| 86 {"y~8000~foo", componentID{"foo", "0", false}}, | |
| 87 {"n~8000:8080~foo", componentID{"foo", "00", true}}, | |
| 88 } | |
| 89 Convey(`Component ID Decoding`, t, func() { | |
| 90 for _, tc := range decodingTestCases { | |
| 91 Convey(fmt.Sprintf(`%q decodes to %+v`, tc.encoded, tc.c
id), func() { | |
| 92 var cid componentID | |
| 93 cid.setID(tc.encoded) | |
| 94 So(cid, ShouldResemble, tc.cid) | |
| 95 }) | |
| 96 } | |
| 97 }) | |
| 98 } | |
| OLD | NEW |