From 75dcd8a51268ff1b8cdeb32d174b671d87e7b688 Mon Sep 17 00:00:00 2001 From: vimystic <122659254+vimystic@users.noreply.github.com> Date: Tue, 19 Nov 2024 22:25:16 -0700 Subject: [PATCH] Optimize tests --- internal/fullnode/build_pods.go | 4 ++-- internal/fullnode/build_pods_test.go | 8 +++----- internal/fullnode/pod_control.go | 2 +- internal/fullnode/pod_control_test.go | 8 ++++---- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/internal/fullnode/build_pods.go b/internal/fullnode/build_pods.go index d0a69a8f..9b10f1b5 100644 --- a/internal/fullnode/build_pods.go +++ b/internal/fullnode/build_pods.go @@ -12,13 +12,13 @@ const ( ) // BuildPods creates the final state of pods given the crd. -func BuildPods(crd *cosmosv1.CosmosFullNode, cksums ConfigChecksums, startingOrdinal int32) ([]diff.Resource[*corev1.Pod], error) { +func BuildPods(crd *cosmosv1.CosmosFullNode, cksums ConfigChecksums) ([]diff.Resource[*corev1.Pod], error) { var ( builder = NewPodBuilder(crd) pods []diff.Resource[*corev1.Pod] ) candidates := podCandidates(crd) - for i := startingOrdinal; i < crd.Spec.Replicas+startingOrdinal; i++ { + for i := crd.Spec.Ordinal.Start; i < crd.Spec.Ordinal.Start+crd.Spec.Replicas; i++ { pod, err := builder.WithOrdinal(i).Build() if err != nil { return nil, err diff --git a/internal/fullnode/build_pods_test.go b/internal/fullnode/build_pods_test.go index f69f1f32..6aad9886 100644 --- a/internal/fullnode/build_pods_test.go +++ b/internal/fullnode/build_pods_test.go @@ -39,7 +39,7 @@ func TestBuildPods(t *testing.T) { cksums[client.ObjectKey{Namespace: crd.Namespace, Name: fmt.Sprintf("agoric-%d", i+int(startingOrdinal))}] = strconv.Itoa(i + int(startingOrdinal)) } - pods, err := BuildPods(crd, cksums, startingOrdinal) + pods, err := BuildPods(crd, cksums) require.NoError(t, err) require.Equal(t, 5, len(pods)) @@ -84,8 +84,7 @@ func TestBuildPods(t *testing.T) { }, } - startingOrdinal := int32(2) - pods, err := BuildPods(crd, nil, startingOrdinal) + pods, err := BuildPods(crd, nil) require.NoError(t, err) require.Equal(t, 4, len(pods)) @@ -121,8 +120,7 @@ func TestBuildPods(t *testing.T) { }, } - startingOrdinal := int32(2) - pods, err := BuildPods(crd, nil, startingOrdinal) + pods, err := BuildPods(crd, nil) require.NoError(t, err) require.Equal(t, 4, len(pods)) diff --git a/internal/fullnode/pod_control.go b/internal/fullnode/pod_control.go index 2a3abb2a..9fab0795 100644 --- a/internal/fullnode/pod_control.go +++ b/internal/fullnode/pod_control.go @@ -61,7 +61,7 @@ func (pc PodControl) Reconcile( return false, kube.TransientError(fmt.Errorf("list existing pods: %w", err)) } - wantPods, err := BuildPods(crd, cksums, startingOrdinal) + wantPods, err := BuildPods(crd, cksums) if err != nil { return false, kube.UnrecoverableError(fmt.Errorf("build pods: %w", err)) } diff --git a/internal/fullnode/pod_control_test.go b/internal/fullnode/pod_control_test.go index 438d2bc4..f8c40f0a 100644 --- a/internal/fullnode/pod_control_test.go +++ b/internal/fullnode/pod_control_test.go @@ -69,7 +69,7 @@ func TestPodControl_Reconcile(t *testing.T) { crd.Namespace = namespace crd.Spec.Replicas = 1 - pods, err := BuildPods(&crd, nil, 0) + pods, err := BuildPods(&crd, nil) require.NoError(t, err) existing := diff.New(nil, pods).Creates() @@ -130,7 +130,7 @@ func TestPodControl_Reconcile(t *testing.T) { MaxUnavailable: ptr(intstr.FromInt(2)), } - pods, err := BuildPods(&crd, nil, 0) + pods, err := BuildPods(&crd, nil) require.NoError(t, err) mClient := newMockPodClient(diff.New(nil, pods).Creates()) @@ -222,7 +222,7 @@ func TestPodControl_Reconcile(t *testing.T) { } crd.Status.Height = make(map[string]uint64) - pods, err := BuildPods(&crd, nil, 0) + pods, err := BuildPods(&crd, nil) require.NoError(t, err) existing := diff.New(nil, pods).Creates() @@ -415,7 +415,7 @@ func TestPodControl_Reconcile(t *testing.T) { } crd.Status.Height = make(map[string]uint64) - pods, err := BuildPods(&crd, nil, 0) + pods, err := BuildPods(&crd, nil) require.NoError(t, err) existing := diff.New(nil, pods).Creates()