fix bug where string slice flag is not assigned

This commit is contained in:
zhiming 2021-06-05 20:33:17 +08:00
parent 8eff96dd12
commit c9414c2bba
2 changed files with 3 additions and 4 deletions

View File

@ -46,8 +46,7 @@ func (s *StringSlice) String() string {
func (s *StringSlice) Set(val string) error {
if s.value == nil || !s.changed {
v := make([]string, 0)
s.value = &v
*s.value = make([]string, 0)
}
*s.value = append(*s.value, val)
s.changed = true

View File

@ -83,8 +83,8 @@ func TestStringSlice(t *testing.T) {
} else if err != nil {
t.Errorf("%d: expected nil error, got %v", i, err)
}
if !reflect.DeepEqual(*v.value, test.expected) {
t.Errorf("%d: expected %+v, got %+v", i, test.expected, *v.value)
if !reflect.DeepEqual(s, test.expected) {
t.Errorf("%d: expected %+v, got %+v", i, test.expected, s)
}
if v.changed != test.changed {
t.Errorf("%d: expected %t got %t", i, test.changed, v.changed)