go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/analysis/internal/buildbucket/mock.go (about) 1 // Copyright 2022 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 buildbucket 16 17 import ( 18 "context" 19 20 "github.com/golang/mock/gomock" 21 22 bbpb "go.chromium.org/luci/buildbucket/proto" 23 "go.chromium.org/luci/common/proto" 24 ) 25 26 // MockedClient is a mocked Buildbucket client for testing. 27 // It wraps a bbpb.MockBuildsClient and a context with the mocked client. 28 type MockedClient struct { 29 Client *bbpb.MockBuildsClient 30 Ctx context.Context 31 } 32 33 // NewMockedClient creates a MockedClient for testing. 34 func NewMockedClient(ctx context.Context, ctl *gomock.Controller) *MockedClient { 35 mockClient := bbpb.NewMockBuildsClient(ctl) 36 return &MockedClient{ 37 Client: mockClient, 38 Ctx: useBuildsClientForTesting(ctx, mockClient), 39 } 40 } 41 42 // GetBuild Mocks the GetBuild RPC. 43 func (mc *MockedClient) GetBuild(req *bbpb.GetBuildRequest, res *bbpb.Build) { 44 mc.Client.EXPECT().GetBuild(gomock.Any(), proto.MatcherEqual(req), gomock.Any()).Return(res, nil) 45 }