1
1
package pod
2
2
3
3
import (
4
+ "context"
4
5
"testing"
5
6
"time"
6
7
@@ -10,76 +11,86 @@ import (
10
11
"k8s.io/apimachinery/pkg/runtime"
11
12
)
12
13
13
- func TestWaitForAllPodsInNamespacesHealthy (t * testing.T ) {
14
+ func TestPodWaitForAllPodsInNamespacesHealthy (t * testing.T ) {
15
+ generateTestPod := func (namespace string , conditionType corev1.PodConditionType ) * corev1.Pod {
16
+ pod := buildDummyPodWithPhaseAndCondition (corev1 .PodRunning , conditionType , false )
17
+ pod .Namespace = namespace
18
+
19
+ return pod
20
+ }
21
+
14
22
testCases := []struct {
15
23
namespaces []string
16
24
includeSucceeded bool
17
25
skipRedinessCheck bool
18
26
ignoreRestartPolicyNever bool
19
27
ignoreNamespaces []string
20
- expectedErrMsg string
28
+ pods []runtime.Object
29
+ expectedError error
21
30
}{
22
31
{
23
32
namespaces : []string {"ns1" },
24
33
includeSucceeded : true ,
25
34
skipRedinessCheck : true ,
26
35
ignoreRestartPolicyNever : true ,
27
36
ignoreNamespaces : []string {},
28
- expectedErrMsg : "" ,
37
+ pods : []runtime.Object {
38
+ generateTestPod ("ns1" , corev1 .PodReady ), generateTestPod ("ns2" , corev1 .PodInitialized )},
39
+ expectedError : nil ,
29
40
},
30
41
{
31
42
namespaces : []string {"ns1" },
32
43
includeSucceeded : true ,
33
44
skipRedinessCheck : false ,
34
45
ignoreRestartPolicyNever : true ,
35
46
ignoreNamespaces : []string {},
36
- expectedErrMsg : "" ,
47
+ pods : []runtime.Object {generateTestPod ("ns1" , corev1 .PodReady )},
48
+ expectedError : nil ,
37
49
},
38
50
{
39
51
namespaces : []string {"ns2" },
40
52
includeSucceeded : true ,
41
53
skipRedinessCheck : false ,
42
54
ignoreRestartPolicyNever : true ,
43
55
ignoreNamespaces : []string {},
44
- expectedErrMsg : "context deadline exceeded" ,
56
+ pods : []runtime.Object {generateTestPod ("ns2" , corev1 .PodInitialized )},
57
+ expectedError : context .DeadlineExceeded ,
45
58
},
46
59
{
47
60
namespaces : []string {},
48
61
includeSucceeded : true ,
49
62
skipRedinessCheck : false ,
50
63
ignoreRestartPolicyNever : true ,
51
64
ignoreNamespaces : []string {},
52
- expectedErrMsg : "context deadline exceeded" ,
65
+ pods : []runtime.Object {
66
+ generateTestPod ("ns1" , corev1 .PodReady ), generateTestPod ("ns2" , corev1 .PodInitialized )},
67
+ expectedError : context .DeadlineExceeded ,
53
68
},
54
69
{
55
70
namespaces : []string {},
56
71
includeSucceeded : true ,
57
72
skipRedinessCheck : false ,
58
73
ignoreRestartPolicyNever : true ,
59
74
ignoreNamespaces : []string {"ns2" },
60
- expectedErrMsg : "" ,
75
+ pods : []runtime.Object {generateTestPod ("ns1" , corev1 .PodReady )},
76
+ expectedError : nil ,
61
77
},
62
78
}
63
79
64
- var runtimeObjects []runtime.Object
65
- runtimeObjects = append (runtimeObjects , generateTestPod ("test1" , "ns1" , corev1 .PodRunning , corev1 .PodReady , false ))
66
- runtimeObjects = append (runtimeObjects , generateTestPod ("test2" , "ns1" , corev1 .PodRunning , corev1 .PodReady , false ))
67
- runtimeObjects = append (runtimeObjects , generateTestPod ("test3" , "ns1" , corev1 .PodRunning , corev1 .PodReady , false ))
68
- runtimeObjects = append (runtimeObjects , generateTestPod ("test4" , "ns1" , corev1 .PodRunning , corev1 .PodReady , false ))
69
- runtimeObjects = append (runtimeObjects , generateTestPod ("test5" , "ns1" , corev1 .PodRunning , corev1 .PodReady , false ))
70
- runtimeObjects = append (runtimeObjects , generateTestPod ("test1" , "ns2" , corev1 .PodRunning , corev1 .PodReady , false ))
71
- runtimeObjects = append (runtimeObjects , generateTestPod ("test2" , "ns2" , corev1 .PodRunning , corev1 .PodInitialized ,
72
- false ))
73
-
74
- testSettings := clients .GetTestClients (clients.TestClientParams {
75
- K8sMockObjects : runtimeObjects ,
76
- })
77
-
78
80
for _ , testCase := range testCases {
79
- err := WaitForAllPodsInNamespacesHealthy (testSettings , testCase .namespaces , 2 * time .Second , testCase .includeSucceeded ,
81
+ testSettings := clients .GetTestClients (clients.TestClientParams {
82
+ K8sMockObjects : testCase .pods ,
83
+ })
84
+
85
+ err := WaitForAllPodsInNamespacesHealthy (
86
+ testSettings ,
87
+ testCase .namespaces ,
88
+ time .Second ,
89
+ testCase .includeSucceeded ,
80
90
testCase .skipRedinessCheck ,
81
- testCase .ignoreRestartPolicyNever , testCase .ignoreNamespaces )
91
+ testCase .ignoreRestartPolicyNever ,
92
+ testCase .ignoreNamespaces )
82
93
83
- assert .Equal (t , testCase .expectedErrMsg , getErrorString ( err ) )
94
+ assert .Equal (t , testCase .expectedError , err )
84
95
}
85
96
}
0 commit comments