fix staticcheck in test/integration/apiserver

This commit is contained in:
tanjunchen 2019-12-06 23:05:20 +08:00
parent 3994f52ee6
commit 06c5901769
5 changed files with 15 additions and 18 deletions

View File

@ -81,8 +81,6 @@ test/images/agnhost/pause
test/images/agnhost/serve-hostname
test/images/agnhost/webhook
test/images/pets/peer-finder
test/integration/apiserver
test/integration/apiserver/admissionwebhook
test/integration/auth
test/integration/client
test/integration/deployment

View File

@ -596,7 +596,7 @@ func testWebhookAdmission(t *testing.T, watchCache bool) {
})
}
duration := time.Now().Sub(start)
duration := time.Since(start)
perResourceDuration := time.Duration(int(duration) / count)
if perResourceDuration >= 150*time.Millisecond {
t.Errorf("expected resources to process in < 150ms, average was %v", perResourceDuration)
@ -736,6 +736,10 @@ func testResourceDelete(c *testContext) {
}
return true, nil
})
if err != nil {
c.t.Error(err)
return
}
// remove the finalizer
_, err = c.client.Resource(c.gvr).Namespace(obj.GetNamespace()).Patch(
@ -1431,17 +1435,11 @@ var (
)
func shouldTestResource(gvr schema.GroupVersionResource, resource metav1.APIResource) bool {
if !sets.NewString(resource.Verbs...).HasAny("create", "update", "patch", "connect", "delete", "deletecollection") {
return false
}
return true
return sets.NewString(resource.Verbs...).HasAny("create", "update", "patch", "connect", "delete", "deletecollection")
}
func shouldTestResourceVerb(gvr schema.GroupVersionResource, resource metav1.APIResource, verb string) bool {
if !sets.NewString(resource.Verbs...).Has(verb) {
return false
}
return true
return sets.NewString(resource.Verbs...).Has(verb)
}
//

View File

@ -247,11 +247,11 @@ func newClientAuthWebhookHandler(t *testing.T, recorder *clientAuthRecorder) htt
defer r.Body.Close()
data, err := ioutil.ReadAll(r.Body)
if err != nil {
http.Error(w, err.Error(), 400)
http.Error(w, err.Error(), http.StatusBadRequest)
}
review := v1beta1.AdmissionReview{}
if err := json.Unmarshal(data, &review); err != nil {
http.Error(w, err.Error(), 400)
http.Error(w, err.Error(), http.StatusBadRequest)
}
if review.Request.UserInfo.Username != testClientAuthClientUsername {
// skip requests not originating from this integration test's client
@ -261,17 +261,17 @@ func newClientAuthWebhookHandler(t *testing.T, recorder *clientAuthRecorder) htt
if authz := r.Header.Get("Authorization"); authz != "Bearer localhost-match-with-port" {
t.Errorf("unexpected authz header: %q", authz)
http.Error(w, "Invalid auth", 401)
http.Error(w, "Invalid auth", http.StatusUnauthorized)
return
}
if len(review.Request.Object.Raw) == 0 {
http.Error(w, err.Error(), 400)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
pod := &corev1.Pod{}
if err := json.Unmarshal(review.Request.Object.Raw, pod); err != nil {
http.Error(w, err.Error(), 400)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}

View File

@ -428,6 +428,9 @@ func newTimeoutWebhookHandler(recorder *timeoutRecorder) http.Handler {
}
timeout, err := time.ParseDuration(r.URL.Query().Get("timeout"))
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
}
invocation := invocation{path: r.URL.Path, timeoutSeconds: int(timeout.Round(time.Second) / time.Second)}
recorder.RecordInvocation(invocation)

View File

@ -403,11 +403,9 @@ func TestNameInFieldSelector(t *testing.T) {
defer closeFn()
numNamespaces := 3
namespaces := make([]*v1.Namespace, 0, numNamespaces)
for i := 0; i < 3; i++ {
ns := framework.CreateTestingNamespace(fmt.Sprintf("ns%d", i), s, t)
defer framework.DeleteTestingNamespace(ns, s, t)
namespaces = append(namespaces, ns)
_, err := clientSet.CoreV1().Secrets(ns.Name).Create(makeSecret("foo"))
if err != nil {