| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. |
| 4 |
| 5 package types |
| 6 |
| 7 import ( |
| 8 "fmt" |
| 9 "net/url" |
| 10 "testing" |
| 11 |
| 12 . "github.com/luci/luci-go/common/testing/assertions" |
| 13 . "github.com/smartystreets/goconvey/convey" |
| 14 ) |
| 15 |
| 16 func TestStreamAddr(t *testing.T) { |
| 17 t.Parallel() |
| 18 |
| 19 var successes = []struct { |
| 20 s string |
| 21 exp StreamAddr |
| 22 }{ |
| 23 {"logdog://host/project/a/+/b", StreamAddr{"host", "project", "a
/+/b"}}, |
| 24 {"logdog://host.example.com/project/foo/bar/+/baz", StreamAddr{"
host.example.com", "project", "foo/bar/+/baz"}}, |
| 25 } |
| 26 |
| 27 var failures = []struct { |
| 28 s string |
| 29 err string |
| 30 }{ |
| 31 {"://project/prefix/+/name", "failed to parse URL"}, |
| 32 {"http://example.com/foo/bar/+/baz", "is not logdog"}, |
| 33 {"logdog://example.com/foo", "URL path does not include both pro
ject and path components"}, |
| 34 {"logdog://example.com/foo@d/bar", "invalid project name"}, |
| 35 {"logdog://example.com/foo/bar", "invalid stream path"}, |
| 36 {"logdog://example.com/foo/bar/+/ba!", "invalid stream path"}, |
| 37 } |
| 38 |
| 39 Convey(`Testing StreamAddr`, t, func() { |
| 40 |
| 41 for _, tc := range successes { |
| 42 Convey(fmt.Sprintf(`Success: %q`, tc.s), func() { |
| 43 addr, err := ParseURL(tc.s) |
| 44 So(err, ShouldBeNil) |
| 45 So(addr, ShouldResemble, &tc.exp) |
| 46 |
| 47 u, err := url.Parse(tc.s) |
| 48 So(err, ShouldBeNil) |
| 49 So(addr.URL(), ShouldResemble, u) |
| 50 }) |
| 51 } |
| 52 |
| 53 for _, tc := range failures { |
| 54 Convey(fmt.Sprintf(`Failure: %q fails like: %q`, tc.s, t
c.err), func() { |
| 55 _, err := ParseURL(tc.s) |
| 56 So(err, ShouldErrLike, tc.err) |
| 57 }) |
| 58 } |
| 59 }) |
| 60 } |
| OLD | NEW |