-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathresolve_test.go
More file actions
93 lines (84 loc) · 2.26 KB
/
resolve_test.go
File metadata and controls
93 lines (84 loc) · 2.26 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package seiconfig
import (
"reflect"
"testing"
)
func TestSetReflectValue_StringSlice(t *testing.T) {
var s []string
v := reflect.ValueOf(&s).Elem()
if err := setReflectValue(v, "a, b ,c"); err != nil {
t.Fatalf("setReflectValue: %v", err)
}
want := []string{"a", "b", "c"}
if !reflect.DeepEqual(s, want) {
t.Errorf("got %v, want %v", s, want)
}
}
func TestSetReflectValue_RejectsNonStringSlice(t *testing.T) {
var s []int
v := reflect.ValueOf(&s).Elem()
err := setReflectValue(v, "1,2,3")
if err == nil {
t.Fatal("expected error for []int slice")
}
if got := err.Error(); got != "unsupported slice element kind: int" {
t.Errorf("got %q, want %q", got, "unsupported slice element kind: int")
}
}
func TestSetReflectValue_RejectsSliceOfSlice(t *testing.T) {
var s [][]string
v := reflect.ValueOf(&s).Elem()
err := setReflectValue(v, "anything")
if err == nil {
t.Fatal("expected error for [][]string")
}
if got := err.Error(); got != "unsupported slice element kind: slice" {
t.Errorf("got %q, want %q", got, "unsupported slice element kind: slice")
}
}
func TestParseStringSlice(t *testing.T) {
cases := []struct {
name string
in string
want []string
}{
{"empty yields non-nil empty", "", []string{}},
{"single value", "a", []string{"a"}},
{"multi value", "a,b,c", []string{"a", "b", "c"}},
{"trims whitespace", " a , b , c ", []string{"a", "b", "c"}},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got, err := parseStringSlice(tc.in)
if err != nil {
t.Fatalf("parseStringSlice(%q): %v", tc.in, err)
}
if !reflect.DeepEqual(got, tc.want) {
t.Errorf("parseStringSlice(%q): got %v, want %v", tc.in, got, tc.want)
}
if got == nil {
t.Errorf("parseStringSlice(%q) returned nil; want non-nil empty slice", tc.in)
}
})
}
}
func TestParseStringSlice_RejectsEmptyEntries(t *testing.T) {
cases := []struct {
name string
in string
}{
{"leading comma", ",a"},
{"trailing comma", "a,"},
{"consecutive commas", "a,,b"},
{"only whitespace entry", "a, ,b"},
{"only commas", ",,,"},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
_, err := parseStringSlice(tc.in)
if err == nil {
t.Fatalf("parseStringSlice(%q): expected error, got nil", tc.in)
}
})
}
}