...
1
16
17 package job
18
19 import (
20 "testing"
21
22 batch "k8s.io/api/batch/v1"
23 "k8s.io/api/core/v1"
24 )
25
26 func TestIsJobFinished(t *testing.T) {
27 testCases := map[string]struct {
28 conditionType batch.JobConditionType
29 conditionStatus v1.ConditionStatus
30 expectJobNotFinished bool
31 }{
32 "Job is completed and condition is true": {
33 batch.JobComplete,
34 v1.ConditionTrue,
35 false,
36 },
37 "Job is completed and condition is false": {
38 batch.JobComplete,
39 v1.ConditionFalse,
40 true,
41 },
42 "Job is completed and condition is unknown": {
43 batch.JobComplete,
44 v1.ConditionUnknown,
45 true,
46 },
47 "Job is failed and condition is true": {
48 batch.JobFailed,
49 v1.ConditionTrue,
50 false,
51 },
52 "Job is failed and condition is false": {
53 batch.JobFailed,
54 v1.ConditionFalse,
55 true,
56 },
57 "Job is failed and condition is unknown": {
58 batch.JobFailed,
59 v1.ConditionUnknown,
60 true,
61 },
62 }
63
64 for name, tc := range testCases {
65 job := &batch.Job{
66 Status: batch.JobStatus{
67 Conditions: []batch.JobCondition{{
68 Type: tc.conditionType,
69 Status: tc.conditionStatus,
70 }},
71 },
72 }
73
74 if tc.expectJobNotFinished == IsJobFinished(job) {
75 if tc.expectJobNotFinished {
76 t.Errorf("test name: %s, job was not expected to be finished", name)
77 } else {
78 t.Errorf("test name: %s, job was expected to be finished", name)
79 }
80 }
81 }
82 }
83
View as plain text