generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34c0593
commit 22a408b
Showing
3 changed files
with
124 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package controllers | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
jobset "sigs.k8s.io/jobset/api/jobset/v1alpha2" | ||
) | ||
|
||
func TestIsDependsOnJobReachedStatus(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
dependsOnJob jobset.DependsOn | ||
dependsOnJobReplicas int32 | ||
rJobsStatuses []jobset.ReplicatedJobStatus | ||
expected bool | ||
}{ | ||
{ | ||
name: "status for ReplicatedJob is nil", | ||
dependsOnJob: jobset.DependsOn{ | ||
Name: "initializer", Status: jobset.CompleteStatus, | ||
}, | ||
dependsOnJobReplicas: 1, | ||
rJobsStatuses: []jobset.ReplicatedJobStatus{ | ||
{ | ||
Name: "invalid", | ||
Ready: 0, | ||
Succeeded: 1, | ||
Failed: 0, | ||
Suspended: 0, | ||
Active: 0, | ||
}, | ||
}, | ||
expected: false, | ||
}, | ||
{ | ||
name: "depends on ReplicatedJob reaches complete status", | ||
dependsOnJob: jobset.DependsOn{ | ||
Name: "initializer", Status: jobset.CompleteStatus, | ||
}, | ||
dependsOnJobReplicas: 2, | ||
rJobsStatuses: []jobset.ReplicatedJobStatus{ | ||
{ | ||
Name: "initializer", | ||
Ready: 0, | ||
Succeeded: 2, | ||
Failed: 0, | ||
Suspended: 0, | ||
Active: 0, | ||
}, | ||
}, | ||
expected: true, | ||
}, | ||
{ | ||
name: "depends on ReplicatedJob doesn't reach complete status", | ||
dependsOnJob: jobset.DependsOn{ | ||
Name: "initializer", Status: jobset.CompleteStatus, | ||
}, | ||
dependsOnJobReplicas: 2, | ||
rJobsStatuses: []jobset.ReplicatedJobStatus{ | ||
{ | ||
Name: "initializer", | ||
Ready: 1, | ||
Succeeded: 1, | ||
Failed: 0, | ||
Suspended: 0, | ||
Active: 0, | ||
}, | ||
}, | ||
expected: false, | ||
}, | ||
{ | ||
name: "depends on ReplicatedJob reaches ready status", | ||
dependsOnJob: jobset.DependsOn{ | ||
Name: "initializer", Status: jobset.ReadyStatus, | ||
}, | ||
dependsOnJobReplicas: 3, | ||
rJobsStatuses: []jobset.ReplicatedJobStatus{ | ||
{ | ||
Name: "initializer", | ||
Ready: 1, | ||
Succeeded: 1, | ||
Failed: 1, | ||
Suspended: 0, | ||
Active: 0, | ||
}, | ||
}, | ||
expected: true, | ||
}, | ||
{ | ||
name: "depends on ReplicatedJob doesn't reach ready status", | ||
dependsOnJob: jobset.DependsOn{ | ||
Name: "initializer", Status: jobset.ReadyStatus, | ||
}, | ||
dependsOnJobReplicas: 3, | ||
rJobsStatuses: []jobset.ReplicatedJobStatus{ | ||
{ | ||
Name: "initializer", | ||
Ready: 2, | ||
Succeeded: 0, | ||
Failed: 0, | ||
Suspended: 0, | ||
Active: 1, | ||
}, | ||
}, | ||
expected: false, | ||
}, | ||
} | ||
for _, tc := range tests { | ||
t.Run(tc.name, func(t *testing.T) { | ||
actual := isDependsOnJobReachedStatus(tc.dependsOnJob, tc.dependsOnJobReplicas, tc.rJobsStatuses) | ||
if diff := cmp.Diff(tc.expected, actual); diff != "" { | ||
t.Errorf("unexpected finished value (+got/-want): %s", diff) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters