@@ -42,6 +42,47 @@ func TestCreateDeployment(t *testing.T) {
4242 }
4343}
4444
45+ func TestCreateDeploymentWithTolerations (t * testing.T ) {
46+ os .Setenv ("POD_NAMESPACE" , "test-namespace" )
47+ os .Setenv ("IMAGE_REGISTRY" , "test-registry" )
48+ os .Setenv ("IMAGE_REPOSITORY" , "test-repo" )
49+ os .Setenv ("APP_VERSION" , "v1.0.0" )
50+
51+ class := overcommit.OvercommitClass {
52+ ObjectMeta : metav1.ObjectMeta {
53+ Name : "test-class" ,
54+ },
55+ Spec : overcommit.OvercommitClassSpec {
56+ Labels : map [string ]string {"key" : "value" },
57+ Annotations : map [string ]string {"annotation-key" : "annotation-value" },
58+ Tolerations : []corev1.Toleration {
59+ {
60+ Key : "key1" ,
61+ Operator : corev1 .TolerationOpExists ,
62+ },
63+ },
64+ },
65+ }
66+
67+ deployment := CreateDeployment (class )
68+
69+ if deployment .ObjectMeta .Name != "test-class-overcommit-webhook" {
70+ t .Errorf ("Expected deployment name 'test-class-overcommit-webhook', got '%s'" , deployment .ObjectMeta .Name )
71+ }
72+
73+ if deployment .Spec .Replicas == nil || * deployment .Spec .Replicas != 1 {
74+ t .Errorf ("Expected replicas to be 1, got '%v'" , deployment .Spec .Replicas )
75+ }
76+
77+ if len (deployment .Spec .Template .Spec .Tolerations ) != 1 {
78+ t .Errorf ("Expected 1 toleration, got '%d'" , len (deployment .Spec .Template .Spec .Tolerations ))
79+ }
80+
81+ if deployment .Spec .Template .Spec .Tolerations [0 ].Key != "key1" {
82+ t .Errorf ("Expected toleration key 'key1', got '%s'" , deployment .Spec .Template .Spec .Tolerations [0 ].Key )
83+ }
84+ }
85+
4586func TestCreateService (t * testing.T ) {
4687 os .Setenv ("POD_NAMESPACE" , "test-namespace" )
4788
0 commit comments