| Index: milo/common/pubsub_test.go
|
| diff --git a/milo/common/pubsub_test.go b/milo/common/pubsub_test.go
|
| index 4ac7886d91ec9ec43f73b9a5b5c37aa7bc3648ff..172d5708f48055cc9cc450f6a783015912c178ed 100644
|
| --- a/milo/common/pubsub_test.go
|
| +++ b/milo/common/pubsub_test.go
|
| @@ -13,6 +13,7 @@ import (
|
| "golang.org/x/net/context"
|
|
|
| "github.com/luci/gae/impl/memory"
|
| + luciErrors "github.com/luci/luci-go/common/errors"
|
| "github.com/luci/luci-go/common/logging/gologger"
|
|
|
| . "github.com/smartystreets/goconvey/convey"
|
| @@ -26,7 +27,7 @@ type testPubSubClient struct {
|
| }
|
|
|
| // Topic returns an empty pubsub topic reference.
|
| -func (client *testPubSubClient) getTopic(id string) (*pubsub.Topic, error) {
|
| +func (client *testPubSubClient) getTopic(c context.Context, id string) (*pubsub.Topic, error) {
|
| if err, ok := client.topics[id]; ok {
|
| return &pubsub.Topic{}, err
|
| }
|
| @@ -34,7 +35,7 @@ func (client *testPubSubClient) getTopic(id string) (*pubsub.Topic, error) {
|
| }
|
|
|
| // Subscription returns an empty subscription reference.
|
| -func (client *testPubSubClient) getSubscription(id string) (
|
| +func (client *testPubSubClient) getSubscription(c context.Context, id string) (
|
| *pubsub.Subscription, error) {
|
| if err, ok := client.subscriptions[id]; ok {
|
| return &pubsub.Subscription{}, err
|
| @@ -45,7 +46,7 @@ func (client *testPubSubClient) getSubscription(id string) (
|
| // CreateSubscription records that an attempt to create a subscription with
|
| // an id, then returns an empty subscription.
|
| func (client *testPubSubClient) createSubscription(
|
| - id string, cfg pubsub.SubscriptionConfig) (
|
| + c context.Context, id string, cfg pubsub.SubscriptionConfig) (
|
| *pubsub.Subscription, error) {
|
|
|
| if err, ok := client.createdSubsErr[id]; ok {
|
| @@ -61,53 +62,62 @@ func TestPubSub(t *testing.T) {
|
| Convey("Test Environment", t, func() {
|
| c := memory.UseWithAppID(context.Background(), "dev~luci-milo")
|
| c = gologger.StdConfig.Use(c)
|
| - client := &testPubSubClient{
|
| + miloClient := &testPubSubClient{
|
| topics: map[string]error{},
|
| subscriptions: map[string]error{},
|
| createdSubsErr: map[string]error{},
|
| createdSubs: map[string]pubsub.SubscriptionConfig{}}
|
| - c = context.WithValue(c, &pubSubClientKey, client)
|
| + bbClient := &testPubSubClient{
|
| + topics: map[string]error{},
|
| + subscriptions: map[string]error{},
|
| + createdSubsErr: map[string]error{},
|
| + createdSubs: map[string]pubsub.SubscriptionConfig{}}
|
| + clients := newClientsBundle()
|
| + clients.clients["buildbucket"] = bbClient
|
| + clients.clients["luci-milo"] = miloClient
|
| + c = context.WithValue(c, &pubSubClientKey, clients)
|
|
|
| Convey("Buildbucket PubSub subscriber", func() {
|
| - proj := "foo"
|
| + proj := "buildbucket"
|
| Convey("Non-existant topic", func() {
|
| - client.topics["builds"] = errNotExist
|
| + bbClient.topics["builds"] = errNotExist
|
| err := ensureBuildbucketSubscribed(c, proj)
|
| So(err.Error(), ShouldEndWith, "does not exist")
|
| })
|
| Convey("Permission denied", func() {
|
| pErr := errors.New(
|
| "something PermissionDenied something")
|
| - client.topics["builds"] = pErr
|
| + bbClient.topics["builds"] = pErr
|
| err := ensureBuildbucketSubscribed(c, proj)
|
| So(err, ShouldEqual, pErr)
|
| })
|
| Convey("Normal error", func() {
|
| pErr := errors.New("foobar")
|
| - client.topics["builds"] = pErr
|
| + bbClient.topics["builds"] = pErr
|
| err := ensureBuildbucketSubscribed(c, proj)
|
| So(err, ShouldEqual, pErr)
|
| })
|
| - client.topics["builds"] = nil
|
| + bbClient.topics["builds"] = nil
|
| Convey("Subscription exists", func() {
|
| - client.subscriptions["luci-milo"] = nil
|
| + miloClient.subscriptions["buildbucket"] = nil
|
| err := ensureBuildbucketSubscribed(c, proj)
|
| So(err, ShouldBeNil)
|
| - So(len(client.createdSubs), ShouldEqual, 0)
|
| + So(len(miloClient.createdSubs), ShouldEqual, 0)
|
| + So(len(bbClient.createdSubs), ShouldEqual, 0)
|
| })
|
| - client.subscriptions["luci-milo"] = errNotExist
|
| + miloClient.subscriptions["buildbucket"] = errNotExist
|
| Convey("Not registered", func() {
|
| errNotReg := errors.New("The supplied HTTP URL is not registered")
|
| - client.createdSubsErr["luci-milo"] = errNotReg
|
| + miloClient.createdSubsErr["buildbucket"] = errNotReg
|
| err := ensureBuildbucketSubscribed(c, proj)
|
| - So(err, ShouldEqual, errNotReg)
|
| + So((err.(luciErrors.Wrapped)).InnerError(), ShouldEqual, errNotReg)
|
| })
|
| Convey("Create subscription", func() {
|
| - client.createdSubsErr["luci-milo"] = nil
|
| + miloClient.createdSubsErr["buildbucket"] = nil
|
| err := ensureBuildbucketSubscribed(c, proj)
|
| So(err, ShouldBeNil)
|
| - So(len(client.createdSubs), ShouldEqual, 1)
|
| - _, ok := client.createdSubs["luci-milo"]
|
| + So(len(miloClient.createdSubs), ShouldEqual, 1)
|
| + _, ok := miloClient.createdSubs["buildbucket"]
|
| So(ok, ShouldEqual, true)
|
| })
|
| })
|
|
|