go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/bisection/util/buildbucket_util_test.go (about) 1 // Copyright 2023 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 util 16 17 import ( 18 "testing" 19 20 bbpb "go.chromium.org/luci/buildbucket/proto" 21 "google.golang.org/protobuf/types/known/structpb" 22 23 . "github.com/smartystreets/goconvey/convey" 24 . "go.chromium.org/luci/common/testing/assertions" 25 ) 26 27 func TestGetGitilesCommitForBuild(t *testing.T) { 28 Convey("Get position from output", t, func() { 29 build := &bbpb.Build{ 30 Input: &bbpb.Build_Input{ 31 GitilesCommit: &bbpb.GitilesCommit{ 32 Host: "chromium.googlesource.com", 33 Project: "chromium/src", 34 Id: "refs/heads/gfiTest", 35 Ref: "1", 36 }, 37 }, 38 Output: &bbpb.Build_Output{ 39 GitilesCommit: &bbpb.GitilesCommit{ 40 Host: "chromium.googlesource.com", 41 Project: "chromium/src", 42 Id: "refs/heads/gfiTest", 43 Ref: "1", 44 Position: 456, 45 }, 46 }, 47 } 48 commit := GetGitilesCommitForBuild(build) 49 So(commit, ShouldResembleProto, &bbpb.GitilesCommit{ 50 Host: "chromium.googlesource.com", 51 Project: "chromium/src", 52 Id: "refs/heads/gfiTest", 53 Ref: "1", 54 Position: 456, 55 }) 56 }) 57 58 Convey("Output does not match input", t, func() { 59 build := &bbpb.Build{ 60 Input: &bbpb.Build_Input{ 61 GitilesCommit: &bbpb.GitilesCommit{ 62 Host: "chromium.googlesource.com", 63 Project: "chromium/src", 64 Id: "refs/heads/gfiTest", 65 Ref: "1", 66 }, 67 }, 68 Output: &bbpb.Build_Output{ 69 GitilesCommit: &bbpb.GitilesCommit{ 70 Host: "chromium1.googlesource.com", 71 Project: "chromium/src", 72 Id: "refs/heads/gfiTest", 73 Ref: "1", 74 Position: 456, 75 }, 76 }, 77 } 78 commit := GetGitilesCommitForBuild(build) 79 So(commit, ShouldResembleProto, &bbpb.GitilesCommit{ 80 Host: "chromium.googlesource.com", 81 Project: "chromium/src", 82 Id: "refs/heads/gfiTest", 83 Ref: "1", 84 }) 85 }) 86 87 Convey("No output", t, func() { 88 build := &bbpb.Build{ 89 Input: &bbpb.Build_Input{ 90 GitilesCommit: &bbpb.GitilesCommit{ 91 Host: "chromium.googlesource.com", 92 Project: "chromium/src", 93 Id: "refs/heads/gfiTest", 94 Ref: "1", 95 }, 96 }, 97 } 98 commit := GetGitilesCommitForBuild(build) 99 So(commit, ShouldResembleProto, &bbpb.GitilesCommit{ 100 Host: "chromium.googlesource.com", 101 Project: "chromium/src", 102 Id: "refs/heads/gfiTest", 103 Ref: "1", 104 }) 105 }) 106 } 107 108 func TestGetSheriffRotationsForBuild(t *testing.T) { 109 Convey("No sheriff rotation", t, func() { 110 build := &bbpb.Build{} 111 rotations := GetSheriffRotationsForBuild(build) 112 So(rotations, ShouldResemble, []string{}) 113 }) 114 115 Convey("Has sheriff rotation", t, func() { 116 build := &bbpb.Build{ 117 Input: &bbpb.Build_Input{ 118 Properties: &structpb.Struct{ 119 Fields: map[string]*structpb.Value{ 120 "sheriff_rotations": structpb.NewListValue(&structpb.ListValue{ 121 Values: []*structpb.Value{ 122 structpb.NewStringValue("chromium"), 123 }, 124 }), 125 }, 126 }, 127 }, 128 } 129 rotations := GetSheriffRotationsForBuild(build) 130 So(rotations, ShouldResemble, []string{"chromium"}) 131 }) 132 133 } 134 135 func TestGetTaskDimensions(t *testing.T) { 136 dims := []*bbpb.RequestedDimension{ 137 { 138 Key: "dimen_key_1", 139 Value: "dimen_val_1", 140 }, 141 } 142 Convey("from build on swarming", t, func() { 143 build := &bbpb.Build{ 144 Infra: &bbpb.BuildInfra{ 145 Swarming: &bbpb.BuildInfra_Swarming{ 146 TaskDimensions: dims, 147 }, 148 }, 149 } 150 got := GetTaskDimensions(build) 151 So(got, ShouldResembleProto, dims) 152 }) 153 154 Convey("from build on backend", t, func() { 155 build := &bbpb.Build{ 156 Infra: &bbpb.BuildInfra{ 157 Backend: &bbpb.BuildInfra_Backend{ 158 TaskDimensions: dims, 159 }, 160 }, 161 } 162 got := GetTaskDimensions(build) 163 So(got, ShouldResembleProto, dims) 164 }) 165 166 }