|
|
|
@ -201,3 +201,124 @@ func TestTestExecuteExceptions(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestTestUnmarshal(t *testing.T) {
|
|
|
|
|
type kubeletConfig struct {
|
|
|
|
|
Kind string
|
|
|
|
|
ApiVersion string
|
|
|
|
|
Address string
|
|
|
|
|
}
|
|
|
|
|
cases := []struct {
|
|
|
|
|
content string
|
|
|
|
|
jsonInterface interface{}
|
|
|
|
|
expectedToFail bool
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
`{
|
|
|
|
|
"kind": "KubeletConfiguration",
|
|
|
|
|
"apiVersion": "kubelet.config.k8s.io/v1beta1",
|
|
|
|
|
"address": "0.0.0.0"
|
|
|
|
|
}
|
|
|
|
|
`,
|
|
|
|
|
kubeletConfig{},
|
|
|
|
|
false,
|
|
|
|
|
}, {
|
|
|
|
|
`
|
|
|
|
|
kind: KubeletConfiguration
|
|
|
|
|
address: 0.0.0.0
|
|
|
|
|
apiVersion: kubelet.config.k8s.io/v1beta1
|
|
|
|
|
authentication:
|
|
|
|
|
anonymous:
|
|
|
|
|
enabled: false
|
|
|
|
|
webhook:
|
|
|
|
|
cacheTTL: 2m0s
|
|
|
|
|
enabled: true
|
|
|
|
|
x509:
|
|
|
|
|
clientCAFile: /etc/kubernetes/pki/ca.crt
|
|
|
|
|
tlsCipherSuites:
|
|
|
|
|
- TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
|
|
|
|
|
- TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
|
|
|
|
|
`,
|
|
|
|
|
kubeletConfig{},
|
|
|
|
|
false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
`
|
|
|
|
|
kind: ddress: 0.0.0.0
|
|
|
|
|
apiVersion: kubelet.config.k8s.io/v1beta
|
|
|
|
|
`,
|
|
|
|
|
kubeletConfig{},
|
|
|
|
|
true,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, c := range cases {
|
|
|
|
|
err := unmarshal(c.content, &c.jsonInterface)
|
|
|
|
|
if err != nil {
|
|
|
|
|
if !c.expectedToFail {
|
|
|
|
|
t.Errorf("%s, expectedToFail:%v, got:%v\n", c.content, c.expectedToFail, err)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if c.expectedToFail {
|
|
|
|
|
t.Errorf("%s, expectedToFail:%v, got:Did not fail\n", c.content, c.expectedToFail)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestExecuteJSONPath(t *testing.T) {
|
|
|
|
|
type kubeletConfig struct {
|
|
|
|
|
Kind string
|
|
|
|
|
ApiVersion string
|
|
|
|
|
Address string
|
|
|
|
|
}
|
|
|
|
|
cases := []struct {
|
|
|
|
|
jsonPath string
|
|
|
|
|
jsonInterface kubeletConfig
|
|
|
|
|
expectedResult string
|
|
|
|
|
expectedToFail bool
|
|
|
|
|
}{
|
|
|
|
|
{
|
|
|
|
|
// JSONPath parse works, results don't match
|
|
|
|
|
"{.Kind}",
|
|
|
|
|
kubeletConfig{
|
|
|
|
|
Kind: "KubeletConfiguration",
|
|
|
|
|
ApiVersion: "kubelet.config.k8s.io/v1beta1",
|
|
|
|
|
Address: "127.0.0.0",
|
|
|
|
|
},
|
|
|
|
|
"blah",
|
|
|
|
|
true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
// JSONPath parse works, results match
|
|
|
|
|
"{.Kind}",
|
|
|
|
|
kubeletConfig{
|
|
|
|
|
Kind: "KubeletConfiguration",
|
|
|
|
|
ApiVersion: "kubelet.config.k8s.io/v1beta1",
|
|
|
|
|
Address: "127.0.0.0",
|
|
|
|
|
},
|
|
|
|
|
"KubeletConfiguration",
|
|
|
|
|
false,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
// JSONPath parse fails
|
|
|
|
|
"{.ApiVersion",
|
|
|
|
|
kubeletConfig{
|
|
|
|
|
Kind: "KubeletConfiguration",
|
|
|
|
|
ApiVersion: "kubelet.config.k8s.io/v1beta1",
|
|
|
|
|
Address: "127.0.0.0",
|
|
|
|
|
},
|
|
|
|
|
"",
|
|
|
|
|
true,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
for _, c := range cases {
|
|
|
|
|
result, err := executeJSONPath(c.jsonPath, c.jsonInterface)
|
|
|
|
|
if err != nil && !c.expectedToFail {
|
|
|
|
|
t.Fatalf("jsonPath:%q, expectedResult:%q got:%v\n", c.jsonPath, c.expectedResult, err)
|
|
|
|
|
}
|
|
|
|
|
if c.expectedResult != result && !c.expectedToFail {
|
|
|
|
|
t.Errorf("jsonPath:%q, expectedResult:%q got:%q\n", c.jsonPath, c.expectedResult, result)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|