mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
fix staticcheck in test/integration/apiserver
This commit is contained in:
parent
3994f52ee6
commit
06c5901769
@ -81,8 +81,6 @@ test/images/agnhost/pause
|
|||||||
test/images/agnhost/serve-hostname
|
test/images/agnhost/serve-hostname
|
||||||
test/images/agnhost/webhook
|
test/images/agnhost/webhook
|
||||||
test/images/pets/peer-finder
|
test/images/pets/peer-finder
|
||||||
test/integration/apiserver
|
|
||||||
test/integration/apiserver/admissionwebhook
|
|
||||||
test/integration/auth
|
test/integration/auth
|
||||||
test/integration/client
|
test/integration/client
|
||||||
test/integration/deployment
|
test/integration/deployment
|
||||||
|
@ -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)
|
perResourceDuration := time.Duration(int(duration) / count)
|
||||||
if perResourceDuration >= 150*time.Millisecond {
|
if perResourceDuration >= 150*time.Millisecond {
|
||||||
t.Errorf("expected resources to process in < 150ms, average was %v", perResourceDuration)
|
t.Errorf("expected resources to process in < 150ms, average was %v", perResourceDuration)
|
||||||
@ -736,6 +736,10 @@ func testResourceDelete(c *testContext) {
|
|||||||
}
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
})
|
})
|
||||||
|
if err != nil {
|
||||||
|
c.t.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// remove the finalizer
|
// remove the finalizer
|
||||||
_, err = c.client.Resource(c.gvr).Namespace(obj.GetNamespace()).Patch(
|
_, err = c.client.Resource(c.gvr).Namespace(obj.GetNamespace()).Patch(
|
||||||
@ -1431,17 +1435,11 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func shouldTestResource(gvr schema.GroupVersionResource, resource metav1.APIResource) bool {
|
func shouldTestResource(gvr schema.GroupVersionResource, resource metav1.APIResource) bool {
|
||||||
if !sets.NewString(resource.Verbs...).HasAny("create", "update", "patch", "connect", "delete", "deletecollection") {
|
return sets.NewString(resource.Verbs...).HasAny("create", "update", "patch", "connect", "delete", "deletecollection")
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func shouldTestResourceVerb(gvr schema.GroupVersionResource, resource metav1.APIResource, verb string) bool {
|
func shouldTestResourceVerb(gvr schema.GroupVersionResource, resource metav1.APIResource, verb string) bool {
|
||||||
if !sets.NewString(resource.Verbs...).Has(verb) {
|
return sets.NewString(resource.Verbs...).Has(verb)
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -247,11 +247,11 @@ func newClientAuthWebhookHandler(t *testing.T, recorder *clientAuthRecorder) htt
|
|||||||
defer r.Body.Close()
|
defer r.Body.Close()
|
||||||
data, err := ioutil.ReadAll(r.Body)
|
data, err := ioutil.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, err.Error(), 400)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
review := v1beta1.AdmissionReview{}
|
review := v1beta1.AdmissionReview{}
|
||||||
if err := json.Unmarshal(data, &review); err != nil {
|
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 {
|
if review.Request.UserInfo.Username != testClientAuthClientUsername {
|
||||||
// skip requests not originating from this integration test's client
|
// 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" {
|
if authz := r.Header.Get("Authorization"); authz != "Bearer localhost-match-with-port" {
|
||||||
t.Errorf("unexpected authz header: %q", authz)
|
t.Errorf("unexpected authz header: %q", authz)
|
||||||
http.Error(w, "Invalid auth", 401)
|
http.Error(w, "Invalid auth", http.StatusUnauthorized)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(review.Request.Object.Raw) == 0 {
|
if len(review.Request.Object.Raw) == 0 {
|
||||||
http.Error(w, err.Error(), 400)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pod := &corev1.Pod{}
|
pod := &corev1.Pod{}
|
||||||
if err := json.Unmarshal(review.Request.Object.Raw, pod); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,6 +428,9 @@ func newTimeoutWebhookHandler(recorder *timeoutRecorder) http.Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
timeout, err := time.ParseDuration(r.URL.Query().Get("timeout"))
|
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)}
|
invocation := invocation{path: r.URL.Path, timeoutSeconds: int(timeout.Round(time.Second) / time.Second)}
|
||||||
recorder.RecordInvocation(invocation)
|
recorder.RecordInvocation(invocation)
|
||||||
|
|
||||||
|
@ -403,11 +403,9 @@ func TestNameInFieldSelector(t *testing.T) {
|
|||||||
defer closeFn()
|
defer closeFn()
|
||||||
|
|
||||||
numNamespaces := 3
|
numNamespaces := 3
|
||||||
namespaces := make([]*v1.Namespace, 0, numNamespaces)
|
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
ns := framework.CreateTestingNamespace(fmt.Sprintf("ns%d", i), s, t)
|
ns := framework.CreateTestingNamespace(fmt.Sprintf("ns%d", i), s, t)
|
||||||
defer framework.DeleteTestingNamespace(ns, s, t)
|
defer framework.DeleteTestingNamespace(ns, s, t)
|
||||||
namespaces = append(namespaces, ns)
|
|
||||||
|
|
||||||
_, err := clientSet.CoreV1().Secrets(ns.Name).Create(makeSecret("foo"))
|
_, err := clientSet.CoreV1().Secrets(ns.Name).Create(makeSecret("foo"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user