Skip to content

Commit

Permalink
Merge pull request #13 from joselo85/windowsk8s/windows-unit-tests/co…
Browse files Browse the repository at this point in the history
…nsul-635-update-mesh_webhook_test.go-add-isWindows-test

[CONSUL-635] Add isWindows Test
  • Loading branch information
joselo85 authored Jan 31, 2023
2 parents eb44609 + 093d521 commit 9027f9f
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions control-plane/connect-inject/webhook/mesh_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1778,6 +1778,54 @@ func TestHandler_checkUnsupportedMultiPortCases(t *testing.T) {
}
}

func TestIsWindows(t *testing.T) {

cases := []struct {
Name string
Pod func(*corev1.Pod) *corev1.Pod
expValue bool
}{
{
"Nodeselector not set",
func(pod *corev1.Pod) *corev1.Pod {
return pod
},
false,
},
{
"Nodeselector.kubernetes.io/os set to linux",
func(pod *corev1.Pod) *corev1.Pod {
pod.Spec = corev1.PodSpec{
NodeSelector: map[string]string{
"kubernetes.io/os": "linux",
},
}
return pod
},
false,
},
{
"Nodeselector.kubernetes.io/os set to windows",
func(pod *corev1.Pod) *corev1.Pod {
pod.Spec = corev1.PodSpec{
NodeSelector: map[string]string{
"kubernetes.io/os": "windows",
},
}
return pod
},
true,
},
}

for _, tt := range cases {
t.Run(tt.Name, func(t *testing.T) {
actual := isWindows(*tt.Pod(&corev1.Pod{}))
require.EqualValues(t, tt.expValue, actual)
})
}
}

// encodeRaw is a helper to encode some data into a RawExtension.
func encodeRaw(t *testing.T, input interface{}) runtime.RawExtension {
data, err := json.Marshal(input)
Expand Down

0 comments on commit 9027f9f

Please sign in to comment.