Skip to content

Commit

Permalink
replace ioutil with new functions (#473)
Browse files Browse the repository at this point in the history
Signed-off-by: Sandor Szücs <[email protected]>
  • Loading branch information
szuecs authored Feb 8, 2022
1 parent ff9e0b5 commit 9f2db47
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 29 deletions.
4 changes: 2 additions & 2 deletions aws/iam_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aws

import (
"io/ioutil"
"os"
"testing"
"time"

Expand Down Expand Up @@ -31,7 +31,7 @@ func (m mockedIAMClient) GetServerCertificate(*iam.GetServerCertificateInput) (*
}

func mustRead(testFile string) string {
buf, err := ioutil.ReadFile("testdata/" + testFile)
buf, err := os.ReadFile("testdata/" + testFile)
if err != nil {
panic(err)
}
Expand Down
10 changes: 5 additions & 5 deletions kubernetes/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"reflect"
"strings"
"testing"
Expand Down Expand Up @@ -498,20 +498,20 @@ func (c *mockClient) get(res string) (io.ReadCloser, error) {
return nil, fmt.Errorf("unexpected resource: %s", res)
}

buf, err := ioutil.ReadFile(fixture)
buf, err := os.ReadFile(fixture)
if err != nil {
return nil, err
}
return ioutil.NopCloser(bytes.NewReader(buf)), nil
return io.NopCloser(bytes.NewReader(buf)), nil
}

func (c *mockClient) patch(res string, payload []byte) (io.ReadCloser, error) {
if !c.broken {
switch res {
case fmt.Sprintf("/apis/%s/namespaces/default/ingresses/foo/status", IngressAPIVersionNetworking):
return ioutil.NopCloser(strings.NewReader(":)")), nil
return io.NopCloser(strings.NewReader(":)")), nil
case "/apis/zalando.org/v1/namespaces/default/routegroups/foo/status":
return ioutil.NopCloser(strings.NewReader(":)")), nil
return io.NopCloser(strings.NewReader(":)")), nil
}
}
return nil, errors.New("mocked error")
Expand Down
10 changes: 5 additions & 5 deletions kubernetes/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"os"
"strings"
"time"

Expand Down Expand Up @@ -50,7 +50,7 @@ func newSimpleClient(cfg *Config, disableInstrumentedHttpClient bool) (client, e
c *http.Client = http.DefaultClient
)
if cfg.CAFile != "" {
fileData, err := ioutil.ReadFile(cfg.CAFile)
fileData, err := os.ReadFile(cfg.CAFile)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -114,7 +114,7 @@ func (c *simpleClient) get(resource string) (io.ReadCloser, error) {
if resp.StatusCode == http.StatusForbidden {
return nil, ErrNoPermissionToAccessResource
}
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err == nil {
err = fmt.Errorf("unexpected status code (%s) for GET %q: %s", http.StatusText(resp.StatusCode), resource, b)
}
Expand All @@ -133,13 +133,13 @@ func (c *simpleClient) patch(resource string, payload []byte) (io.ReadCloser, er
}
if resp.StatusCode != http.StatusOK {
var err error
b, err := ioutil.ReadAll(resp.Body)
b, err := io.ReadAll(resp.Body)
if err == nil {
err = fmt.Errorf("unexpected status code (%s) for PATCH %q: %s", http.StatusText(resp.StatusCode), resource, b)
}

resp.Body.Close()
return ioutil.NopCloser(bytes.NewBuffer(b)), err
return io.NopCloser(bytes.NewBuffer(b)), err
}
return resp.Body, nil
}
Expand Down
9 changes: 4 additions & 5 deletions kubernetes/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"crypto/tls"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"reflect"
Expand Down Expand Up @@ -54,7 +53,7 @@ func TestClientGet(t *testing.T) {
}

if !test.wantError {
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
t.Error("error reading response", err)
}
Expand Down Expand Up @@ -93,7 +92,7 @@ func TestClientPatch(t *testing.T) {
w.WriteHeader(http.StatusBadRequest)
return
}
b, err := ioutil.ReadAll(r.Body)
b, err := io.ReadAll(r.Body)
if err != nil {
t.Error("failure reading request payload", err)
return
Expand All @@ -120,7 +119,7 @@ func TestClientPatch(t *testing.T) {
}

if !test.wantError {
b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
t.Error("error reading response", err)
}
Expand All @@ -139,7 +138,7 @@ func TestTLS(t *testing.T) {
if token != "Bearer foo" {
t.Errorf(`wrong auth bearer token. wanted "Bearer: foo" but got %q`, token)
}
buf, err := ioutil.ReadAll(r.Body)
buf, err := io.ReadAll(r.Body)
if err != nil {
t.Error(err)
}
Expand Down
3 changes: 1 addition & 2 deletions kubernetes/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package kubernetes

import (
"io/ioutil"
"net"
"os"
"time"
Expand Down Expand Up @@ -68,7 +67,7 @@ func InClusterConfig() (*Config, error) {
}

dir := serviceAccountLocator()
token, err := ioutil.ReadFile(dir + serviceAccountTokenKey)
token, err := os.ReadFile(dir + serviceAccountTokenKey)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions kubernetes/config_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package kubernetes
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
)

const (
Expand Down Expand Up @@ -32,7 +32,7 @@ func getConfigMap(c client, namespace, name string) (*configMap, error) {

defer r.Close()

b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
return nil, fmt.Errorf("failed to read ConfigMap %s/%s: %v", namespace, name, err)
}
Expand Down
4 changes: 2 additions & 2 deletions kubernetes/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package kubernetes
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
"time"
)

Expand Down Expand Up @@ -104,7 +104,7 @@ func (ic *ingressClient) listIngress(c client) (*ingressList, error) {

defer r.Close()

b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions kubernetes/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package kubernetes
import (
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -112,7 +111,7 @@ func TestUpdateIngressLoadBalancer(t *testing.T) {
if !expectedContentType[ct] {
t.Error("unexpected content type", ct)
}
b, err := ioutil.ReadAll(req.Body)
b, err := io.ReadAll(req.Body)
if err != nil {
t.Error(err)
}
Expand Down
4 changes: 2 additions & 2 deletions kubernetes/routegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package kubernetes
import (
"encoding/json"
"fmt"
"io/ioutil"
"io"
)

type routegroupList struct {
Expand Down Expand Up @@ -54,7 +54,7 @@ func listRoutegroups(c client) (*routegroupList, error) {

defer r.Close()

b, err := ioutil.ReadAll(r)
b, err := io.ReadAll(r)
if err != nil {
return nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions kubernetes/routegroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package kubernetes
import (
"fmt"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -78,7 +77,7 @@ func TestUpdateRoutegroupLoadBalancer(t *testing.T) {
if !expectedContentType[ct] {
t.Error("unexpected content type", ct)
}
b, err := ioutil.ReadAll(req.Body)
b, err := io.ReadAll(req.Body)
if err != nil {
t.Error(err)
}
Expand Down

0 comments on commit 9f2db47

Please sign in to comment.