Skip to content

Commit 06d81cf

Browse files
authored
Merge pull request kubernetes#130359 from my-git9/assertion1
fix wrong assertion on tests
2 parents 6511ba7 + d92c70b commit 06d81cf

File tree

19 files changed

+177
-63
lines changed

19 files changed

+177
-63
lines changed

hack/golangci.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,5 +277,4 @@ linters-settings: # please keep this alphabetized
277277
enable-all: true
278278
disable: # TODO: remove each disabled rule and fix it
279279
- float-compare
280-
- go-require
281280
- require-error

hack/golangci.yaml.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ linters-settings: # please keep this alphabetized
242242
disable: # TODO: remove each disabled rule and fix it
243243
{{- if .Base }}
244244
- float-compare
245-
- go-require
246245
{{- end}}
247246
- require-error
248247
{{- end}}

pkg/client/tests/remotecommand_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ import (
2929
"testing"
3030
"time"
3131

32-
"github.com/stretchr/testify/require"
33-
3432
"k8s.io/apimachinery/pkg/runtime"
3533
"k8s.io/apimachinery/pkg/runtime/schema"
3634
"k8s.io/apimachinery/pkg/types"
@@ -124,7 +122,9 @@ func fakeServer(t *testing.T, requestReceived chan struct{}, testName string, ex
124122
}
125123

126124
opts, err := remotecommand.NewOptions(req)
127-
require.NoError(t, err)
125+
if err != nil {
126+
t.Errorf("unexpected error %v", err)
127+
}
128128
if exec {
129129
cmd := req.URL.Query()[api.ExecCommandParam]
130130
remotecommand.ServeExec(w, req, executor, "pod", "uid", "container", cmd, opts, 0, 10*time.Second, serverProtocols)

pkg/kubelet/logs/container_log_manager_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ func TestRotateLogs(t *testing.T) {
172172
err = wait.PollUntilContextCancel(pollTimeoutCtx, 5*time.Millisecond, false, func(ctx context.Context) (done bool, err error) {
173173
return c.queue.Len() == 0, nil
174174
})
175-
require.NoError(t, err)
175+
if err != nil {
176+
t.Errorf("unexpected error %v", err)
177+
}
176178
c.queue.ShutDown()
177179
}()
178180
// This is a blocking call. But the above routine takes care of ensuring that this is terminated once the queue is shutdown

staging/src/k8s.io/apiserver/pkg/admission/audit_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,13 @@ func TestWithAuditConcurrency(t *testing.T) {
200200
go func() {
201201
defer wg.Done()
202202
mutator, ok := handler.(MutationInterface)
203-
require.True(t, ok)
203+
if !ok {
204+
t.Error("handler is not an interface of type MutationInterface")
205+
}
204206
auditMutator, ok := auditHandler.(MutationInterface)
205-
require.True(t, ok)
207+
if !ok {
208+
t.Error("handler is not an interface of type MutationInterface")
209+
}
206210
assert.Equal(t, mutator.Admit(ctx, a, nil), auditMutator.Admit(ctx, a, nil), "WithAudit decorator should not effect the return value")
207211
}()
208212
}

staging/src/k8s.io/apiserver/pkg/admission/plugin/policy/internal/generic/controller_test.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ func TestReconcile(t *testing.T) {
199199
go func() {
200200
defer wg.Done()
201201
stopReason := myController.Run(testContext)
202-
require.ErrorIs(t, stopReason, context.Canceled)
202+
if !errors.Is(stopReason, context.Canceled) {
203+
t.Errorf("expected error to be context.Canceled, but got: %v", stopReason)
204+
}
203205
}()
204206

205207
// The controller is blocked because the reconcile function sends on an
@@ -255,7 +257,9 @@ func TestShutdown(t *testing.T) {
255257
go func() {
256258
defer wg.Done()
257259
stopReason := myController.Run(testContext)
258-
require.ErrorIs(t, stopReason, context.Canceled)
260+
if !errors.Is(stopReason, context.Canceled) {
261+
t.Errorf("expected error to be context.Canceled, but got: %v", stopReason)
262+
}
259263
}()
260264

261265
// Wait for controller and informer to start up
@@ -287,7 +291,9 @@ func TestInformerNeverStarts(t *testing.T) {
287291
go func() {
288292
defer wg.Done()
289293
stopReason := myController.Run(testContext)
290-
require.ErrorIs(t, stopReason, context.DeadlineExceeded)
294+
if !errors.Is(stopReason, context.DeadlineExceeded) {
295+
t.Errorf("expected error to be context.Canceled, but got: %v", stopReason)
296+
}
291297
}()
292298

293299
// Wait for deadline to pass without syncing the cache
@@ -335,7 +341,9 @@ func TestIgnoredUpdate(t *testing.T) {
335341
go func() {
336342
defer wg.Done()
337343
stopReason := myController.Run(testContext)
338-
require.ErrorIs(t, stopReason, context.Canceled)
344+
if !errors.Is(stopReason, context.Canceled) {
345+
t.Errorf("expected error to be context.Canceled, but got: %v", stopReason)
346+
}
339347
}()
340348

341349
// The controller is blocked because the reconcile function sends on an
@@ -392,7 +400,9 @@ func TestReconcileRetry(t *testing.T) {
392400
go func() {
393401
defer wg.Done()
394402
stopReason := myController.Run(testContext)
395-
require.ErrorIs(t, stopReason, context.Canceled)
403+
if !errors.Is(stopReason, context.Canceled) {
404+
t.Errorf("expected error to be context.Canceled, but got: %v", stopReason)
405+
}
396406
}()
397407

398408
// Add object to informer

staging/src/k8s.io/apiserver/pkg/storage/cacher/cacher_whitebox_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2197,7 +2197,9 @@ func TestWaitUntilWatchCacheFreshAndForceAllEvents(t *testing.T) {
21972197

21982198
go func(t *testing.T) {
21992199
err := cacher.watchCache.Add(makeTestPodDetails("pod1", 105, "node1", map[string]string{"label": "value1"}))
2200-
require.NoError(t, err, "failed adding a pod to the watchCache")
2200+
if err != nil {
2201+
t.Errorf("failed adding a pod to the watchCache %v", err)
2202+
}
22012203
}(t)
22022204
w, err = cacher.Watch(context.Background(), "pods/ns", scenario.opts)
22032205
require.NoError(t, err, "failed to create watch: %v")

staging/src/k8s.io/apiserver/pkg/util/proxy/streamtunnel_test.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,14 @@ func TestTunnelingHandler_UpgradeStreamingAndTunneling(t *testing.T) {
5757
defer close(stopServerChan)
5858
spdyServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
5959
_, err := httpstream.Handshake(req, w, []string{constants.PortForwardV1Name})
60-
require.NoError(t, err)
60+
if err != nil {
61+
t.Errorf("unexpected error %v", err)
62+
}
6163
upgrader := spdy.NewResponseUpgrader()
6264
conn := upgrader.UpgradeResponse(w, req, justQueueStream(streamChan))
63-
require.NotNil(t, conn)
65+
if conn == nil {
66+
t.Error("connect is unexpected nil")
67+
}
6468
defer conn.Close() //nolint:errcheck
6569
<-stopServerChan
6670
}))
@@ -97,9 +101,13 @@ func TestTunnelingHandler_UpgradeStreamingAndTunneling(t *testing.T) {
97101
var actual []byte
98102
go func() {
99103
clientStream, err := spdyClient.CreateStream(http.Header{})
100-
require.NoError(t, err)
104+
if err != nil {
105+
t.Errorf("unexpected error %v", err)
106+
}
101107
_, err = io.Copy(clientStream, bytes.NewReader(randomData))
102-
require.NoError(t, err)
108+
if err != nil {
109+
t.Errorf("unexpected error %v", err)
110+
}
103111
clientStream.Close() //nolint:errcheck
104112
}()
105113
select {
@@ -169,7 +177,9 @@ func TestTunnelingHandler_BadHandshakeError(t *testing.T) {
169177
spdyServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
170178
// Handshake fails.
171179
_, err := httpstream.Handshake(req, w, []string{constants.PortForwardV1Name})
172-
require.Error(t, err, "handshake should have returned an error")
180+
if err == nil {
181+
t.Errorf("handshake should have returned an error %v", err)
182+
}
173183
assert.ErrorContains(t, err, "unable to negotiate protocol")
174184
w.WriteHeader(http.StatusForbidden)
175185
}))
@@ -223,7 +233,9 @@ func TestTunnelingHandler_UpstreamSPDYServerErrorPropagated(t *testing.T) {
223233
// Create fake upstream SPDY server, which returns a 500-level error.
224234
spdyServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
225235
_, err := httpstream.Handshake(req, w, []string{constants.PortForwardV1Name})
226-
require.NoError(t, err, "handshake should have succeeded")
236+
if err != nil {
237+
t.Errorf("handshake should have succeeded %v", err)
238+
}
227239
// Returned status code should be incremented in metrics.
228240
w.WriteHeader(statusCode)
229241
}))

staging/src/k8s.io/client-go/discovery/cached/disk/cached_discovery_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,9 @@ func TestCachedDiscoveryClientUnaggregatedServerGroups(t *testing.T) {
350350
return
351351
}
352352
output, err := json.Marshal(body)
353-
require.NoError(t, err)
353+
if err != nil {
354+
t.Errorf("unexpected error %v", err)
355+
}
354356
// Content-type is "unaggregated" discovery format -- no resources returned.
355357
w.Header().Set("Content-Type", discovery.AcceptV1)
356358
w.WriteHeader(http.StatusOK)

staging/src/k8s.io/client-go/discovery/cached/memory/memcache_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,9 @@ func TestMemCacheGroupsAndMaybeResources(t *testing.T) {
587587
return
588588
}
589589
output, err := json.Marshal(body)
590-
require.NoError(t, err)
590+
if err != nil {
591+
t.Errorf("unexpected error %v", err)
592+
}
591593
// Content-type is "unaggregated" discovery format -- no resources returned.
592594
w.Header().Set("Content-Type", discovery.AcceptV1)
593595
w.WriteHeader(http.StatusOK)
@@ -1116,7 +1118,9 @@ func TestAggregatedMemCacheGroupsAndMaybeResources(t *testing.T) {
11161118
return
11171119
}
11181120
output, err := json.Marshal(agg)
1119-
require.NoError(t, err)
1121+
if err != nil {
1122+
t.Errorf("unexpected error %v", err)
1123+
}
11201124
// Content-type is "aggregated" discovery format.
11211125
w.Header().Set("Content-Type", discovery.AcceptV2)
11221126
w.WriteHeader(http.StatusOK)
@@ -1414,7 +1418,9 @@ func TestMemCacheAggregatedServerGroups(t *testing.T) {
14141418
return
14151419
}
14161420
output, err := json.Marshal(agg)
1417-
require.NoError(t, err)
1421+
if err != nil {
1422+
t.Errorf("unexpected error %v", err)
1423+
}
14181424
// Content-type is "aggregated" discovery format.
14191425
w.Header().Set("Content-Type", discovery.AcceptV2Beta1)
14201426
w.WriteHeader(http.StatusOK)

0 commit comments

Comments
 (0)