fix some ineffassigns

Signed-off-by: haoshuwei <haoshuwei24@gmail.com>
This commit is contained in:
haoshuwei 2019-09-09 18:52:17 +08:00
parent 89a6533ef6
commit aaed9daf9b
8 changed files with 71 additions and 8 deletions

View File

@ -3078,6 +3078,9 @@ func TestDelete(t *testing.T) {
client := http.Client{} client := http.Client{}
request, err := http.NewRequest("DELETE", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, nil) request, err := http.NewRequest("DELETE", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, nil)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
res, err := client.Do(request) res, err := client.Do(request)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
@ -3110,6 +3113,9 @@ func TestDeleteWithOptions(t *testing.T) {
client := http.Client{} client := http.Client{}
request, err := http.NewRequest("DELETE", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, bytes.NewReader(body)) request, err := http.NewRequest("DELETE", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, bytes.NewReader(body))
if err != nil {
t.Errorf("unexpected error: %v", err)
}
res, err := client.Do(request) res, err := client.Do(request)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
@ -3147,6 +3153,9 @@ func TestDeleteWithOptionsQuery(t *testing.T) {
client := http.Client{} client := http.Client{}
request, err := http.NewRequest("DELETE", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID+"?gracePeriodSeconds="+strconv.FormatInt(grace, 10), nil) request, err := http.NewRequest("DELETE", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID+"?gracePeriodSeconds="+strconv.FormatInt(grace, 10), nil)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
res, err := client.Do(request) res, err := client.Do(request)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
@ -3187,6 +3196,9 @@ func TestDeleteWithOptionsQueryAndBody(t *testing.T) {
} }
client := http.Client{} client := http.Client{}
request, err := http.NewRequest("DELETE", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID+"?gracePeriodSeconds="+strconv.FormatInt(grace+10, 10), bytes.NewReader(body)) request, err := http.NewRequest("DELETE", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID+"?gracePeriodSeconds="+strconv.FormatInt(grace+10, 10), bytes.NewReader(body))
if err != nil {
t.Errorf("unexpected error: %v", err)
}
res, err := client.Do(request) res, err := client.Do(request)
if err != nil { if err != nil {
t.Fatalf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
@ -3223,6 +3235,9 @@ func TestDeleteInvokesAdmissionControl(t *testing.T) {
client := http.Client{} client := http.Client{}
request, err := http.NewRequest("DELETE", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, nil) request, err := http.NewRequest("DELETE", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, nil)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
response, err := client.Do(request) response, err := client.Do(request)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
@ -3246,6 +3261,9 @@ func TestDeleteMissing(t *testing.T) {
client := http.Client{} client := http.Client{}
request, err := http.NewRequest("DELETE", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, nil) request, err := http.NewRequest("DELETE", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, nil)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
response, err := client.Do(request) response, err := client.Do(request)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
@ -3286,6 +3304,9 @@ func TestUpdate(t *testing.T) {
client := http.Client{} client := http.Client{}
request, err := http.NewRequest("PUT", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, bytes.NewReader(body)) request, err := http.NewRequest("PUT", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, bytes.NewReader(body))
if err != nil {
t.Errorf("unexpected error: %v", err)
}
response, err := client.Do(request) response, err := client.Do(request)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
@ -3328,6 +3349,9 @@ func TestUpdateInvokesAdmissionControl(t *testing.T) {
client := http.Client{} client := http.Client{}
request, err := http.NewRequest("PUT", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, bytes.NewReader(body)) request, err := http.NewRequest("PUT", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, bytes.NewReader(body))
if err != nil {
t.Errorf("unexpected error: %v", err)
}
response, err := client.Do(request) response, err := client.Do(request)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
@ -3361,6 +3385,9 @@ func TestUpdateRequiresMatchingName(t *testing.T) {
client := http.Client{} client := http.Client{}
request, err := http.NewRequest("PUT", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, bytes.NewReader(body)) request, err := http.NewRequest("PUT", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, bytes.NewReader(body))
if err != nil {
t.Errorf("unexpected error: %v", err)
}
response, err := client.Do(request) response, err := client.Do(request)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
@ -3395,6 +3422,9 @@ func TestUpdateAllowsMissingNamespace(t *testing.T) {
client := http.Client{} client := http.Client{}
request, err := http.NewRequest("PUT", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, bytes.NewReader(body)) request, err := http.NewRequest("PUT", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, bytes.NewReader(body))
if err != nil {
t.Errorf("unexpected error: %v", err)
}
response, err := client.Do(request) response, err := client.Do(request)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
@ -3436,6 +3466,9 @@ func TestUpdateDisallowsMismatchedNamespaceOnError(t *testing.T) {
client := http.Client{} client := http.Client{}
request, err := http.NewRequest("PUT", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, bytes.NewReader(body)) request, err := http.NewRequest("PUT", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, bytes.NewReader(body))
if err != nil {
t.Errorf("unexpected error: %v", err)
}
response, err := client.Do(request) response, err := client.Do(request)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
@ -3475,6 +3508,9 @@ func TestUpdatePreventsMismatchedNamespace(t *testing.T) {
client := http.Client{} client := http.Client{}
request, err := http.NewRequest("PUT", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, bytes.NewReader(body)) request, err := http.NewRequest("PUT", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, bytes.NewReader(body))
if err != nil {
t.Errorf("unexpected error: %v", err)
}
response, err := client.Do(request) response, err := client.Do(request)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
@ -3509,6 +3545,9 @@ func TestUpdateMissing(t *testing.T) {
client := http.Client{} client := http.Client{}
request, err := http.NewRequest("PUT", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, bytes.NewReader(body)) request, err := http.NewRequest("PUT", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, bytes.NewReader(body))
if err != nil {
t.Errorf("unexpected error: %v", err)
}
response, err := client.Do(request) response, err := client.Do(request)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)

View File

@ -53,6 +53,9 @@ func TestPatch(t *testing.T) {
client := http.Client{} client := http.Client{}
request, err := http.NewRequest("PATCH", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, bytes.NewReader([]byte(`{"labels":{"foo":"bar"}}`))) request, err := http.NewRequest("PATCH", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, bytes.NewReader([]byte(`{"labels":{"foo":"bar"}}`)))
if err != nil {
t.Errorf("unexpected error: %v", err)
}
request.Header.Set("Content-Type", "application/merge-patch+json; charset=UTF-8") request.Header.Set("Content-Type", "application/merge-patch+json; charset=UTF-8")
response, err := client.Do(request) response, err := client.Do(request)
if err != nil { if err != nil {
@ -94,6 +97,9 @@ func TestForbiddenForceOnNonApply(t *testing.T) {
client := http.Client{} client := http.Client{}
request, err := http.NewRequest("PATCH", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, bytes.NewReader([]byte(`{"labels":{"foo":"bar"}}`))) request, err := http.NewRequest("PATCH", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, bytes.NewReader([]byte(`{"labels":{"foo":"bar"}}`)))
if err != nil {
t.Errorf("unexpected error: %v", err)
}
request.Header.Set("Content-Type", "application/merge-patch+json; charset=UTF-8") request.Header.Set("Content-Type", "application/merge-patch+json; charset=UTF-8")
_, err = client.Do(request) _, err = client.Do(request)
if err != nil { if err != nil {
@ -101,6 +107,9 @@ func TestForbiddenForceOnNonApply(t *testing.T) {
} }
request, err = http.NewRequest("PATCH", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID+"?force=true", bytes.NewReader([]byte(`{"labels":{"foo":"bar"}}`))) request, err = http.NewRequest("PATCH", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID+"?force=true", bytes.NewReader([]byte(`{"labels":{"foo":"bar"}}`)))
if err != nil {
t.Errorf("unexpected error: %v", err)
}
request.Header.Set("Content-Type", "application/merge-patch+json; charset=UTF-8") request.Header.Set("Content-Type", "application/merge-patch+json; charset=UTF-8")
response, err := client.Do(request) response, err := client.Do(request)
if err != nil { if err != nil {
@ -111,6 +120,9 @@ func TestForbiddenForceOnNonApply(t *testing.T) {
} }
request, err = http.NewRequest("PATCH", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID+"?force=false", bytes.NewReader([]byte(`{"labels":{"foo":"bar"}}`))) request, err = http.NewRequest("PATCH", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID+"?force=false", bytes.NewReader([]byte(`{"labels":{"foo":"bar"}}`)))
if err != nil {
t.Errorf("unexpected error: %v", err)
}
request.Header.Set("Content-Type", "application/merge-patch+json; charset=UTF-8") request.Header.Set("Content-Type", "application/merge-patch+json; charset=UTF-8")
response, err = client.Do(request) response, err = client.Do(request)
if err != nil { if err != nil {
@ -140,6 +152,9 @@ func TestPatchRequiresMatchingName(t *testing.T) {
client := http.Client{} client := http.Client{}
request, err := http.NewRequest("PATCH", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, bytes.NewReader([]byte(`{"metadata":{"name":"idbar"}}`))) request, err := http.NewRequest("PATCH", server.URL+"/"+prefix+"/"+testGroupVersion.Group+"/"+testGroupVersion.Version+"/namespaces/default/simple/"+ID, bytes.NewReader([]byte(`{"metadata":{"name":"idbar"}}`)))
if err != nil {
t.Errorf("unexpected error: %v", err)
}
request.Header.Set("Content-Type", "application/merge-patch+json") request.Header.Set("Content-Type", "application/merge-patch+json")
response, err := client.Do(request) response, err := client.Do(request)
if err != nil { if err != nil {

View File

@ -35,7 +35,7 @@ func TestNamespaceContext(t *testing.T) {
} }
ctx = NewContext() ctx = NewContext()
result, ok = NamespaceFrom(ctx) _, ok = NamespaceFrom(ctx)
if ok { if ok {
t.Fatalf("Should not be ok because there is no namespace on the context") t.Fatalf("Should not be ok because there is no namespace on the context")
} }

View File

@ -604,6 +604,9 @@ func TestWatchHTTPErrors(t *testing.T) {
req, _ := http.NewRequest("GET", dest.String(), nil) req, _ := http.NewRequest("GET", dest.String(), nil)
client := http.Client{} client := http.Client{}
resp, err := client.Do(req) resp, err := client.Do(req)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
errStatus := errors.NewInternalError(fmt.Errorf("we got an error")).Status() errStatus := errors.NewInternalError(fmt.Errorf("we got an error")).Status()
watcher.Error(&errStatus) watcher.Error(&errStatus)
watcher.Stop() watcher.Stop()
@ -728,6 +731,9 @@ func TestWatchHTTPTimeout(t *testing.T) {
req, _ := http.NewRequest("GET", dest.String(), nil) req, _ := http.NewRequest("GET", dest.String(), nil)
client := http.Client{} client := http.Client{}
resp, err := client.Do(req) resp, err := client.Do(req)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
watcher.Add(&apitesting.Simple{TypeMeta: metav1.TypeMeta{APIVersion: newGroupVersion.String()}}) watcher.Add(&apitesting.Simple{TypeMeta: metav1.TypeMeta{APIVersion: newGroupVersion.String()}})
// Make sure we can actually watch an endpoint // Make sure we can actually watch an endpoint

View File

@ -316,13 +316,13 @@ func TestStoreCreate(t *testing.T) {
} }
// create the object with denying admission // create the object with denying admission
objA, err := registry.Create(testContext, podA, denyCreateValidation, &metav1.CreateOptions{}) _, err := registry.Create(testContext, podA, denyCreateValidation, &metav1.CreateOptions{})
if err == nil { if err == nil {
t.Errorf("Expected admission error: %v", err) t.Errorf("Expected admission error: %v", err)
} }
// create the object // create the object
objA, err = registry.Create(testContext, podA, rest.ValidateAllObjectFunc, &metav1.CreateOptions{}) objA, err := registry.Create(testContext, podA, rest.ValidateAllObjectFunc, &metav1.CreateOptions{})
if err != nil { if err != nil {
t.Errorf("Unexpected error: %v", err) t.Errorf("Unexpected error: %v", err)
} }
@ -1335,6 +1335,9 @@ func TestStoreDeletionPropagation(t *testing.T) {
t.Fatalf("Unexpected error: %v", err) t.Fatalf("Unexpected error: %v", err)
} }
_, _, err = registry.Delete(testContext, pod.Name, rest.ValidateAllObjectFunc, tc.options) _, _, err = registry.Delete(testContext, pod.Name, rest.ValidateAllObjectFunc, tc.options)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
obj, err := registry.Get(testContext, pod.Name, &metav1.GetOptions{}) obj, err := registry.Get(testContext, pod.Name, &metav1.GetOptions{})
if tc.expectedNotFound { if tc.expectedNotFound {
if err == nil || !errors.IsNotFound(err) { if err == nil || !errors.IsNotFound(err) {

View File

@ -54,7 +54,7 @@ func TestInputStreamReader(t *testing.T) {
return return
} }
defer readCloser.Close() defer readCloser.Close()
result, err := ioutil.ReadAll(readCloser) result, _ := ioutil.ReadAll(readCloser)
if string(result) != resultString { if string(result) != resultString {
t.Errorf("Stream content does not match. Got: %s. Expected: %s.", string(result), resultString) t.Errorf("Stream content does not match. Got: %s. Expected: %s.", string(result), resultString)
} }
@ -118,7 +118,7 @@ func TestInputStreamTransport(t *testing.T) {
return return
} }
defer readCloser.Close() defer readCloser.Close()
result, err := ioutil.ReadAll(readCloser) result, _ := ioutil.ReadAll(readCloser)
if string(result) != message { if string(result) != message {
t.Errorf("Stream content does not match. Got: %s. Expected: %s.", string(result), message) t.Errorf("Stream content does not match. Got: %s. Expected: %s.", string(result), message)
} }

View File

@ -78,7 +78,7 @@ func TestGCMKeyRotation(t *testing.T) {
} }
// verify changing the context fails storage // verify changing the context fails storage
from, stale, err = p.TransformFromStorage(out, value.DefaultContext([]byte("incorrect_context"))) _, _, err = p.TransformFromStorage(out, value.DefaultContext([]byte("incorrect_context")))
if err == nil { if err == nil {
t.Fatalf("expected unauthenticated data") t.Fatalf("expected unauthenticated data")
} }
@ -130,7 +130,7 @@ func TestCBCKeyRotation(t *testing.T) {
} }
// verify changing the context fails storage // verify changing the context fails storage
from, stale, err = p.TransformFromStorage(out, value.DefaultContext([]byte("incorrect_context"))) _, _, err = p.TransformFromStorage(out, value.DefaultContext([]byte("incorrect_context")))
if err != nil { if err != nil {
t.Fatalf("CBC mode does not support authentication: %v", err) t.Fatalf("CBC mode does not support authentication: %v", err)
} }

View File

@ -58,7 +58,7 @@ func TestSecretboxKeyRotation(t *testing.T) {
// verify changing the context does not fails storage // verify changing the context does not fails storage
// Secretbox is not currently an authenticating store // Secretbox is not currently an authenticating store
from, stale, err = p.TransformFromStorage(out, value.DefaultContext([]byte("incorrect_context"))) _, _, err = p.TransformFromStorage(out, value.DefaultContext([]byte("incorrect_context")))
if err != nil { if err != nil {
t.Fatalf("secretbox is not authenticated") t.Fatalf("secretbox is not authenticated")
} }