mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #49829 from zhangxiaoyu-zidif/add-test-item-for-job-util
Automatic merge from submit-queue (batch tested with PRs 51666, 49829, 51058, 51004, 50938) Add test items for job utils **What this PR does / why we need it**: Add test item for job util **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes # **Special notes for your reviewer**: NONE **Release note**: ```release-note NONE ```
This commit is contained in:
commit
6c60a73f8a
@ -24,26 +24,59 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestIsJobFinished(t *testing.T) {
|
func TestIsJobFinished(t *testing.T) {
|
||||||
job := &batch.Job{
|
testCases := map[string]struct {
|
||||||
Status: batch.JobStatus{
|
conditionType batch.JobConditionType
|
||||||
Conditions: []batch.JobCondition{{
|
conditionStatus v1.ConditionStatus
|
||||||
Type: batch.JobComplete,
|
expectJobNotFinished bool
|
||||||
Status: v1.ConditionTrue,
|
}{
|
||||||
}},
|
"Job is completed and condition is true": {
|
||||||
|
batch.JobComplete,
|
||||||
|
v1.ConditionTrue,
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
"Job is completed and condition is false": {
|
||||||
|
batch.JobComplete,
|
||||||
|
v1.ConditionFalse,
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
"Job is completed and condition is unknown": {
|
||||||
|
batch.JobComplete,
|
||||||
|
v1.ConditionUnknown,
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
"Job is failed and condition is true": {
|
||||||
|
batch.JobFailed,
|
||||||
|
v1.ConditionTrue,
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
"Job is failed and condition is false": {
|
||||||
|
batch.JobFailed,
|
||||||
|
v1.ConditionFalse,
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
"Job is failed and condition is unknown": {
|
||||||
|
batch.JobFailed,
|
||||||
|
v1.ConditionUnknown,
|
||||||
|
true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
if !IsJobFinished(job) {
|
for name, tc := range testCases {
|
||||||
t.Error("Job was expected to be finished")
|
job := &batch.Job{
|
||||||
}
|
Status: batch.JobStatus{
|
||||||
|
Conditions: []batch.JobCondition{{
|
||||||
|
Type: tc.conditionType,
|
||||||
|
Status: tc.conditionStatus,
|
||||||
|
}},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
job.Status.Conditions[0].Status = v1.ConditionFalse
|
if tc.expectJobNotFinished == IsJobFinished(job) {
|
||||||
if IsJobFinished(job) {
|
if tc.expectJobNotFinished {
|
||||||
t.Error("Job was not expected to be finished")
|
t.Errorf("test name: %s, job was not expected to be finished", name)
|
||||||
}
|
} else {
|
||||||
|
t.Errorf("test name: %s, job was expected to be finished", name)
|
||||||
job.Status.Conditions[0].Status = v1.ConditionUnknown
|
}
|
||||||
if IsJobFinished(job) {
|
}
|
||||||
t.Error("Job was not expected to be finished")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user