MCPcopy
hub / github.com/spf13/pflag / TestSAWithDefault

Function TestSAWithDefault

string_array_test.go:85–116  ·  string_array_test.go::TestSAWithDefault
(t *testing.T)

Source from the content-addressed store, hash-verified

83}
84
85func TestSAWithDefault(t *testing.T) {
86 var sa []string
87 f := setUpSAFlagSetWithDefault(&sa)
88
89 val := "one"
90 arg := fmt.Sprintf("--sa=%s", val)
91 err := f.Parse([]string{arg})
92 if err != nil {
93 t.Fatal("expected no error; got", err)
94 }
95
96 if len(sa) != 1 {
97 t.Fatalf("expected number of values to be %d but %d", 1, len(sa))
98 }
99
100 if sa[0] != val {
101 t.Fatalf("expected value to be %s but got: %s", sa[0], val)
102 }
103
104 getSA, err := f.GetStringArray("sa")
105 if err != nil {
106 t.Fatal("got an error from GetStringArray():", err)
107 }
108
109 if len(getSA) != 1 {
110 t.Fatalf("expected number of values to be %d but %d", 1, len(getSA))
111 }
112
113 if getSA[0] != val {
114 t.Fatalf("expected value to be %s but got: %s", getSA[0], val)
115 }
116}
117
118func TestSACalledTwice(t *testing.T) {
119 var sa []string

Callers

nothing calls this directly

Calls 3

GetStringArrayMethod · 0.80
ParseMethod · 0.65

Tested by

no test coverage detected