Skip to content

Commit 06c5901

Browse files
committed
fix staticcheck in test/integration/apiserver
1 parent 3994f52 commit 06c5901

File tree

5 files changed

+15
-18
lines changed

5 files changed

+15
-18
lines changed

hack/.staticcheck_failures

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ test/images/agnhost/pause
8181
test/images/agnhost/serve-hostname
8282
test/images/agnhost/webhook
8383
test/images/pets/peer-finder
84-
test/integration/apiserver
85-
test/integration/apiserver/admissionwebhook
8684
test/integration/auth
8785
test/integration/client
8886
test/integration/deployment

test/integration/apiserver/admissionwebhook/admission_test.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ func testWebhookAdmission(t *testing.T, watchCache bool) {
596596
})
597597
}
598598

599-
duration := time.Now().Sub(start)
599+
duration := time.Since(start)
600600
perResourceDuration := time.Duration(int(duration) / count)
601601
if perResourceDuration >= 150*time.Millisecond {
602602
t.Errorf("expected resources to process in < 150ms, average was %v", perResourceDuration)
@@ -736,6 +736,10 @@ func testResourceDelete(c *testContext) {
736736
}
737737
return true, nil
738738
})
739+
if err != nil {
740+
c.t.Error(err)
741+
return
742+
}
739743

740744
// remove the finalizer
741745
_, err = c.client.Resource(c.gvr).Namespace(obj.GetNamespace()).Patch(
@@ -1431,17 +1435,11 @@ var (
14311435
)
14321436

14331437
func shouldTestResource(gvr schema.GroupVersionResource, resource metav1.APIResource) bool {
1434-
if !sets.NewString(resource.Verbs...).HasAny("create", "update", "patch", "connect", "delete", "deletecollection") {
1435-
return false
1436-
}
1437-
return true
1438+
return sets.NewString(resource.Verbs...).HasAny("create", "update", "patch", "connect", "delete", "deletecollection")
14381439
}
14391440

14401441
func shouldTestResourceVerb(gvr schema.GroupVersionResource, resource metav1.APIResource, verb string) bool {
1441-
if !sets.NewString(resource.Verbs...).Has(verb) {
1442-
return false
1443-
}
1444-
return true
1442+
return sets.NewString(resource.Verbs...).Has(verb)
14451443
}
14461444

14471445
//

test/integration/apiserver/admissionwebhook/client_auth_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,11 @@ func newClientAuthWebhookHandler(t *testing.T, recorder *clientAuthRecorder) htt
247247
defer r.Body.Close()
248248
data, err := ioutil.ReadAll(r.Body)
249249
if err != nil {
250-
http.Error(w, err.Error(), 400)
250+
http.Error(w, err.Error(), http.StatusBadRequest)
251251
}
252252
review := v1beta1.AdmissionReview{}
253253
if err := json.Unmarshal(data, &review); err != nil {
254-
http.Error(w, err.Error(), 400)
254+
http.Error(w, err.Error(), http.StatusBadRequest)
255255
}
256256
if review.Request.UserInfo.Username != testClientAuthClientUsername {
257257
// skip requests not originating from this integration test's client
@@ -261,17 +261,17 @@ func newClientAuthWebhookHandler(t *testing.T, recorder *clientAuthRecorder) htt
261261

262262
if authz := r.Header.Get("Authorization"); authz != "Bearer localhost-match-with-port" {
263263
t.Errorf("unexpected authz header: %q", authz)
264-
http.Error(w, "Invalid auth", 401)
264+
http.Error(w, "Invalid auth", http.StatusUnauthorized)
265265
return
266266
}
267267

268268
if len(review.Request.Object.Raw) == 0 {
269-
http.Error(w, err.Error(), 400)
269+
http.Error(w, err.Error(), http.StatusBadRequest)
270270
return
271271
}
272272
pod := &corev1.Pod{}
273273
if err := json.Unmarshal(review.Request.Object.Raw, pod); err != nil {
274-
http.Error(w, err.Error(), 400)
274+
http.Error(w, err.Error(), http.StatusBadRequest)
275275
return
276276
}
277277

test/integration/apiserver/admissionwebhook/timeout_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,9 @@ func newTimeoutWebhookHandler(recorder *timeoutRecorder) http.Handler {
428428
}
429429

430430
timeout, err := time.ParseDuration(r.URL.Query().Get("timeout"))
431+
if err != nil {
432+
http.Error(w, err.Error(), http.StatusBadRequest)
433+
}
431434
invocation := invocation{path: r.URL.Path, timeoutSeconds: int(timeout.Round(time.Second) / time.Second)}
432435
recorder.RecordInvocation(invocation)
433436

test/integration/apiserver/apiserver_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,9 @@ func TestNameInFieldSelector(t *testing.T) {
403403
defer closeFn()
404404

405405
numNamespaces := 3
406-
namespaces := make([]*v1.Namespace, 0, numNamespaces)
407406
for i := 0; i < 3; i++ {
408407
ns := framework.CreateTestingNamespace(fmt.Sprintf("ns%d", i), s, t)
409408
defer framework.DeleteTestingNamespace(ns, s, t)
410-
namespaces = append(namespaces, ns)
411409

412410
_, err := clientSet.CoreV1().Secrets(ns.Name).Create(makeSecret("foo"))
413411
if err != nil {

0 commit comments

Comments
 (0)