From 11c9c6cda090e344cc35489a8628b83c8b564e05 Mon Sep 17 00:00:00 2001 From: guangwu Date: Fri, 19 Jan 2024 08:20:04 +0800 Subject: [PATCH] chore: pkg import only once (#1175) Signed-off-by: guoguangwu Co-authored-by: Heba <31887807+helayoty@users.noreply.github.com> --- internal/test/e2e/framework/pod.go | 5 ++--- node/node_test.go | 33 +++++++++++++++--------------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/internal/test/e2e/framework/pod.go b/internal/test/e2e/framework/pod.go index 0d2e46ed7..da9a6fb47 100644 --- a/internal/test/e2e/framework/pod.go +++ b/internal/test/e2e/framework/pod.go @@ -6,7 +6,6 @@ import ( "strings" corev1 "k8s.io/api/core/v1" - v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/fields" "k8s.io/apimachinery/pkg/runtime" @@ -106,9 +105,9 @@ func (f *Framework) WaitUntilPodReady(namespace, name string) (*corev1.Pod, erro } // IsPodReady returns true if a pod is ready. -func IsPodReady(pod *v1.Pod) bool { +func IsPodReady(pod *corev1.Pod) bool { for _, cond := range pod.Status.Conditions { - if cond.Type == v1.PodReady && cond.Status == v1.ConditionTrue { + if cond.Type == corev1.PodReady && cond.Status == corev1.ConditionTrue { return true } } diff --git a/node/node_test.go b/node/node_test.go index 922626e33..ff26de5b8 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -25,7 +25,6 @@ import ( "gotest.tools/assert" "gotest.tools/assert/cmp" - is "gotest.tools/assert/cmp" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -394,8 +393,8 @@ func TestBeforeAnnotationsPreserved(t *testing.T) { newNode, err := nodes.Get(ctx, testNodeCopy.Name, emptyGetOptions) assert.NilError(t, err) - assert.Assert(t, is.Contains(newNode.Annotations, "testAnnotation")) - assert.Assert(t, is.Contains(newNode.Annotations, "beforeAnnotation")) + assert.Assert(t, cmp.Contains(newNode.Annotations, "testAnnotation")) + assert.Assert(t, cmp.Contains(newNode.Annotations, "beforeAnnotation")) } // Are conditions set by systems outside of VK preserved? @@ -444,7 +443,7 @@ func TestManualConditionsPreserved(t *testing.T) { newNode, err := nodes.Get(ctx, testNodeCopy.Name, emptyGetOptions) assert.NilError(t, err) - assert.Assert(t, is.Len(newNode.Status.Conditions, 0)) + assert.Assert(t, cmp.Len(newNode.Status.Conditions, 0)) baseCondition := corev1.NodeCondition{ Type: "BaseCondition", @@ -479,8 +478,8 @@ func TestManualConditionsPreserved(t *testing.T) { newNode, err = nodes.Get(ctx, testNodeCopy.Name, emptyGetOptions) assert.NilError(t, err) - assert.Assert(t, is.Len(newNode.Status.Conditions, 1)) - assert.Assert(t, is.Contains(newNode.Annotations, "testAnnotation")) + assert.Assert(t, cmp.Len(newNode.Status.Conditions, 1)) + assert.Assert(t, cmp.Contains(newNode.Annotations, "testAnnotation")) // Add a new event manually manuallyAddedCondition := corev1.NodeCondition{ @@ -507,8 +506,8 @@ func TestManualConditionsPreserved(t *testing.T) { return true } } - assert.Assert(t, is.Contains(receivedNode.Annotations, "testAnnotation")) - assert.Assert(t, is.Contains(newNode.Annotations, "manuallyAddedAnnotation")) + assert.Assert(t, cmp.Contains(receivedNode.Annotations, "testAnnotation")) + assert.Assert(t, cmp.Contains(newNode.Annotations, "manuallyAddedAnnotation")) return false })) @@ -553,11 +552,11 @@ func TestManualConditionsPreserved(t *testing.T) { for idx := range newNode.Status.Conditions { seenConditionTypes[idx] = newNode.Status.Conditions[idx].Type } - assert.Assert(t, is.Contains(seenConditionTypes, baseCondition.Type)) - assert.Assert(t, is.Contains(seenConditionTypes, newCondition.Type)) - assert.Assert(t, is.Contains(seenConditionTypes, manuallyAddedCondition.Type)) - assert.Assert(t, is.Equal(newNode.Annotations["testAnnotation"], "")) - assert.Assert(t, is.Contains(newNode.Annotations, "manuallyAddedAnnotation")) + assert.Assert(t, cmp.Contains(seenConditionTypes, baseCondition.Type)) + assert.Assert(t, cmp.Contains(seenConditionTypes, newCondition.Type)) + assert.Assert(t, cmp.Contains(seenConditionTypes, manuallyAddedCondition.Type)) + assert.Assert(t, cmp.Equal(newNode.Annotations["testAnnotation"], "")) + assert.Assert(t, cmp.Contains(newNode.Annotations, "manuallyAddedAnnotation")) t.Log(newNode.Status.Conditions) } @@ -607,15 +606,15 @@ func TestNodePingSingleInflight(t *testing.T) { assert.Assert(t, timeTakenToCompleteFirstPing < pingTimeout*5, "Time taken to complete first ping: %v", timeTakenToCompleteFirstPing) assert.Assert(t, cmp.Error(firstPing.error, context.DeadlineExceeded.Error())) - assert.Assert(t, is.Equal(1, calls.read())) - assert.Assert(t, is.Equal(0, finished.read())) + assert.Assert(t, cmp.Equal(1, calls.read())) + assert.Assert(t, cmp.Equal(0, finished.read())) // Wait until the first sleep finishes (the test context is done) assert.NilError(t, finished.until(testCtx, func(i int) bool { return i > 0 })) // Assert we didn't stack up goroutines, and that the one goroutine in flight finishd - assert.Assert(t, is.Equal(1, calls.read())) - assert.Assert(t, is.Equal(1, finished.read())) + assert.Assert(t, cmp.Equal(1, calls.read())) + assert.Assert(t, cmp.Equal(1, finished.read())) }