| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 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 types | 5 package types |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "flag" | 8 "flag" |
| 9 "fmt" | 9 "fmt" |
| 10 "strings" | 10 "strings" |
| 11 "testing" | 11 "testing" |
| 12 | 12 |
| 13 . "github.com/smartystreets/goconvey/convey" | 13 . "github.com/smartystreets/goconvey/convey" |
| 14 ) | 14 ) |
| 15 | 15 |
| 16 func TestStreamNameAsFlag(t *testing.T) { | 16 func TestStreamNameAsFlag(t *testing.T) { |
| 17 t.Parallel() |
| 18 |
| 17 Convey(`Given an FlagSet configured with a StreamName flag`, t, func() { | 19 Convey(`Given an FlagSet configured with a StreamName flag`, t, func() { |
| 18 var stream StreamName | 20 var stream StreamName |
| 19 fs := flag.NewFlagSet("test", flag.ContinueOnError) | 21 fs := flag.NewFlagSet("test", flag.ContinueOnError) |
| 20 fs.Var(&stream, "stream", "The stream name.") | 22 fs.Var(&stream, "stream", "The stream name.") |
| 21 | 23 |
| 22 Convey(`When the stream flag is set to "test"`, func() { | 24 Convey(`When the stream flag is set to "test"`, func() { |
| 23 err := fs.Parse([]string{"-stream", "test"}) | 25 err := fs.Parse([]string{"-stream", "test"}) |
| 24 So(err, ShouldBeNil) | 26 So(err, ShouldBeNil) |
| 25 | 27 |
| 26 Convey(`The stream variable should be populated with "te
st".`, func() { | 28 Convey(`The stream variable should be populated with "te
st".`, func() { |
| 27 So(stream, ShouldEqual, "test") | 29 So(stream, ShouldEqual, "test") |
| 28 }) | 30 }) |
| 29 }) | 31 }) |
| 30 | 32 |
| 31 Convey(`An invalid stream name should fail to parse.`, func() { | 33 Convey(`An invalid stream name should fail to parse.`, func() { |
| 32 err := fs.Parse([]string{"-stream", "_beginsWithUndersco
re"}) | 34 err := fs.Parse([]string{"-stream", "_beginsWithUndersco
re"}) |
| 33 So(err, ShouldNotBeNil) | 35 So(err, ShouldNotBeNil) |
| 34 }) | 36 }) |
| 35 }) | 37 }) |
| 36 } | 38 } |
| 37 | 39 |
| 38 func TestStreamName(t *testing.T) { | 40 func TestStreamName(t *testing.T) { |
| 41 t.Parallel() |
| 42 |
| 39 Convey(`MakeStreamName`, t, func() { | 43 Convey(`MakeStreamName`, t, func() { |
| 40 type e struct { | 44 type e struct { |
| 41 t []string // Test value. | 45 t []string // Test value. |
| 42 e string // Expected value. | 46 e string // Expected value. |
| 43 } | 47 } |
| 44 for _, entry := range []e{ | 48 for _, entry := range []e{ |
| 45 {[]string{""}, "FILL"}, | 49 {[]string{""}, "FILL"}, |
| 46 {[]string{"", ""}, "FILL/FILL"}, | 50 {[]string{"", ""}, "FILL/FILL"}, |
| 47 {[]string{"", "foo", "ba!r", "¿baz"}, "FILL/foo/ba_r/FIL
L_baz"}, | 51 {[]string{"", "foo", "ba!r", "¿baz"}, "FILL/foo/ba_r/FIL
L_baz"}, |
| 48 {[]string{"foo", "bar baz"}, "foo/bar_baz"}, | 52 {[]string{"foo", "bar baz"}, "foo/bar_baz"}, |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 Convey(fmt.Sprintf(`Stream Name "%s" has %d segments: %v
`, entry.s, entry.n, entry.p), func() { | 158 Convey(fmt.Sprintf(`Stream Name "%s" has %d segments: %v
`, entry.s, entry.n, entry.p), func() { |
| 155 So(entry.s.Segments(), ShouldResemble, entry.p) | 159 So(entry.s.Segments(), ShouldResemble, entry.p) |
| 156 So(len(entry.s.Segments()), ShouldEqual, entry.s
.SegmentCount()) | 160 So(len(entry.s.Segments()), ShouldEqual, entry.s
.SegmentCount()) |
| 157 So(len(entry.s.Segments()), ShouldEqual, entry.n
) | 161 So(len(entry.s.Segments()), ShouldEqual, entry.n
) |
| 158 }) | 162 }) |
| 159 } | 163 } |
| 160 }) | 164 }) |
| 161 } | 165 } |
| 162 | 166 |
| 163 func TestStreamPath(t *testing.T) { | 167 func TestStreamPath(t *testing.T) { |
| 168 t.Parallel() |
| 169 |
| 164 Convey(`StreamPath.Split, StreamPath.Validate`, t, func() { | 170 Convey(`StreamPath.Split, StreamPath.Validate`, t, func() { |
| 165 type e struct { | 171 type e struct { |
| 166 p string // The stream path. | 172 p string // The stream path. |
| 167 prefix string // The split prefix. | 173 prefix string // The split prefix. |
| 168 name string // The split name. | 174 name string // The split name. |
| 169 sep bool | 175 sep bool |
| 170 valid bool | 176 valid bool |
| 171 } | 177 } |
| 172 for _, entry := range []e{ | 178 for _, entry := range []e{ |
| 173 {"", "", "", false, false}, | 179 {"", "", "", false, false}, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 | 228 |
| 223 if p == "" { | 229 if p == "" { |
| 224 break | 230 break |
| 225 } | 231 } |
| 226 } | 232 } |
| 227 So(parts, ShouldResemble, tc.c) | 233 So(parts, ShouldResemble, tc.c) |
| 228 }) | 234 }) |
| 229 } | 235 } |
| 230 }) | 236 }) |
| 231 } | 237 } |
| OLD | NEW |