io/ioutil has already been deprecated in golang 1.16, so replace all ioutil with io and os

This commit is contained in:
ahrtr
2021-10-30 06:41:02 +08:00
parent 2d0fa78f2f
commit fe95aa614c
96 changed files with 250 additions and 297 deletions

View File

@@ -30,7 +30,7 @@ import (
"encoding/json"
"encoding/pem"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"net/url"
@@ -87,7 +87,7 @@ func getTestTokenAuth() authenticator.Request {
}
func getTestWebhookTokenAuth(serverURL string, customDial utilnet.DialFunc) (authenticator.Request, error) {
kubecfgFile, err := ioutil.TempFile("", "webhook-kubecfg")
kubecfgFile, err := os.CreateTemp("", "webhook-kubecfg")
if err != nil {
return nil, err
}
@@ -495,7 +495,7 @@ func TestAuthModeAlwaysAllow(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}
defer resp.Body.Close()
b, _ := ioutil.ReadAll(resp.Body)
b, _ := io.ReadAll(resp.Body)
if _, ok := r.statusCodes[resp.StatusCode]; !ok {
t.Logf("case %v", r)
t.Errorf("Expected status one of %v, but got %v", r.statusCodes, resp.StatusCode)
@@ -643,7 +643,7 @@ func TestAliceNotForbiddenOrUnauthorized(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}
defer resp.Body.Close()
b, _ := ioutil.ReadAll(resp.Body)
b, _ := io.ReadAll(resp.Body)
if _, ok := r.statusCodes[resp.StatusCode]; !ok {
t.Logf("case %v", r)
t.Errorf("Expected status one of %v, but got %v", r.statusCodes, resp.StatusCode)
@@ -742,7 +742,7 @@ func TestUnknownUserIsUnauthorized(t *testing.T) {
if resp.StatusCode != http.StatusUnauthorized {
t.Logf("case %v", r)
t.Errorf("Expected status %v, but got %v", http.StatusUnauthorized, resp.StatusCode)
b, _ := ioutil.ReadAll(resp.Body)
b, _ := io.ReadAll(resp.Body)
t.Errorf("Body: %v", string(b))
}
}()
@@ -1047,14 +1047,14 @@ func csrPEM(t *testing.T) []byte {
}
func newAuthorizerWithContents(t *testing.T, contents string) authorizer.Authorizer {
f, err := ioutil.TempFile("", "auth_test")
f, err := os.CreateTemp("", "auth_test")
if err != nil {
t.Fatalf("unexpected error creating policyfile: %v", err)
}
f.Close()
defer os.Remove(f.Name())
if err := ioutil.WriteFile(f.Name(), []byte(contents), 0700); err != nil {
if err := os.WriteFile(f.Name(), []byte(contents), 0700); err != nil {
t.Fatalf("unexpected error writing policyfile: %v", err)
}
@@ -1215,7 +1215,7 @@ func TestNamespaceAuthorization(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}
defer resp.Body.Close()
b, _ := ioutil.ReadAll(resp.Body)
b, _ := io.ReadAll(resp.Body)
if _, ok := r.statusCodes[resp.StatusCode]; !ok {
t.Logf("case %v", r)
t.Errorf("Expected status one of %v, but got %v", r.statusCodes, resp.StatusCode)
@@ -1300,7 +1300,7 @@ func TestKindAuthorization(t *testing.T) {
t.Fatalf("unexpected error: %v", err)
}
defer resp.Body.Close()
b, _ := ioutil.ReadAll(resp.Body)
b, _ := io.ReadAll(resp.Body)
if _, ok := r.statusCodes[resp.StatusCode]; !ok {
t.Logf("case %v", r)
t.Errorf("Expected status one of %v, but got %v", r.statusCodes, resp.StatusCode)
@@ -1367,7 +1367,7 @@ func TestReadOnlyAuthorization(t *testing.T) {
if _, ok := r.statusCodes[resp.StatusCode]; !ok {
t.Logf("case %v", r)
t.Errorf("Expected status one of %v, but got %v", r.statusCodes, resp.StatusCode)
b, _ := ioutil.ReadAll(resp.Body)
b, _ := io.ReadAll(resp.Body)
t.Errorf("Body: %v", string(b))
}
}()