| 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 "encoding/json" |
| 8 "flag" | 9 "flag" |
| 9 "fmt" | 10 "fmt" |
| 10 "net/url" | 11 "net/url" |
| 11 "testing" | 12 "testing" |
| 12 | 13 |
| 13 . "github.com/luci/luci-go/common/testing/assertions" | 14 . "github.com/luci/luci-go/common/testing/assertions" |
| 14 . "github.com/smartystreets/goconvey/convey" | 15 . "github.com/smartystreets/goconvey/convey" |
| 15 ) | 16 ) |
| 16 | 17 |
| 17 func TestStreamAddr(t *testing.T) { | 18 func TestStreamAddr(t *testing.T) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 "project", | 73 "project", |
| 73 "a/+/b", | 74 "a/+/b", |
| 74 }) | 75 }) |
| 75 }) | 76 }) |
| 76 | 77 |
| 77 Convey(`bad`, func() { | 78 Convey(`bad`, func() { |
| 78 So(fs.Parse([]string{"-addr", "://host/project/a/+/b"}),
ShouldErrLike, | 79 So(fs.Parse([]string{"-addr", "://host/project/a/+/b"}),
ShouldErrLike, |
| 79 "failed to parse URL") | 80 "failed to parse URL") |
| 80 }) | 81 }) |
| 81 }) | 82 }) |
| 83 |
| 84 Convey(`StreamAddr as a json value`, t, func() { |
| 85 a := &StreamAddr{} |
| 86 |
| 87 Convey(`good`, func() { |
| 88 Convey(`zero`, func() { |
| 89 data, err := json.Marshal(a) |
| 90 So(err, ShouldBeNil) |
| 91 So(string(data), ShouldResemble, `{}`) |
| 92 So(json.Unmarshal(data, a), ShouldBeNil) |
| 93 So(a, ShouldResemble, &StreamAddr{}) |
| 94 }) |
| 95 |
| 96 Convey(`full`, func() { |
| 97 a.Host = "host" |
| 98 a.Project = "project" |
| 99 a.Path = "a/+/b" |
| 100 data, err := json.Marshal(a) |
| 101 So(err, ShouldBeNil) |
| 102 So(string(data), ShouldResemble, `{"host":"host"
,"project":"project","path":"a/+/b"}`) |
| 103 |
| 104 a2 := &StreamAddr{} |
| 105 So(json.Unmarshal(data, a2), ShouldBeNil) |
| 106 So(a2, ShouldResemble, a) |
| 107 }) |
| 108 }) |
| 109 |
| 110 Convey(`bad`, func() { |
| 111 So(json.Unmarshal([]byte(`{"host":"host","project":"proj
ect","path":"fake"}`), a), ShouldErrLike, |
| 112 "must contain at least one character") // from b
ad Path |
| 113 }) |
| 114 }) |
| 82 } | 115 } |
| OLD | NEW |