go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/common/flag/stringslice_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  	. "github.com/smartystreets/goconvey/convey"
    21  )
    22  
    23  func TestStringSliceFlag(t *testing.T) {
    24  	t.Parallel()
    25  
    26  	Convey("one", t, func() {
    27  		var flag stringSliceFlag
    28  		So(flag.Set("abc"), ShouldBeNil)
    29  		So(flag.Get(), ShouldResemble, []string{"abc"})
    30  		So(flag.String(), ShouldEqual, "abc")
    31  	})
    32  
    33  	Convey("many", t, func() {
    34  		var flag stringSliceFlag
    35  		So(flag.Set("abc"), ShouldBeNil)
    36  		So(flag.Set("def"), ShouldBeNil)
    37  		So(flag.Set("ghi"), ShouldBeNil)
    38  		So(flag.Get(), ShouldResemble, []string{"abc", "def", "ghi"})
    39  		So(flag.String(), ShouldEqual, "abc, def, ghi")
    40  	})
    41  }
    42  
    43  func TestStringSlice(t *testing.T) {
    44  	t.Parallel()
    45  
    46  	Convey("one", t, func() {
    47  		var s []string
    48  		So(StringSlice(&s).Set("abc"), ShouldBeNil)
    49  		So(s, ShouldResemble, []string{"abc"})
    50  	})
    51  
    52  	Convey("many", t, func() {
    53  		var s []string
    54  		So(StringSlice(&s).Set("abc"), ShouldBeNil)
    55  		So(StringSlice(&s).Set("def"), ShouldBeNil)
    56  		So(StringSlice(&s).Set("ghi"), ShouldBeNil)
    57  		So(s, ShouldResemble, []string{"abc", "def", "ghi"})
    58  	})
    59  }