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

Side by Side Diff: milo/common/pubsub_test.go

Issue 2981683002: Milo: Move buildbucket pubsub sub from buildbucket project to milo project (Closed)
Patch Set: subID -> appID Created 3 years, 5 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
« milo/common/pubsub.go ('K') | « milo/common/pubsub.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 2017 The LUCI Authors. All rights reserved. 1 // Copyright 2017 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 common 5 package common
6 6
7 import ( 7 import (
8 "errors" 8 "errors"
9 "fmt" 9 "fmt"
10 "testing" 10 "testing"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 } 54 }
55 panic(fmt.Errorf("test error: unknown created sub %s", id)) 55 panic(fmt.Errorf("test error: unknown created sub %s", id))
56 } 56 }
57 57
58 func TestPubSub(t *testing.T) { 58 func TestPubSub(t *testing.T) {
59 t.Parallel() 59 t.Parallel()
60 60
61 Convey("Test Environment", t, func() { 61 Convey("Test Environment", t, func() {
62 c := memory.UseWithAppID(context.Background(), "dev~luci-milo") 62 c := memory.UseWithAppID(context.Background(), "dev~luci-milo")
63 c = gologger.StdConfig.Use(c) 63 c = gologger.StdConfig.Use(c)
64 » » client := &testPubSubClient{ 64 » » miloClient := &testPubSubClient{
65 topics: map[string]error{}, 65 topics: map[string]error{},
66 subscriptions: map[string]error{}, 66 subscriptions: map[string]error{},
67 createdSubsErr: map[string]error{}, 67 createdSubsErr: map[string]error{},
68 createdSubs: map[string]pubsub.SubscriptionConfig{}} 68 createdSubs: map[string]pubsub.SubscriptionConfig{}}
69 » » c = context.WithValue(c, &pubSubClientKey, client) 69 » » bbClient := &testPubSubClient{
70 » » » topics: map[string]error{},
71 » » » subscriptions: map[string]error{},
72 » » » createdSubsErr: map[string]error{},
73 » » » createdSubs: map[string]pubsub.SubscriptionConfig{}}
74 » » clients := pubsubClients{}
75 » » clients["buildbucket"] = bbClient
76 » » clients["luci-milo"] = miloClient
77 » » c = context.WithValue(c, &pubSubClientKey, clients)
70 78
71 Convey("Buildbucket PubSub subscriber", func() { 79 Convey("Buildbucket PubSub subscriber", func() {
72 » » » proj := "foo" 80 » » » proj := "buildbucket"
73 Convey("Non-existant topic", func() { 81 Convey("Non-existant topic", func() {
74 » » » » client.topics["builds"] = errNotExist 82 » » » » bbClient.topics["builds"] = errNotExist
75 err := ensureBuildbucketSubscribed(c, proj) 83 err := ensureBuildbucketSubscribed(c, proj)
76 So(err.Error(), ShouldEndWith, "does not exist") 84 So(err.Error(), ShouldEndWith, "does not exist")
77 }) 85 })
78 Convey("Permission denied", func() { 86 Convey("Permission denied", func() {
79 pErr := errors.New( 87 pErr := errors.New(
80 "something PermissionDenied something") 88 "something PermissionDenied something")
81 » » » » client.topics["builds"] = pErr 89 » » » » bbClient.topics["builds"] = pErr
82 err := ensureBuildbucketSubscribed(c, proj) 90 err := ensureBuildbucketSubscribed(c, proj)
83 So(err, ShouldEqual, pErr) 91 So(err, ShouldEqual, pErr)
84 }) 92 })
85 Convey("Normal error", func() { 93 Convey("Normal error", func() {
86 pErr := errors.New("foobar") 94 pErr := errors.New("foobar")
87 » » » » client.topics["builds"] = pErr 95 » » » » bbClient.topics["builds"] = pErr
88 err := ensureBuildbucketSubscribed(c, proj) 96 err := ensureBuildbucketSubscribed(c, proj)
89 So(err, ShouldEqual, pErr) 97 So(err, ShouldEqual, pErr)
90 }) 98 })
91 » » » client.topics["builds"] = nil 99 » » » bbClient.topics["builds"] = nil
92 Convey("Subscription exists", func() { 100 Convey("Subscription exists", func() {
93 » » » » client.subscriptions["luci-milo"] = nil 101 » » » » miloClient.subscriptions["buildbucket"] = nil
94 err := ensureBuildbucketSubscribed(c, proj) 102 err := ensureBuildbucketSubscribed(c, proj)
95 So(err, ShouldBeNil) 103 So(err, ShouldBeNil)
96 » » » » So(len(client.createdSubs), ShouldEqual, 0) 104 » » » » So(len(miloClient.createdSubs), ShouldEqual, 0)
105 » » » » So(len(bbClient.createdSubs), ShouldEqual, 0)
97 }) 106 })
98 » » » client.subscriptions["luci-milo"] = errNotExist 107 » » » miloClient.subscriptions["buildbucket"] = errNotExist
99 Convey("Not registered", func() { 108 Convey("Not registered", func() {
100 errNotReg := errors.New("The supplied HTTP URL i s not registered") 109 errNotReg := errors.New("The supplied HTTP URL i s not registered")
101 » » » » client.createdSubsErr["luci-milo"] = errNotReg 110 » » » » miloClient.createdSubsErr["buildbucket"] = errNo tReg
102 err := ensureBuildbucketSubscribed(c, proj) 111 err := ensureBuildbucketSubscribed(c, proj)
103 So(err, ShouldEqual, errNotReg) 112 So(err, ShouldEqual, errNotReg)
104 }) 113 })
105 Convey("Create subscription", func() { 114 Convey("Create subscription", func() {
106 » » » » client.createdSubsErr["luci-milo"] = nil 115 » » » » miloClient.createdSubsErr["buildbucket"] = nil
107 err := ensureBuildbucketSubscribed(c, proj) 116 err := ensureBuildbucketSubscribed(c, proj)
108 So(err, ShouldBeNil) 117 So(err, ShouldBeNil)
109 » » » » So(len(client.createdSubs), ShouldEqual, 1) 118 » » » » So(len(miloClient.createdSubs), ShouldEqual, 1)
110 » » » » _, ok := client.createdSubs["luci-milo"] 119 » » » » _, ok := miloClient.createdSubs["buildbucket"]
111 So(ok, ShouldEqual, true) 120 So(ok, ShouldEqual, true)
112 }) 121 })
113 }) 122 })
114 }) 123 })
115 124
116 } 125 }
OLDNEW
« milo/common/pubsub.go ('K') | « milo/common/pubsub.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698