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

Side by Side Diff: logdog/client/butlerlib/streamproto/properties_test.go

Issue 2456953003: LogDog: Update client/bootstrap to generate URLs. (Closed)
Patch Set: Winders Created 4 years, 1 month 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
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 streamproto 5 package streamproto
6 6
7 import ( 7 import (
8 "encoding/json" 8 "encoding/json"
9 "testing" 9 "testing"
10 "time" 10 "time"
11 11
12 "github.com/luci/luci-go/common/clock" 12 "github.com/luci/luci-go/common/clock"
13 "github.com/luci/luci-go/common/clock/testclock" 13 "github.com/luci/luci-go/common/clock/testclock"
14 "github.com/luci/luci-go/common/proto/google" 14 "github.com/luci/luci-go/common/proto/google"
15 "github.com/luci/luci-go/logdog/api/logpb" 15 "github.com/luci/luci-go/logdog/api/logpb"
16 "github.com/luci/luci-go/logdog/common/types" 16 "github.com/luci/luci-go/logdog/common/types"
17 "golang.org/x/net/context" 17 "golang.org/x/net/context"
18 18
19 . "github.com/smartystreets/goconvey/convey" 19 . "github.com/smartystreets/goconvey/convey"
20 ) 20 )
21 21
22 // Test the TeeType struct. 22 // Test the TeeType struct.
23 func TestProperties(t *testing.T) { 23 func TestProperties(t *testing.T) {
24 Convey(`A testing instance`, t, func() { 24 Convey(`A testing instance`, t, func() {
25 ctx, _ := testclock.UseTime(context.Background(), time.Date(2015 , 1, 1, 0, 0, 0, 0, time.UTC)) 25 ctx, _ := testclock.UseTime(context.Background(), time.Date(2015 , 1, 1, 0, 0, 0, 0, time.UTC))
26 Convey(`A Properties instance with no ContentType`, func() { 26 Convey(`A Properties instance with no ContentType`, func() {
27 » » » p := Properties{} 27 » » » p := Properties{
28 » » » » LogStreamDescriptor: &logpb.LogStreamDescriptor{ },
29 » » » }
28 30
29 Convey(`Returns the configured ContentType if one is set .`, func() { 31 Convey(`Returns the configured ContentType if one is set .`, func() {
30 p.ContentType = "foo/bar" 32 p.ContentType = "foo/bar"
31 p.StreamType = logpb.StreamType_TEXT 33 p.StreamType = logpb.StreamType_TEXT
32 So(p.ContentType, ShouldEqual, "foo/bar") 34 So(p.ContentType, ShouldEqual, "foo/bar")
33 }) 35 })
34 36
35 Convey(`Will fail to validate if a Prefix is set.`, func () { 37 Convey(`Will fail to validate if a Prefix is set.`, func () {
36 p.Prefix = "some/prefix" 38 p.Prefix = "some/prefix"
37 So(p.Validate(), ShouldNotBeNil) 39 So(p.Validate(), ShouldNotBeNil)
(...skipping 16 matching lines...) Expand all
54 func TestFlags(t *testing.T) { 56 func TestFlags(t *testing.T) {
55 Convey(`A Flags instance`, t, func() { 57 Convey(`A Flags instance`, t, func() {
56 f := Flags{ 58 f := Flags{
57 Name: "my/stream", 59 Name: "my/stream",
58 ContentType: "foo/bar", 60 ContentType: "foo/bar",
59 } 61 }
60 62
61 Convey(`Converts to Properties.`, func() { 63 Convey(`Converts to Properties.`, func() {
62 p := f.Properties() 64 p := f.Properties()
63 So(p, ShouldResemble, &Properties{ 65 So(p, ShouldResemble, &Properties{
64 » » » » LogStreamDescriptor: logpb.LogStreamDescriptor{ 66 » » » » LogStreamDescriptor: &logpb.LogStreamDescriptor{
65 Name: "my/stream", 67 Name: "my/stream",
66 ContentType: "foo/bar", 68 ContentType: "foo/bar",
67 StreamType: logpb.StreamType_TEXT, 69 StreamType: logpb.StreamType_TEXT,
68 }, 70 },
69 Tee: TeeNone, 71 Tee: TeeNone,
70 }) 72 })
71 }) 73 })
72 }) 74 })
73 } 75 }
74 76
75 func TestFlagsJSON(t *testing.T) { 77 func TestFlagsJSON(t *testing.T) {
76 Convey(`A Flags instance`, t, func() { 78 Convey(`A Flags instance`, t, func() {
77 f := Flags{} 79 f := Flags{}
78 Convey(`Will decode a TEXT stream.`, func() { 80 Convey(`Will decode a TEXT stream.`, func() {
79 t := `{"name": "my/stream", "contentType": "foo/bar", "t ype": "text"}` 81 t := `{"name": "my/stream", "contentType": "foo/bar", "t ype": "text"}`
80 So(json.Unmarshal([]byte(t), &f), ShouldBeNil) 82 So(json.Unmarshal([]byte(t), &f), ShouldBeNil)
81 83
82 So(f.Properties(), ShouldResemble, &Properties{ 84 So(f.Properties(), ShouldResemble, &Properties{
83 » » » » LogStreamDescriptor: logpb.LogStreamDescriptor{ 85 » » » » LogStreamDescriptor: &logpb.LogStreamDescriptor{
84 Name: "my/stream", 86 Name: "my/stream",
85 ContentType: "foo/bar", 87 ContentType: "foo/bar",
86 StreamType: logpb.StreamType_TEXT, 88 StreamType: logpb.StreamType_TEXT,
87 }, 89 },
88 Tee: TeeNone, 90 Tee: TeeNone,
89 }) 91 })
90 }) 92 })
91 93
92 Convey(`Will fail to decode an invalid stream type.`, func() { 94 Convey(`Will fail to decode an invalid stream type.`, func() {
93 t := `{"name": "my/stream", "type": "XXX_whatisthis?"}` 95 t := `{"name": "my/stream", "type": "XXX_whatisthis?"}`
94 So(json.Unmarshal([]byte(t), &f), ShouldNotBeNil) 96 So(json.Unmarshal([]byte(t), &f), ShouldNotBeNil)
95 }) 97 })
96 98
97 Convey(`Will decode a BINARY stream.`, func() { 99 Convey(`Will decode a BINARY stream.`, func() {
98 t := `{"name": "my/stream", "type": "binary"}` 100 t := `{"name": "my/stream", "type": "binary"}`
99 So(json.Unmarshal([]byte(t), &f), ShouldBeNil) 101 So(json.Unmarshal([]byte(t), &f), ShouldBeNil)
100 102
101 So(f.Properties(), ShouldResemble, &Properties{ 103 So(f.Properties(), ShouldResemble, &Properties{
102 » » » » LogStreamDescriptor: logpb.LogStreamDescriptor{ 104 » » » » LogStreamDescriptor: &logpb.LogStreamDescriptor{
103 Name: "my/stream", 105 Name: "my/stream",
104 StreamType: logpb.StreamType_BINARY, 106 StreamType: logpb.StreamType_BINARY,
105 ContentType: string(types.ContentTypeBin ary), 107 ContentType: string(types.ContentTypeBin ary),
106 }, 108 },
107 Tee: TeeNone, 109 Tee: TeeNone,
108 }) 110 })
109 }) 111 })
110 112
111 Convey(`Will decode a DATAGRAM stream.`, func() { 113 Convey(`Will decode a DATAGRAM stream.`, func() {
112 t := `{"name": "my/stream", "type": "datagram"}` 114 t := `{"name": "my/stream", "type": "datagram"}`
113 So(json.Unmarshal([]byte(t), &f), ShouldBeNil) 115 So(json.Unmarshal([]byte(t), &f), ShouldBeNil)
114 116
115 So(f.Properties(), ShouldResemble, &Properties{ 117 So(f.Properties(), ShouldResemble, &Properties{
116 » » » » LogStreamDescriptor: logpb.LogStreamDescriptor{ 118 » » » » LogStreamDescriptor: &logpb.LogStreamDescriptor{
117 Name: "my/stream", 119 Name: "my/stream",
118 StreamType: logpb.StreamType_DATAGRAM, 120 StreamType: logpb.StreamType_DATAGRAM,
119 ContentType: string(types.ContentTypeLog dogDatagram), 121 ContentType: string(types.ContentTypeLog dogDatagram),
120 }, 122 },
121 Tee: TeeNone, 123 Tee: TeeNone,
122 }) 124 })
123 }) 125 })
124 }) 126 })
125 } 127 }
OLDNEW
« no previous file with comments | « logdog/client/butlerlib/streamproto/properties.go ('k') | logdog/client/cmd/logdog_annotee/filesystemClient.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698