Replace deprecated sets.Int with sets.Set[int] in Job integration tests

This commit is contained in:
Michal Wozniak 2023-06-19 13:55:23 +02:00
parent 26f7f8e980
commit 2596245f5a

View File

@ -998,7 +998,7 @@ func TestIndexedJob(t *testing.T) {
Active: 3, Active: 3,
Ready: pointer.Int32(0), Ready: pointer.Int32(0),
}) })
validateIndexedJobPods(ctx, t, clientSet, jobObj, sets.NewInt(0, 1, 2), "") validateIndexedJobPods(ctx, t, clientSet, jobObj, sets.New(0, 1, 2), "")
// One Pod succeeds. // One Pod succeeds.
if err := setJobPhaseForIndex(ctx, clientSet, jobObj, v1.PodSucceeded, 1); err != nil { if err := setJobPhaseForIndex(ctx, clientSet, jobObj, v1.PodSucceeded, 1); err != nil {
@ -1009,7 +1009,7 @@ func TestIndexedJob(t *testing.T) {
Succeeded: 1, Succeeded: 1,
Ready: pointer.Int32(0), Ready: pointer.Int32(0),
}) })
validateIndexedJobPods(ctx, t, clientSet, jobObj, sets.NewInt(0, 2, 3), "1") validateIndexedJobPods(ctx, t, clientSet, jobObj, sets.New(0, 2, 3), "1")
// One Pod fails, which should be recreated. // One Pod fails, which should be recreated.
if err := setJobPhaseForIndex(ctx, clientSet, jobObj, v1.PodFailed, 2); err != nil { if err := setJobPhaseForIndex(ctx, clientSet, jobObj, v1.PodFailed, 2); err != nil {
@ -1021,7 +1021,7 @@ func TestIndexedJob(t *testing.T) {
Succeeded: 1, Succeeded: 1,
Ready: pointer.Int32(0), Ready: pointer.Int32(0),
}) })
validateIndexedJobPods(ctx, t, clientSet, jobObj, sets.NewInt(0, 2, 3), "1") validateIndexedJobPods(ctx, t, clientSet, jobObj, sets.New(0, 2, 3), "1")
// Remaining Pods succeed. // Remaining Pods succeed.
if err, _ := setJobPodsPhase(ctx, clientSet, jobObj, v1.PodSucceeded, 3); err != nil { if err, _ := setJobPodsPhase(ctx, clientSet, jobObj, v1.PodSucceeded, 3); err != nil {
@ -1047,7 +1047,7 @@ func TestElasticIndexedJob(t *testing.T) {
failIndexes []int failIndexes []int
wantSucceededIndexes string wantSucceededIndexes string
wantFailed int wantFailed int
wantRemainingIndexes sets.Int wantRemainingIndexes sets.Set[int]
wantActivePods int wantActivePods int
} }
cases := map[string]struct { cases := map[string]struct {
@ -1087,7 +1087,7 @@ func TestElasticIndexedJob(t *testing.T) {
failIndexes: []int{2}, failIndexes: []int{2},
wantSucceededIndexes: "1", wantSucceededIndexes: "1",
wantFailed: 1, wantFailed: 1,
wantRemainingIndexes: sets.NewInt(0, 2), wantRemainingIndexes: sets.New(0, 2),
wantActivePods: 2, wantActivePods: 2,
}, },
// Scale down completions 3->1, verify prev failure out of range still counts // Scale down completions 3->1, verify prev failure out of range still counts
@ -1107,13 +1107,13 @@ func TestElasticIndexedJob(t *testing.T) {
{ {
succeedIndexes: []int{2}, succeedIndexes: []int{2},
wantSucceededIndexes: "2", wantSucceededIndexes: "2",
wantRemainingIndexes: sets.NewInt(0, 1), wantRemainingIndexes: sets.New(0, 1),
wantActivePods: 2, wantActivePods: 2,
}, },
// Scale completions down 3->2 to exclude previously succeeded index. // Scale completions down 3->2 to exclude previously succeeded index.
{ {
completions: pointer.Int32Ptr(2), completions: pointer.Int32Ptr(2),
wantRemainingIndexes: sets.NewInt(0, 1), wantRemainingIndexes: sets.New(0, 1),
wantActivePods: 2, wantActivePods: 2,
}, },
// Scale completions back up to include previously succeeded index that was temporarily out of range. // Scale completions back up to include previously succeeded index that was temporarily out of range.
@ -1815,7 +1815,7 @@ func validateFinishedPodsNoFinalizer(ctx context.Context, t *testing.T, clientSe
// validateIndexedJobPods validates indexes and hostname of // validateIndexedJobPods validates indexes and hostname of
// active and completed Pods of an Indexed Job. // active and completed Pods of an Indexed Job.
// Call after validateJobPodsStatus // Call after validateJobPodsStatus
func validateIndexedJobPods(ctx context.Context, t *testing.T, clientSet clientset.Interface, jobObj *batchv1.Job, wantActive sets.Int, gotCompleted string) { func validateIndexedJobPods(ctx context.Context, t *testing.T, clientSet clientset.Interface, jobObj *batchv1.Job, wantActive sets.Set[int], gotCompleted string) {
t.Helper() t.Helper()
updatedJob, err := clientSet.BatchV1().Jobs(jobObj.Namespace).Get(ctx, jobObj.Name, metav1.GetOptions{}) updatedJob, err := clientSet.BatchV1().Jobs(jobObj.Namespace).Get(ctx, jobObj.Name, metav1.GetOptions{})
if err != nil { if err != nil {
@ -1828,7 +1828,7 @@ func validateIndexedJobPods(ctx context.Context, t *testing.T, clientSet clients
if err != nil { if err != nil {
t.Fatalf("Failed to list Job Pods: %v", err) t.Fatalf("Failed to list Job Pods: %v", err)
} }
gotActive := sets.NewInt() gotActive := sets.New[int]()
for _, pod := range pods.Items { for _, pod := range pods.Items {
if metav1.IsControlledBy(&pod, jobObj) { if metav1.IsControlledBy(&pod, jobObj) {
if pod.Status.Phase == v1.PodPending || pod.Status.Phase == v1.PodRunning { if pod.Status.Phase == v1.PodPending || pod.Status.Phase == v1.PodRunning {
@ -1846,9 +1846,9 @@ func validateIndexedJobPods(ctx context.Context, t *testing.T, clientSet clients
} }
} }
if wantActive == nil { if wantActive == nil {
wantActive = sets.NewInt() wantActive = sets.New[int]()
} }
if diff := cmp.Diff(wantActive.List(), gotActive.List()); diff != "" { if diff := cmp.Diff(sets.List(wantActive), sets.List(gotActive)); diff != "" {
t.Errorf("Unexpected active indexes (-want,+got):\n%s", diff) t.Errorf("Unexpected active indexes (-want,+got):\n%s", diff)
} }
} }