go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/milo/protoutil/predicates_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 protoutil 16 17 import ( 18 "testing" 19 20 . "github.com/smartystreets/goconvey/convey" 21 22 buildbucketpb "go.chromium.org/luci/buildbucket/proto" 23 . "go.chromium.org/luci/common/testing/assertions" 24 milopb "go.chromium.org/luci/milo/proto/v1" 25 ) 26 27 func TestValidateConsolePredicate(t *testing.T) { 28 t.Parallel() 29 Convey(`TestValidateConsolePredicate`, t, func() { 30 Convey(`valid`, func() { 31 err := ValidateConsolePredicate(&milopb.ConsolePredicate{ 32 Project: "project", 33 Builder: &buildbucketpb.BuilderID{ 34 Project: "another_project", 35 Bucket: "bucket", 36 Builder: "builder", 37 }, 38 }) 39 So(err, ShouldBeNil) 40 }) 41 42 Convey(`valid without builder`, func() { 43 err := ValidateConsolePredicate(&milopb.ConsolePredicate{ 44 Project: "project", 45 }) 46 So(err, ShouldBeNil) 47 }) 48 49 Convey(`partial builder`, func() { 50 err := ValidateConsolePredicate(&milopb.ConsolePredicate{ 51 Project: "project", 52 Builder: &buildbucketpb.BuilderID{ 53 Bucket: "bucket", 54 Builder: "builder", 55 }, 56 }) 57 So(err, ShouldNotBeNil) 58 So(err, ShouldErrLike, "builder: project must match") 59 }) 60 61 }) 62 }