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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « logdog/common/types/streamaddr.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
OLDNEW
« 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