Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(738)

Unified Diff: logdog/common/types/streamaddr_test.go

Issue 2899993002: [logdog/common/types] custom JSON encoding to allow streamaddr to be zero. (Closed)
Patch Set: use omitempty, duh! Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « logdog/common/types/streamaddr.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: logdog/common/types/streamaddr_test.go
diff --git a/logdog/common/types/streamaddr_test.go b/logdog/common/types/streamaddr_test.go
index 1f8a9b2dec21fa07b06d281397ccd70d8db64cd7..347645562bad2af07ad381d582d092e03286c5c6 100644
--- a/logdog/common/types/streamaddr_test.go
+++ b/logdog/common/types/streamaddr_test.go
@@ -5,6 +5,7 @@
package types
import (
+ "encoding/json"
"flag"
"fmt"
"net/url"
@@ -79,4 +80,36 @@ func TestStreamAddr(t *testing.T) {
"failed to parse URL")
})
})
+
+ Convey(`StreamAddr as a json value`, t, func() {
+ a := &StreamAddr{}
+
+ Convey(`good`, func() {
+ Convey(`zero`, func() {
+ data, err := json.Marshal(a)
+ So(err, ShouldBeNil)
+ So(string(data), ShouldResemble, `{}`)
+ So(json.Unmarshal(data, a), ShouldBeNil)
+ So(a, ShouldResemble, &StreamAddr{})
+ })
+
+ Convey(`full`, func() {
+ a.Host = "host"
+ a.Project = "project"
+ a.Path = "a/+/b"
+ data, err := json.Marshal(a)
+ So(err, ShouldBeNil)
+ So(string(data), ShouldResemble, `{"host":"host","project":"project","path":"a/+/b"}`)
+
+ a2 := &StreamAddr{}
+ So(json.Unmarshal(data, a2), ShouldBeNil)
+ So(a2, ShouldResemble, a)
+ })
+ })
+
+ Convey(`bad`, func() {
+ So(json.Unmarshal([]byte(`{"host":"host","project":"project","path":"fake"}`), a), ShouldErrLike,
+ "must contain at least one character") // from bad Path
+ })
+ })
}
« no previous file with comments | « logdog/common/types/streamaddr.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698