1
|
|
|
package metadata |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"testing" |
5
|
|
|
) |
6
|
|
|
|
7
|
|
|
func TestPayloadAddTag(t *testing.T) { |
8
|
|
|
p := New() |
9
|
|
|
|
10
|
|
|
p.AddTag("tag1", "true") |
11
|
|
|
if p.Tags()["tag1"] != true { |
12
|
|
|
t.Errorf("`true` strings should be converted to bool type, got `%t`", p.Tags()["tag1"]) |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
p.AddTag("tag2", "false") |
16
|
|
|
if p.Tags()["tag2"] != false { |
17
|
|
|
t.Errorf("`false` strings should be converted to bool type, got `%t`", p.Tags()["tag2"]) |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
p.AddTag("tag3", "test") |
21
|
|
|
if p.Tags()["tag3"] != "test" { |
22
|
|
|
t.Errorf("strings should not be converted, got `%s`", p.Tags()["tag3"]) |
23
|
|
|
} |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
func TestPayloadAddList(t *testing.T) { |
27
|
|
|
p := New() |
28
|
|
|
if p.UseSeparator() { |
29
|
|
|
t.Error("separator usage should be `false` by default") |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
p.AddList("tag1", []string{"a"}) |
33
|
|
|
if p.UseSeparator() { |
34
|
|
|
t.Error("separator usage should not be set to `true` if adding a list tag with less than 2 non-empty values") |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
p.AddList("tag2", []string{"a", "a", "", " "}) |
38
|
|
|
if p.UseSeparator() { |
39
|
|
|
t.Errorf("separator usage should not be set to `true` if adding a list tag with less than 2 non-empty unique values: `%s`", p.Tags()["tag2"]) |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
p.AddList("tag3", []string{"a", "b"}) |
43
|
|
|
if !p.UseSeparator() { |
44
|
|
|
t.Error("separator should be set to `true` after adding a list tag with more than one non-empty value") |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
p.AddList("tag4", []string{"c"}) |
48
|
|
|
if !p.UseSeparator() { |
49
|
|
|
t.Error("separator shouldn't be set to `false` once it is set to `true`") |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
func TestPayloadUpdateTag(t *testing.T) { |
54
|
|
|
p := New() |
55
|
|
|
if p.UseSeparator() { |
56
|
|
|
t.Error("separator usage should be `false` by default") |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
p.AddList("tag1", []string{"a"}) |
60
|
|
|
if p.UseSeparator() { |
61
|
|
|
t.Error("separator usage should not be set to `true` if adding a list tag with less than 2 non-empty values") |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
p.UpdateList("tag1", []string{"b"}) |
65
|
|
|
if !p.UseSeparator() { |
66
|
|
|
t.Error("separator should be set to `true` after adding a list tag with more than one non-empty value") |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
p.AddList("tag1", []string{"c"}) |
70
|
|
|
if p.UseSeparator() { |
71
|
|
|
t.Error("separator usage should not be set to `true` if adding a list tag with less than 2 non-empty values") |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|