Skip to content

Commit c77d4f1

Browse files
committed
Remove use of io/ioutil package because its deprecated
Signed-off-by: Alvin Lin <[email protected]>
1 parent 5d0df05 commit c77d4f1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+158
-178
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ dist/
2424
Makefile.local
2525

2626
.idea
27+
.vscode
2728
compose
2829
compose-simple

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ linters-settings:
1313
staticcheck:
1414
checks:
1515
- all
16-
- "-SA1019" # Disable because too many file uses io/ioutil now, will fix later
1716
errcheck:
1817
# path to a file containing a list of functions to exclude from checking
1918
# see https://github.com/kisielk/errcheck#excluding-functions for details

cmd/cortex/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"crypto/sha256"
66
"flag"
77
"fmt"
8-
"io/ioutil"
8+
"io"
99
"math/rand"
1010
"os"
1111
"runtime"
@@ -204,7 +204,7 @@ func main() {
204204
func parseConfigFileParameter(args []string) (configFile string, expandEnv bool) {
205205
// ignore errors and any output here. Any flag errors will be reported by main flag.Parse() call.
206206
fs := flag.NewFlagSet("", flag.ContinueOnError)
207-
fs.SetOutput(ioutil.Discard)
207+
fs.SetOutput(io.Discard)
208208

209209
// usage not used in these functions.
210210
fs.StringVar(&configFile, configFileOption, "", "")
@@ -223,7 +223,7 @@ func parseConfigFileParameter(args []string) (configFile string, expandEnv bool)
223223

224224
// LoadConfig read YAML-formatted config from filename into cfg.
225225
func LoadConfig(filename string, expandENV bool, cfg *cortex.Config) error {
226-
buf, err := ioutil.ReadFile(filename)
226+
buf, err := os.ReadFile(filename)
227227
if err != nil {
228228
return errors.Wrap(err, "Error reading config file")
229229
}

integration/api_endpoints_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package integration
55

66
import (
77
"fmt"
8-
"io/ioutil"
8+
"io"
99
"net/http"
1010
"testing"
1111

@@ -55,7 +55,7 @@ func TestConfigAPIEndpoint(t *testing.T) {
5555
require.NoError(t, err)
5656

5757
defer runutil.ExhaustCloseWithErrCapture(&err, res.Body, "config API response")
58-
body, err := ioutil.ReadAll(res.Body)
58+
body, err := io.ReadAll(res.Body)
5959
require.NoError(t, err)
6060
require.Equal(t, http.StatusOK, res.StatusCode)
6161

integration/e2e/scenario_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package e2e_test
66
import (
77
"bytes"
88
"context"
9-
"io/ioutil"
9+
"io"
1010
"testing"
1111
"time"
1212

@@ -65,13 +65,13 @@ func testMinioWorking(t *testing.T, m *e2e.HTTPService) {
6565

6666
r, err := bkt.Get(ctx, "recipe")
6767
require.NoError(t, err)
68-
b, err = ioutil.ReadAll(r)
68+
b, err = io.ReadAll(r)
6969
require.NoError(t, err)
7070
require.Equal(t, "Just go to Pastry Shop and buy.", string(b))
7171

7272
r, err = bkt.Get(ctx, "mom/recipe")
7373
require.NoError(t, err)
74-
b, err = ioutil.ReadAll(r)
74+
b, err = io.ReadAll(r)
7575
require.NoError(t, err)
7676
require.Equal(t, "https://www.bbcgoodfood.com/recipes/strawberry-cheesecake-4-easy-steps", string(b))
7777
}

integration/e2e/service.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"net"
99
"os/exec"
1010
"regexp"
@@ -418,7 +418,7 @@ func (p *HTTPReadinessProbe) Ready(service *ConcreteService) (err error) {
418418
}
419419

420420
defer runutil.ExhaustCloseWithErrCapture(&err, res.Body, "response readiness")
421-
body, _ := ioutil.ReadAll(res.Body)
421+
body, _ := io.ReadAll(res.Body)
422422

423423
if res.StatusCode < p.expectedStatusRangeStart || res.StatusCode > p.expectedStatusRangeEnd {
424424
return fmt.Errorf("expected code in range: [%v, %v], got status code: %v and body: %v", p.expectedStatusRangeStart, p.expectedStatusRangeEnd, res.StatusCode, string(body))
@@ -534,7 +534,7 @@ func (s *HTTPService) Metrics() (_ string, err error) {
534534
}
535535

536536
defer runutil.ExhaustCloseWithErrCapture(&err, res.Body, "metrics response")
537-
body, err := ioutil.ReadAll(res.Body)
537+
body, err := io.ReadAll(res.Body)
538538

539539
return string(body), err
540540
}

integration/e2e/util.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package e2e
22

33
import (
44
"context"
5-
"io/ioutil"
65
"math"
76
"math/rand"
87
"net/http"
@@ -157,7 +156,7 @@ func GetTempDirectory() (string, error) {
157156
}
158157
}
159158

160-
tmpDir, err := ioutil.TempDir(dir, "e2e_integration_test")
159+
tmpDir, err := os.MkdirTemp(dir, "e2e_integration_test")
161160
if err != nil {
162161
return "", err
163162
}

integration/querier_remote_read_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package integration
66
import (
77
"bytes"
88
"context"
9-
"io/ioutil"
9+
"io"
1010
"net/http"
1111
"testing"
1212
"time"
@@ -102,7 +102,7 @@ func TestQuerierRemoteRead(t *testing.T) {
102102
require.NoError(t, err)
103103
require.Equal(t, http.StatusOK, httpResp.StatusCode)
104104

105-
compressed, err = ioutil.ReadAll(httpResp.Body)
105+
compressed, err = io.ReadAll(httpResp.Body)
106106
require.NoError(t, err)
107107

108108
uncompressed, err := snappy.Decode(nil, compressed)

integration/util.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package integration
55

66
import (
77
"bytes"
8-
"io/ioutil"
98
"os"
109
"os/exec"
1110
"path/filepath"
@@ -44,14 +43,14 @@ func writeFileToSharedDir(s *e2e.Scenario, dst string, content []byte) error {
4443
return err
4544
}
4645

47-
return ioutil.WriteFile(
46+
return os.WriteFile(
4847
dst,
4948
content,
5049
os.ModePerm)
5150
}
5251

5352
func copyFileToSharedDir(s *e2e.Scenario, src, dst string) error {
54-
content, err := ioutil.ReadFile(filepath.Join(getCortexProjectDir(), src))
53+
content, err := os.ReadFile(filepath.Join(getCortexProjectDir(), src))
5554
if err != nil {
5655
return errors.Wrapf(err, "unable to read local file %s", src)
5756
}

pkg/alertmanager/alertmanager_http_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package alertmanager
22

33
import (
44
"context"
5-
"io/ioutil"
5+
"io"
66
"net/http/httptest"
77
"testing"
88
"time"
@@ -77,7 +77,7 @@ func TestMultitenantAlertmanager_GetStatusHandler(t *testing.T) {
7777

7878
resp := w.Result()
7979
require.Equal(t, 200, w.Code)
80-
body, _ := ioutil.ReadAll(resp.Body)
80+
body, _ := io.ReadAll(resp.Body)
8181
content := string(body)
8282
require.Contains(t, content, tt.content)
8383
require.NotContains(t, content, tt.nocontent)

0 commit comments

Comments
 (0)