forked from mtougeron/k8s-pvc-tagger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
111 lines (107 loc) · 2.68 KB
/
main_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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Licensed to Michael Tougeron <github@e.tougeron.com> under
// one or more contributor license agreements. See the LICENSE
// file distributed with this work for additional information
// regarding copyright ownership.
// Michael Tougeron <github@e.tougeron.com> licenses this file
// to you under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package main
import (
"reflect"
"testing"
)
func Test_parseCsv(t *testing.T) {
tests := []struct {
name string
csv string
want map[string]string
}{
{
name: "empty string",
csv: "",
want: map[string]string{},
},
{
name: "single key/value string",
csv: "touge=me",
want: map[string]string{"touge": "me"},
},
{
name: "multiple key/value string",
csv: "touge=me,foo=bar",
want: map[string]string{"touge": "me", "foo": "bar"},
},
{
name: "invalid string",
csv: "foo",
want: map[string]string{},
},
{
name: "invalid key string",
csv: "=foo",
want: map[string]string{},
},
{
name: "invalid value string",
csv: "foo=",
want: map[string]string{},
},
{
name: "double delim",
csv: "foo=bar,,touge=me",
want: map[string]string{"touge": "me", "foo": "bar"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := parseCsv(tt.csv); !reflect.DeepEqual(got, tt.want) {
t.Errorf("parseCsv() = %v, want %v", got, tt.want)
}
})
}
}
func Test_parseCopyLabels(t *testing.T) {
tests := []struct {
name string
copyLabelsString string
want []string
}{
{
name: "copy all labels",
copyLabelsString: "*",
want: []string{"*"},
},
{
name: "copy one label",
copyLabelsString: "foo",
want: []string{"foo"},
},
{
name: "copy multiple labels",
copyLabelsString: "foo,bar",
want: []string{"foo", "bar"},
},
{
name: "copy no labels",
copyLabelsString: "",
want: []string{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := parseCopyLabels(tt.copyLabelsString); !reflect.DeepEqual(got, tt.want) {
t.Errorf("parseCopyLabels() = %v, want %v", got, tt.want)
}
})
}
}