go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/analysis/internal/buildbucket/buildbucket_test.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 "testing" 20 21 "github.com/golang/mock/gomock" 22 "google.golang.org/genproto/protobuf/field_mask" 23 "google.golang.org/protobuf/proto" 24 25 bbpb "go.chromium.org/luci/buildbucket/proto" 26 27 . "github.com/smartystreets/goconvey/convey" 28 . "go.chromium.org/luci/common/testing/assertions" 29 ) 30 31 func TestGetBuild(t *testing.T) { 32 t.Parallel() 33 34 Convey("Get build", t, func() { 35 36 ctl := gomock.NewController(t) 37 defer ctl.Finish() 38 mc := NewMockedClient(context.Background(), ctl) 39 40 bID := int64(87654321) 41 inv := "invocations/build-87654321" 42 43 req := &bbpb.GetBuildRequest{ 44 Id: bID, 45 Mask: &bbpb.BuildMask{ 46 Fields: &field_mask.FieldMask{ 47 Paths: []string{"builder", "infra.resultdb", "status"}, 48 }, 49 }, 50 } 51 52 res := &bbpb.Build{ 53 Builder: &bbpb.BuilderID{ 54 Project: "chromium", 55 Bucket: "ci", 56 Builder: "builder", 57 }, 58 Infra: &bbpb.BuildInfra{ 59 Resultdb: &bbpb.BuildInfra_ResultDB{ 60 Hostname: "results.api.cr.dev", 61 Invocation: inv, 62 }, 63 }, 64 Status: bbpb.Status_FAILURE, 65 } 66 reqCopy := proto.Clone(req).(*bbpb.GetBuildRequest) 67 mc.GetBuild(reqCopy, res) 68 69 bc, err := NewClient(mc.Ctx, "bbhost", "chromium") 70 So(err, ShouldBeNil) 71 b, err := bc.GetBuild(mc.Ctx, req) 72 So(err, ShouldBeNil) 73 So(b, ShouldResembleProto, res) 74 }) 75 }