go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/auth_service/internal/pubsub/publish_test.go (about) 1 // Copyright 2024 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package pubsub 16 17 import ( 18 "context" 19 "testing" 20 "time" 21 22 "github.com/golang/mock/gomock" 23 24 "go.chromium.org/luci/gae/impl/memory" 25 "go.chromium.org/luci/gae/service/info" 26 "go.chromium.org/luci/server/auth" 27 "go.chromium.org/luci/server/auth/service/protocol" 28 "go.chromium.org/luci/server/auth/signing" 29 "go.chromium.org/luci/server/auth/signing/signingtest" 30 31 . "github.com/smartystreets/goconvey/convey" 32 ) 33 34 func TestPublishAuthDBRevision(t *testing.T) { 35 t.Parallel() 36 37 Convey("PublishAuthDBRevision works", t, func() { 38 testAppID := "chrome-infra-auth-test" 39 ctx := memory.UseWithAppID(context.Background(), "dev~"+testAppID) 40 ctx = auth.ModifyConfig(ctx, func(cfg auth.Config) auth.Config { 41 cfg.Signer = signingtest.NewSigner(&signing.ServiceInfo{ 42 AppID: testAppID, 43 ServiceAccountName: "chrome-infra-auth-test@fake.serviceaccount.com", 44 }) 45 return cfg 46 }) 47 48 // Set up mock Pubsub client 49 ctl := gomock.NewController(t) 50 mockClient := NewMockedClient(ctx, ctl) 51 ctx = mockClient.Ctx 52 53 // Define expected client calls. 54 gomock.InOrder( 55 mockClient.Client.EXPECT().Publish(gomock.Any(), gomock.Any()).Times(1), 56 mockClient.Client.EXPECT().Close().Times(1), 57 ) 58 59 testModifiedTS := time.Date(2021, time.August, 16, 12, 20, 0, 0, time.UTC) 60 testRev := &protocol.AuthDBRevision{ 61 PrimaryId: info.AppID(ctx), 62 AuthDbRev: 123, 63 ModifiedTs: testModifiedTS.UnixMicro(), 64 } 65 err := PublishAuthDBRevision(ctx, testRev, false) 66 So(err, ShouldBeNil) 67 }) 68 }