...

Source file src/github.com/chaos-mesh/chaos-mesh/pkg/flags/flags_test.go

Documentation: github.com/chaos-mesh/chaos-mesh/pkg/flags

     1  // Copyright 2021 Chaos Mesh 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  
    16  package flags
    17  
    18  import (
    19  	"strings"
    20  	"testing"
    21  
    22  	. "github.com/onsi/gomega"
    23  )
    24  
    25  func TestNewMapStringStringFlag(t *testing.T) {
    26  	g := NewGomegaWithT(t)
    27  	flag := NewMapStringStringFlag()
    28  	g.Expect(flag.Values).ShouldNot(BeNil())
    29  }
    30  
    31  func TestMapStringStringFlag_String(t *testing.T) {
    32  	g := NewGomegaWithT(t)
    33  	flag := NewMapStringStringFlag()
    34  
    35  	g.Expect(flag.String()).Should(BeEmpty())
    36  
    37  	var err error
    38  
    39  	err = flag.Set("flag1")
    40  	g.Expect(err).ShouldNot(BeNil())
    41  	g.Expect(flag.String()).Should(BeEmpty())
    42  
    43  	//err = flag.Set("flag1=")
    44  	//err = flag.Set("=")
    45  
    46  	err = flag.Set("")
    47  	g.Expect(err).ShouldNot(BeNil())
    48  	g.Expect(flag.String()).Should(BeEmpty())
    49  
    50  	err = flag.Set("flag2=key2")
    51  	g.Expect(err).Should(BeNil())
    52  	g.Expect(flag.String()).Should(Equal("flag2=key2"))
    53  
    54  	//err = flag.Set("    flag3=key3     ")
    55  	err = flag.Set("flag2=key2")
    56  	g.Expect(err).Should(BeNil())
    57  	g.Expect(flag.String()).Should(Equal("flag2=key2"))
    58  
    59  	err = flag.Set("flag3=key3,flag4=key4,flag2=key22")
    60  
    61  	g.Expect(err).Should(BeNil())
    62  	g.Expect(strings.Contains(flag.String(), "flag2=key22")).To(Equal(true))
    63  	g.Expect(strings.Contains(flag.String(), "flag4=key4")).To(Equal(true))
    64  	g.Expect(strings.Contains(flag.String(), "flag3=key3")).To(Equal(true))
    65  	g.Expect(strings.Contains(flag.String(), ",")).To(Equal(true))
    66  
    67  	g.Expect(len(flag.String())).To(Equal(len("flag3=key3,flag4=key4,flag2=key22")))
    68  }
    69