...
1
16
17 package componentconfigs
18
19 import (
20 "path/filepath"
21 "reflect"
22 "testing"
23
24 kubeletconfig "k8s.io/kubelet/config/v1beta1"
25 "k8s.io/utils/ptr"
26 )
27
28 func TestMutatePaths(t *testing.T) {
29 const drive = "C:"
30 var fooResolverConfig string = "/foo/resolver"
31
32 tests := []struct {
33 name string
34 cfg *kubeletconfig.KubeletConfiguration
35 expected *kubeletconfig.KubeletConfiguration
36 }{
37 {
38 name: "valid: all fields are absolute paths",
39 cfg: &kubeletconfig.KubeletConfiguration{
40 ResolverConfig: &fooResolverConfig,
41 StaticPodPath: "/foo/staticpods",
42 Authentication: kubeletconfig.KubeletAuthentication{
43 X509: kubeletconfig.KubeletX509Authentication{
44 ClientCAFile: "/foo/ca.crt",
45 },
46 },
47 },
48 expected: &kubeletconfig.KubeletConfiguration{
49 ResolverConfig: ptr.To(""),
50 StaticPodPath: filepath.Join(drive, "/foo/staticpods"),
51 Authentication: kubeletconfig.KubeletAuthentication{
52 X509: kubeletconfig.KubeletX509Authentication{
53 ClientCAFile: filepath.Join(drive, "/foo/ca.crt"),
54 },
55 },
56 },
57 },
58 {
59 name: "valid: some fields are not absolute paths",
60 cfg: &kubeletconfig.KubeletConfiguration{
61 ResolverConfig: &fooResolverConfig,
62 StaticPodPath: "./foo/staticpods",
63 Authentication: kubeletconfig.KubeletAuthentication{
64 X509: kubeletconfig.KubeletX509Authentication{
65 ClientCAFile: "/foo/ca.crt",
66 },
67 },
68 },
69 expected: &kubeletconfig.KubeletConfiguration{
70 ResolverConfig: ptr.To(""),
71 StaticPodPath: "./foo/staticpods",
72 Authentication: kubeletconfig.KubeletAuthentication{
73 X509: kubeletconfig.KubeletX509Authentication{
74 ClientCAFile: filepath.Join(drive, "/foo/ca.crt"),
75 },
76 },
77 },
78 },
79 }
80
81 for _, test := range tests {
82 t.Run(test.name, func(t *testing.T) {
83 mutatePaths(test.cfg, drive)
84 if !reflect.DeepEqual(test.cfg, test.expected) {
85 t.Errorf("Missmatch between expected and got:\nExpected:\n%+v\n---\nGot:\n%+v",
86 test.expected, test.cfg)
87 }
88 })
89 }
90 }
91
View as plain text