From 6f4519b156f31b1646b76b97218a523062a1fe24 Mon Sep 17 00:00:00 2001 From: bobz965 Date: Sun, 22 Sep 2024 11:17:43 +0800 Subject: [PATCH] fix lint Signed-off-by: bobz965 --- pkg/util/k8s_test.go | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/pkg/util/k8s_test.go b/pkg/util/k8s_test.go index 359fbe5adf9..11b25296354 100644 --- a/pkg/util/k8s_test.go +++ b/pkg/util/k8s_test.go @@ -256,7 +256,6 @@ func TestGetPodIPs(t *testing.T) { } }) } - } func TestServiceClusterIPs(t *testing.T) { @@ -340,14 +339,16 @@ func TestUpdateNodeLabels(t *testing.T) { } for _, tt := range tests { // create a node - client.CoreV1().Nodes().Create(context.Background(), &v1.Node{ + node, err := client.CoreV1().Nodes().Create(context.Background(), &v1.Node{ ObjectMeta: metav1.ObjectMeta{ Name: tt.node, }, }, metav1.CreateOptions{}) + require.NoError(t, err) + require.NotNil(t, node) t.Run(tt.name, func(t *testing.T) { err := UpdateNodeLabels(tt.cs, tt.node, tt.labels) - if err != tt.exp { + if errors.Is(err, tt.exp) { t.Errorf("got %v, want %v", err, tt.exp) } }) @@ -367,7 +368,7 @@ func TestUpdateNodeAnnotations(t *testing.T) { { name: "node_with_annotations", cs: nodeClient, - node: "node", + node: "node1", annotations: map[string]any{ "key1": "value1", }, @@ -376,21 +377,27 @@ func TestUpdateNodeAnnotations(t *testing.T) { { name: "node_with_nil_annotations", cs: nodeClient, - node: "node", + node: "node2", annotations: map[string]any{}, exp: nil, }, } for _, tt := range tests { // create a node - client.CoreV1().Nodes().Create(context.Background(), &v1.Node{ + node, err := client.CoreV1().Nodes().Create(context.Background(), &v1.Node{ ObjectMeta: metav1.ObjectMeta{ Name: tt.node, }, }, metav1.CreateOptions{}) + require.NoError(t, err) + require.NotNil(t, node) t.Run(tt.name, func(t *testing.T) { err := UpdateNodeAnnotations(tt.cs, tt.node, tt.annotations) - if err != tt.exp { + if tt.exp == nil { + require.NoError(t, err) + return + } + if errors.Is(err, tt.exp) { t.Errorf("got %v, want %v", err, tt.exp) } }) @@ -417,14 +424,20 @@ func TestNodeMergePatch(t *testing.T) { } for _, tt := range tests { // create a node - client.CoreV1().Nodes().Create(context.Background(), &v1.Node{ + node, err := client.CoreV1().Nodes().Create(context.Background(), &v1.Node{ ObjectMeta: metav1.ObjectMeta{ Name: tt.node, }, }, metav1.CreateOptions{}) + require.NoError(t, err) + require.NotNil(t, node) t.Run(tt.name, func(t *testing.T) { err := nodeMergePatch(tt.cs, tt.node, tt.patch) - if err != tt.exp { + if tt.exp == nil { + require.NoError(t, err) + return + } + if errors.Is(err, tt.exp) { t.Errorf("got %v, want %v", err, tt.exp) } })