forked from mogensen/kubernetes-split-yaml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kubernetes-resources_test.go
53 lines (48 loc) · 1.2 KB
/
kubernetes-resources_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
package main
import (
"fmt"
"testing"
)
func Test_getShortName(t *testing.T) {
tests := []struct {
name string
have string
want string
}{
{have: "ServiceAccount", want: "sa"},
{have: "horizontalpodautoscaler", want: "hpa"},
{have: "Pod", want: "pod"},
}
for _, tt := range tests {
name := fmt.Sprintf("%s -> %s", tt.have, tt.want)
t.Run(name, func(t *testing.T) {
if got := getShortName(tt.have, nil); got != tt.want {
t.Errorf("getShortName() = %v, want %v", got, tt.want)
}
})
}
}
func Test_getShortName_CustomMap(t *testing.T) {
tests := []struct {
name string
have string
want string
}{
{have: "ServiceAccount", want: "sa"},
{have: "horizontalpodautoscaler", want: "hpa"},
{have: "Pod", want: "pod"},
{have: "Deployment", want: "dep"},
}
customShortNameMap, err := loadCustomShortnameMapFile("./testdata/custom_sn_map.json")
if err != nil {
t.Fatalf("Could not load custom shortname map file: %v", err)
}
for _, tt := range tests {
name := fmt.Sprintf("%s -> %s", tt.have, tt.want)
t.Run(name, func(t *testing.T) {
if got := getShortName(tt.have, customShortNameMap); got != tt.want {
t.Errorf("getShortName() = %v, want %v", got, tt.want)
}
})
}
}