-
Notifications
You must be signed in to change notification settings - Fork 8
/
string_map_test.go
73 lines (64 loc) · 1.38 KB
/
string_map_test.go
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
package main
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestStringMapString(t *testing.T) {
stringMap := StringMap(map[string]string{
"master": "true",
})
expected := "master=true"
if stringMap.String() != expected {
t.Errorf("expected %s, got %s", expected, stringMap.String())
}
}
func TestSetStringMapValue(t *testing.T) {
for _, tc := range []struct {
msg string
value string
valid bool
expected map[string]string
}{
{
msg: "test valid stringMap",
value: "key=value",
valid: true,
expected: map[string]string{
"key": "value",
},
},
{
msg: "test invalid stringMap",
value: "key:value",
valid: false,
},
{
msg: "test valid stringMap with 'complex' key",
value: "complex/key/1:2:3=value",
valid: true,
expected: map[string]string{
"complex/key/1:2:3": "value",
},
},
} {
t.Run(tc.msg, func(t *testing.T) {
stringMap := StringMap(map[string]string{})
err := stringMap.Set(tc.value)
if err != nil && tc.valid {
t.Errorf("should not fail: %s", err)
}
if err == nil && !tc.valid {
t.Error("expected failure")
}
if tc.valid {
require.Equal(t, tc.expected, map[string]string(stringMap))
}
})
}
}
func TestStringMapIsCumulative(t *testing.T) {
var stringMap StringMap
if !stringMap.IsCumulative() {
t.Error("expected IsCumulative = true")
}
}