Skip to content

Commit e4c54e3

Browse files
committed
Added unit tests for Job BackOffLimitExceeded
Signed-off-by: Ilyes Ben Dlala <ilyes.bendlala@iteratec.com>
1 parent 589941f commit e4c54e3

1 file changed

Lines changed: 108 additions & 0 deletions

File tree

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// SPDX-FileCopyrightText: the secureCodeBox authors
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
package scancontrollers
6+
7+
import (
8+
. "github.com/onsi/ginkgo"
9+
. "github.com/onsi/gomega"
10+
batch "k8s.io/api/batch/v1"
11+
)
12+
13+
var _ = Describe("ScanControllers", func() {
14+
Context("checkIfAllJobsCompleted", func() {
15+
It("should return completed if all jobs succeeded", func() {
16+
jobs := &batch.JobList{
17+
Items: []batch.Job{
18+
{
19+
Status: batch.JobStatus{
20+
Succeeded: 1,
21+
},
22+
},
23+
{
24+
Status: batch.JobStatus{
25+
Succeeded: 1,
26+
},
27+
},
28+
},
29+
}
30+
Expect(checkIfAllJobsCompleted(jobs)).To(Equal(completed))
31+
})
32+
33+
It("should return incomplete if any job did not succeed", func() {
34+
jobs := &batch.JobList{
35+
Items: []batch.Job{
36+
{
37+
Status: batch.JobStatus{
38+
Succeeded: 1,
39+
},
40+
},
41+
{
42+
Status: batch.JobStatus{
43+
Succeeded: 0,
44+
},
45+
},
46+
},
47+
}
48+
Expect(checkIfAllJobsCompleted(jobs)).To(Equal(incomplete))
49+
})
50+
51+
It("should return failed if any job exceeded backoff limit", func() {
52+
jobs := &batch.JobList{
53+
Items: []batch.Job{
54+
{
55+
Status: batch.JobStatus{
56+
Failed: 1,
57+
Conditions: []batch.JobCondition{
58+
{
59+
Reason: "BackoffLimitExceeded",
60+
},
61+
},
62+
},
63+
},
64+
},
65+
}
66+
Expect(checkIfAllJobsCompleted(jobs)).To(Equal(failed))
67+
})
68+
})
69+
70+
Context("isBackoffLimitExceeded", func() {
71+
It("should return true if job exceeded backoff limit", func() {
72+
job := batch.Job{
73+
Status: batch.JobStatus{
74+
Failed: 1,
75+
Conditions: []batch.JobCondition{
76+
{
77+
Reason: "BackoffLimitExceeded",
78+
},
79+
},
80+
},
81+
}
82+
Expect(isBackoffLimitExceeded(job)).To(BeTrue())
83+
})
84+
85+
It("should return false if job did not exceed backoff limit", func() {
86+
job := batch.Job{
87+
Status: batch.JobStatus{
88+
Failed: 1,
89+
Conditions: []batch.JobCondition{
90+
{
91+
Reason: "SomeOtherReason",
92+
},
93+
},
94+
},
95+
}
96+
Expect(isBackoffLimitExceeded(job)).To(BeFalse())
97+
})
98+
99+
It("should return false if job did not fail", func() {
100+
job := batch.Job{
101+
Status: batch.JobStatus{
102+
Failed: 0,
103+
},
104+
}
105+
Expect(isBackoffLimitExceeded(job)).To(BeFalse())
106+
})
107+
})
108+
})

0 commit comments

Comments
 (0)