go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/buildbucket/cli/status_test.go (about) 1 // Copyright 2019 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 cli 16 17 import ( 18 "testing" 19 20 pb "go.chromium.org/luci/buildbucket/proto" 21 22 . "github.com/smartystreets/goconvey/convey" 23 . "go.chromium.org/luci/common/testing/assertions" 24 ) 25 26 func TestStatusFlag(t *testing.T) { 27 t.Parallel() 28 29 Convey("StatusFlag", t, func() { 30 var status pb.Status 31 f := StatusFlag(&status) 32 33 Convey("Get", func() { 34 So(f.Get(), ShouldEqual, status) 35 status = pb.Status_SUCCESS 36 So(f.Get(), ShouldEqual, status) 37 }) 38 39 Convey("String", func() { 40 So(f.String(), ShouldEqual, "") 41 status = pb.Status_SUCCESS 42 So(f.String(), ShouldEqual, "success") 43 }) 44 45 Convey("Set", func() { 46 Convey("success", func() { 47 So(f.Set("success"), ShouldBeNil) 48 So(status, ShouldEqual, pb.Status_SUCCESS) 49 }) 50 Convey("SUCCESS", func() { 51 So(f.Set("SUCCESS"), ShouldBeNil) 52 So(status, ShouldEqual, pb.Status_SUCCESS) 53 }) 54 Convey("unspecified", func() { 55 So(f.Set("unspecified"), ShouldErrLike, `invalid status "unspecified"; expected one of canceled, ended, failure, infra_failure, scheduled, started, success`) 56 }) 57 Convey("garbage", func() { 58 So(f.Set("garbage"), ShouldErrLike, `invalid status "garbage"; expected one of canceled, ended, failure, infra_failure, scheduled, started, success`) 59 }) 60 }) 61 }) 62 }