go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/common/flag/fieldslice_test.go (about) 1 // Copyright 2018 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 flag 16 17 import ( 18 "testing" 19 20 "google.golang.org/api/googleapi" 21 22 . "github.com/smartystreets/goconvey/convey" 23 ) 24 25 func TestFieldSliceFlag(t *testing.T) { 26 t.Parallel() 27 28 Convey("one", t, func() { 29 var flag fieldSliceFlag 30 So(flag.Set("abc"), ShouldBeNil) 31 So(flag.Get(), ShouldResemble, []googleapi.Field{"abc"}) 32 So(flag.String(), ShouldEqual, "abc") 33 }) 34 35 Convey("many", t, func() { 36 var flag fieldSliceFlag 37 So(flag.Set("abc"), ShouldBeNil) 38 So(flag.Set("def"), ShouldBeNil) 39 So(flag.Set("ghi"), ShouldBeNil) 40 So(flag.Get(), ShouldResemble, []googleapi.Field{"abc", "def", "ghi"}) 41 So(flag.String(), ShouldEqual, "abc, def, ghi") 42 }) 43 } 44 45 func TestFieldSlice(t *testing.T) { 46 t.Parallel() 47 48 Convey("one", t, func() { 49 var f []googleapi.Field 50 So(FieldSlice(&f).Set("abc"), ShouldBeNil) 51 So(f, ShouldResemble, []googleapi.Field{"abc"}) 52 }) 53 54 Convey("many", t, func() { 55 var f []googleapi.Field 56 So(FieldSlice(&f).Set("abc"), ShouldBeNil) 57 So(FieldSlice(&f).Set("def"), ShouldBeNil) 58 So(FieldSlice(&f).Set("ghi"), ShouldBeNil) 59 So(f, ShouldResemble, []googleapi.Field{"abc", "def", "ghi"}) 60 }) 61 }