-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalue_string_slice_test.go
More file actions
55 lines (38 loc) · 1.12 KB
/
value_string_slice_test.go
File metadata and controls
55 lines (38 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package env
import (
"testing"
"strings"
)
func TestStringSliceValue_Set(t *testing.T) {
var p []string
val := newStringSliceValue([]string{"one", "two"}, &p)
vals := []string{"three", "four"}
val.Set(strings.Join(vals, ",")) // nolint: errcheck
for i, v := range p {
if vals[i] != v {
t.Fatalf("expected p[%d] to be %s but got: %s", i, vals[i], v)
}
}
}
func TestStringSliceValue_SetEmpty(t *testing.T) {
var p []string
val := newStringSliceValue([]string{"one", "two"}, &p)
val.Set("") // nolint: errcheck
if len(p) != 0 {
t.Error("string slice should be clear of default value upon set (even if empty)")
}
}
func TestStringSliceValue_Comma(t *testing.T) {
var p []string
val := newStringSliceValue([]string{}, &p)
expected := []string{"one,two", "three", "four,five", "six"}
val.Set(`"one,two","three","four,five",six`) // nolint: errcheck
if got, want := len(p), len(expected); got != want {
t.Fatalf("expected length of string slice to be %d but got: %d", want, got)
}
for i, v := range p {
if expected[i] != v {
t.Fatalf("expected p[%d] to be %s but got: %s", i, expected[i], v)
}
}
}