Skip to content

Commit cb87e09

Browse files
committed
chore: Drop deprecated io/ioutil
1 parent df459c5 commit cb87e09

17 files changed

+41
-42
lines changed

pkg/controller/scheduler_daemonset_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"context"
2121
"encoding/json"
2222
"fmt"
23-
"io/ioutil"
23+
"io"
2424
"net/http"
2525
"net/http/httptest"
2626
"testing"
@@ -445,7 +445,7 @@ func TestScheduler_DaemonSetTargetPortName(t *testing.T) {
445445

446446
func TestScheduler_DaemonSetAlerts(t *testing.T) {
447447
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
448-
b, err := ioutil.ReadAll(r.Body)
448+
b, err := io.ReadAll(r.Body)
449449
require.NoError(t, err)
450450
var payload = notifier.SlackPayload{}
451451
err = json.Unmarshal(b, &payload)

pkg/controller/scheduler_deployment_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"context"
2121
"encoding/json"
2222
"fmt"
23-
"io/ioutil"
23+
"io"
2424
"net/http"
2525
"net/http/httptest"
2626
"testing"
@@ -596,7 +596,7 @@ func TestScheduler_DeploymentTargetPortName(t *testing.T) {
596596

597597
func TestScheduler_DeploymentAlerts(t *testing.T) {
598598
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
599-
b, err := ioutil.ReadAll(r.Body)
599+
b, err := io.ReadAll(r.Body)
600600
require.NoError(t, err)
601601
var payload = notifier.SlackPayload{}
602602
err = json.Unmarshal(b, &payload)

pkg/controller/webhook.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"encoding/json"
2323
"errors"
2424
"fmt"
25-
"io/ioutil"
25+
"io"
2626
"net/http"
2727
"net/url"
2828
"strconv"
@@ -67,7 +67,7 @@ func callWebhook(webhook string, payload interface{}, timeout string) error {
6767
}
6868
defer r.Body.Close()
6969

70-
b, err := ioutil.ReadAll(r.Body)
70+
b, err := io.ReadAll(r.Body)
7171
if err != nil {
7272
return fmt.Errorf("error reading body: %s", err.Error())
7373
}

pkg/loadtester/concord.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
"errors"
2424
"fmt"
2525
"io"
26-
"io/ioutil"
2726
"mime/multipart"
2827
"net/http"
2928
"net/url"
@@ -189,7 +188,7 @@ func (task *ConcordTask) newRequest(method, path string, contentType string, bod
189188
}
190189

191190
apiKey := ""
192-
dat, err := ioutil.ReadFile(task.APIKeyPath)
191+
dat, err := os.ReadFile(task.APIKeyPath)
193192
if err != nil {
194193
return req, err
195194
}

pkg/loadtester/concord_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package loadtester
1919
import (
2020
"bytes"
2121
"fmt"
22-
"io/ioutil"
22+
"io"
2323
"mime/multipart"
2424
"testing"
2525

@@ -94,7 +94,7 @@ func assertNextPartHasKeyAndValue(t *testing.T, r *multipart.Reader, key string,
9494
}
9595
// assert.Equal(t, 1, part)
9696

97-
slurp, err := ioutil.ReadAll(part)
97+
slurp, err := io.ReadAll(part)
9898
if err != nil {
9999
fmt.Printf("Part: %+v", part)
100100
t.Fatalf("Couldn't read part: %v", err)

pkg/loadtester/server.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"context"
2121
"encoding/json"
2222
"fmt"
23-
"io/ioutil"
23+
"io"
2424
"net/http"
2525
"strconv"
2626
"time"
@@ -44,7 +44,7 @@ func ListenAndServe(port string, timeout time.Duration, logger *zap.SugaredLogge
4444
w.Write([]byte("Forbidden"))
4545
})
4646
mux.HandleFunc("/gate/check", func(w http.ResponseWriter, r *http.Request) {
47-
body, err := ioutil.ReadAll(r.Body)
47+
body, err := io.ReadAll(r.Body)
4848
if err != nil {
4949
logger.Error("reading the request body failed", zap.Error(err))
5050
w.WriteHeader(http.StatusBadRequest)
@@ -74,7 +74,7 @@ func ListenAndServe(port string, timeout time.Duration, logger *zap.SugaredLogge
7474
})
7575

7676
mux.HandleFunc("/gate/open", func(w http.ResponseWriter, r *http.Request) {
77-
body, err := ioutil.ReadAll(r.Body)
77+
body, err := io.ReadAll(r.Body)
7878
if err != nil {
7979
logger.Error("reading the request body failed", zap.Error(err))
8080
w.WriteHeader(http.StatusBadRequest)
@@ -99,7 +99,7 @@ func ListenAndServe(port string, timeout time.Duration, logger *zap.SugaredLogge
9999
})
100100

101101
mux.HandleFunc("/gate/close", func(w http.ResponseWriter, r *http.Request) {
102-
body, err := ioutil.ReadAll(r.Body)
102+
body, err := io.ReadAll(r.Body)
103103
if err != nil {
104104
logger.Error("reading the request body failed", zap.Error(err))
105105
w.WriteHeader(http.StatusBadRequest)
@@ -124,7 +124,7 @@ func ListenAndServe(port string, timeout time.Duration, logger *zap.SugaredLogge
124124
})
125125

126126
mux.HandleFunc("/rollback/check", func(w http.ResponseWriter, r *http.Request) {
127-
body, err := ioutil.ReadAll(r.Body)
127+
body, err := io.ReadAll(r.Body)
128128
if err != nil {
129129
logger.Error("reading the request body failed", zap.Error(err))
130130
w.WriteHeader(http.StatusBadRequest)
@@ -153,7 +153,7 @@ func ListenAndServe(port string, timeout time.Duration, logger *zap.SugaredLogge
153153
logger.Infof("%s rollback check: approved %v", canaryName, approved)
154154
})
155155
mux.HandleFunc("/rollback/open", func(w http.ResponseWriter, r *http.Request) {
156-
body, err := ioutil.ReadAll(r.Body)
156+
body, err := io.ReadAll(r.Body)
157157
if err != nil {
158158
logger.Error("reading the request body failed", zap.Error(err))
159159
w.WriteHeader(http.StatusBadRequest)
@@ -177,7 +177,7 @@ func ListenAndServe(port string, timeout time.Duration, logger *zap.SugaredLogge
177177
logger.Infof("%s rollback opened", canaryName)
178178
})
179179
mux.HandleFunc("/rollback/close", func(w http.ResponseWriter, r *http.Request) {
180-
body, err := ioutil.ReadAll(r.Body)
180+
body, err := io.ReadAll(r.Body)
181181
if err != nil {
182182
logger.Error("reading the request body failed", zap.Error(err))
183183
w.WriteHeader(http.StatusBadRequest)
@@ -235,7 +235,7 @@ func HandleHealthz(w http.ResponseWriter, r *http.Request) {
235235
// HandleNewTask handles task creation requests
236236
func HandleNewTask(logger *zap.SugaredLogger, taskRunner TaskRunnerInterface) func(w http.ResponseWriter, r *http.Request) {
237237
return func(w http.ResponseWriter, r *http.Request) {
238-
body, err := ioutil.ReadAll(r.Body)
238+
body, err := io.ReadAll(r.Body)
239239
if err != nil {
240240
logger.Error("reading the request body failed", zap.Error(err))
241241
w.WriteHeader(http.StatusBadRequest)

pkg/loadtester/task_ngrinder.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"encoding/json"
2323
"errors"
2424
"fmt"
25-
"io/ioutil"
25+
"io"
2626
"net/http"
2727
"net/url"
2828
"strconv"
@@ -167,7 +167,7 @@ func (task *NGrinderTask) request(method, url string, ctx context.Context) (map[
167167
}
168168
defer resp.Body.Close()
169169

170-
respBytes, err := ioutil.ReadAll(resp.Body)
170+
respBytes, err := io.ReadAll(resp.Body)
171171
if err != nil {
172172
return nil, fmt.Errorf("reading response body failed: %w", err)
173173
}

pkg/metrics/providers/datadog.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"context"
2121
"encoding/json"
2222
"fmt"
23-
"io/ioutil"
23+
"io"
2424
"net/http"
2525
"strconv"
2626
"time"
@@ -125,7 +125,7 @@ func (p *DatadogProvider) RunQuery(query string) (float64, error) {
125125
}
126126

127127
defer r.Body.Close()
128-
b, err := ioutil.ReadAll(r.Body)
128+
b, err := io.ReadAll(r.Body)
129129
if err != nil {
130130
return 0, fmt.Errorf("error reading body: %w", err)
131131
}
@@ -176,7 +176,7 @@ func (p *DatadogProvider) IsOnline() (bool, error) {
176176

177177
defer r.Body.Close()
178178

179-
b, err := ioutil.ReadAll(r.Body)
179+
b, err := io.ReadAll(r.Body)
180180
if err != nil {
181181
return false, fmt.Errorf("error reading body: %w", err)
182182
}

pkg/metrics/providers/graphite.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"crypto/tls"
2222
"encoding/json"
2323
"fmt"
24-
"io/ioutil"
24+
"io"
2525
"math"
2626
"net/http"
2727
"net/url"
@@ -183,7 +183,7 @@ func (g *GraphiteProvider) RunQuery(query string) (float64, error) {
183183
}
184184
defer r.Body.Close()
185185

186-
b, err := ioutil.ReadAll(r.Body)
186+
b, err := io.ReadAll(r.Body)
187187
if err != nil {
188188
return 0, fmt.Errorf("error reading body: %w", err)
189189
}

pkg/metrics/providers/newrelic.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"context"
2121
"encoding/json"
2222
"fmt"
23-
"io/ioutil"
23+
"io"
2424
"net/http"
2525
"time"
2626

@@ -105,7 +105,7 @@ func (p *NewRelicProvider) RunQuery(query string) (float64, error) {
105105
}
106106

107107
defer r.Body.Close()
108-
b, err := ioutil.ReadAll(r.Body)
108+
b, err := io.ReadAll(r.Body)
109109
if err != nil {
110110
return 0, fmt.Errorf("error reading body: %w", err)
111111
}
@@ -147,7 +147,7 @@ func (p *NewRelicProvider) IsOnline() (bool, error) {
147147

148148
defer r.Body.Close()
149149

150-
b, err := ioutil.ReadAll(r.Body)
150+
b, err := io.ReadAll(r.Body)
151151
if err != nil {
152152
return false, fmt.Errorf("error reading body: %w", err)
153153
}

pkg/metrics/providers/prometheus.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"crypto/tls"
2222
"encoding/json"
2323
"fmt"
24-
"io/ioutil"
24+
"io"
2525
"net/http"
2626
"net/url"
2727
"path"
@@ -121,7 +121,7 @@ func (p *PrometheusProvider) RunQuery(query string) (float64, error) {
121121
}
122122
defer r.Body.Close()
123123

124-
b, err := ioutil.ReadAll(r.Body)
124+
b, err := io.ReadAll(r.Body)
125125
if err != nil {
126126
return 0, fmt.Errorf("error reading body: %w", err)
127127
}

pkg/notifier/client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"context"
2222
"encoding/json"
2323
"fmt"
24-
"io/ioutil"
24+
"io"
2525
"net"
2626
"net/http"
2727
"net/url"
@@ -75,7 +75,7 @@ func postMessage(address string, proxy string, payload interface{}) error {
7575
defer res.Body.Close()
7676
statusCode := res.StatusCode
7777
if statusCode != 200 {
78-
body, _ := ioutil.ReadAll(res.Body)
78+
body, _ := io.ReadAll(res.Body)
7979
return fmt.Errorf("sending notification failed: %s", string(body))
8080
}
8181

pkg/notifier/client_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package notifier
1818

1919
import (
2020
"encoding/json"
21-
"io/ioutil"
21+
"io"
2222
"net/http"
2323
"net/http/httptest"
2424
"testing"
@@ -28,7 +28,7 @@ import (
2828

2929
func Test_postMessage(t *testing.T) {
3030
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
31-
b, err := ioutil.ReadAll(r.Body)
31+
b, err := io.ReadAll(r.Body)
3232
require.NoError(t, err)
3333

3434
var payload = make(map[string]string)

pkg/notifier/discord_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package notifier
1818

1919
import (
2020
"encoding/json"
21-
"io/ioutil"
21+
"io"
2222
"net/http"
2323
"net/http/httptest"
2424
"strings"
@@ -35,7 +35,7 @@ func TestDiscord_Post(t *testing.T) {
3535
}
3636

3737
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
38-
b, err := ioutil.ReadAll(r.Body)
38+
b, err := io.ReadAll(r.Body)
3939
require.NoError(t, err)
4040
var payload = SlackPayload{}
4141
err = json.Unmarshal(b, &payload)

pkg/notifier/rocket_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package notifier
1818

1919
import (
2020
"encoding/json"
21-
"io/ioutil"
21+
"io"
2222
"net/http"
2323
"net/http/httptest"
2424
"testing"
@@ -33,7 +33,7 @@ func TestRocket_Post(t *testing.T) {
3333
}
3434

3535
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
36-
b, err := ioutil.ReadAll(r.Body)
36+
b, err := io.ReadAll(r.Body)
3737
require.NoError(t, err)
3838

3939
var payload = SlackPayload{}

pkg/notifier/slack_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package notifier
1818

1919
import (
2020
"encoding/json"
21-
"io/ioutil"
21+
"io"
2222
"net/http"
2323
"net/http/httptest"
2424
"testing"
@@ -33,7 +33,7 @@ func TestSlack_Post(t *testing.T) {
3333
}
3434

3535
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
36-
b, err := ioutil.ReadAll(r.Body)
36+
b, err := io.ReadAll(r.Body)
3737
require.NoError(t, err)
3838

3939
var payload = SlackPayload{}

pkg/notifier/teams_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package notifier
1818

1919
import (
2020
"encoding/json"
21-
"io/ioutil"
21+
"io"
2222
"net/http"
2323
"net/http/httptest"
2424
"testing"
@@ -34,7 +34,7 @@ func TestTeams_Post(t *testing.T) {
3434
}
3535

3636
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
37-
b, err := ioutil.ReadAll(r.Body)
37+
b, err := io.ReadAll(r.Body)
3838
require.NoError(t, err)
3939
var payload = MSTeamsPayload{}
4040
err = json.Unmarshal(b, &payload)

0 commit comments

Comments
 (0)