forked from slackhq/simple-kubernetes-webhook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinject_env_test.go
78 lines (68 loc) · 1.24 KB
/
inject_env_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
package mutation
import (
"testing"
"github.com/stretchr/testify/assert"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestInjectEnvMutate(t *testing.T) {
want := &corev1.Pod{
ObjectMeta: v1.ObjectMeta{
Name: "test",
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{{
Name: "test",
Env: []corev1.EnvVar{
{
Name: "KUBE",
Value: "true",
},
},
}},
InitContainers: []corev1.Container{{
Name: "inittest",
Env: []corev1.EnvVar{
{
Name: "KUBE",
Value: "true",
},
},
}},
},
}
pod := &corev1.Pod{
ObjectMeta: v1.ObjectMeta{
Name: "test",
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{{
Name: "test",
}},
InitContainers: []corev1.Container{{
Name: "inittest",
}},
},
}
got, err := injectEnv{Logger: logger()}.Mutate(pod)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, want, got)
}
func TestHasEnvVar(t *testing.T) {
ey := corev1.EnvVar{
Name: "foo",
Value: "sball",
}
en := corev1.EnvVar{
Name: "the_pope",
Value: "of_nope",
}
c := corev1.Container{
Name: "test",
Env: []corev1.EnvVar{ey},
}
assert.True(t, HasEnvVar(c, ey))
assert.False(t, HasEnvVar(c, en))
}