Skip to content

Commit 9b67c62

Browse files
authored
refactor: remove deprecated ioutil references (#266)
io/ioutil was deprecated in Go 1.16. See https://tip.golang.org/doc/go1.16#ioutil This is needed to support newer version of golangci-lint because the linters are flagging the usage of io/ioutil as an issue. Because CI is using the linter for the lint job this is blocking the update to newer version of go.
1 parent 1575d79 commit 9b67c62

File tree

5 files changed

+12
-15
lines changed

5 files changed

+12
-15
lines changed

apm-lambda-extension/e2e-testing/e2e_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"flag"
2323
"fmt"
2424
"io"
25-
"io/ioutil"
2625
"net/http"
2726
"net/http/httptest"
2827
"os"
@@ -163,7 +162,7 @@ func retrieveJavaAgent(samJavaPath string, version string) {
163162
func changeJavaAgentPermissions(samJavaPath string) {
164163
agentFolderPath := filepath.Join(samJavaPath, "agent")
165164
extension.Log.Info("Setting appropriate permissions for Java agent files...")
166-
agentFiles, err := ioutil.ReadDir(agentFolderPath)
165+
agentFiles, err := os.ReadDir(agentFolderPath)
167166
ProcessError(err)
168167
for _, f := range agentFiles {
169168
if err = os.Chmod(filepath.Join(agentFolderPath, f.Name()), 0755); err != nil {

apm-lambda-extension/e2e-testing/e2e_util.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"bufio"
2323
"fmt"
2424
"io"
25-
"io/ioutil"
2625
"net"
2726
"net/http"
2827
"os"
@@ -154,7 +153,7 @@ func IsStringInSlice(a string, list []string) bool {
154153
func GetDecompressedBytesFromRequest(req *http.Request) ([]byte, error) {
155154
var rawBytes []byte
156155
if req.Body != nil {
157-
rawBytes, _ = ioutil.ReadAll(req.Body)
156+
rawBytes, _ = io.ReadAll(req.Body)
158157
}
159158
return apmproxy.GetUncompressedBytes(rawBytes, req.Header.Get("Content-Encoding"))
160159
}

apm-lambda-extension/extension/client_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package extension
1919

2020
import (
2121
"context"
22-
"io/ioutil"
22+
"io"
2323
"net/http"
2424
"net/http/httptest"
2525
"testing"
@@ -42,7 +42,7 @@ func TestRegister(t *testing.T) {
4242
`)
4343

4444
runtimeServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
45-
bytes, _ := ioutil.ReadAll(r.Body)
45+
bytes, _ := io.ReadAll(r.Body)
4646
assert.Equal(t, expectedRequest, string(bytes))
4747
if _, err := w.Write(response); err != nil {
4848
t.Fail()

apm-lambda-extension/extension/logger_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package extension
1919

2020
import (
21-
"io/ioutil"
2221
"os"
2322
"testing"
2423

@@ -36,7 +35,7 @@ func TestInitLogger(t *testing.T) {
3635
}
3736

3837
func TestDefaultLogger(t *testing.T) {
39-
tempFile, err := ioutil.TempFile(t.TempDir(), "tempFileLoggerTest-")
38+
tempFile, err := os.CreateTemp(t.TempDir(), "tempFileLoggerTest-")
4039
require.NoError(t, err)
4140
defer tempFile.Close()
4241

@@ -45,7 +44,7 @@ func TestDefaultLogger(t *testing.T) {
4544

4645
Log.Infof("%s", "logger-test-info")
4746
Log.Debugf("%s", "logger-test-debug")
48-
tempFileContents, err := ioutil.ReadFile(tempFile.Name())
47+
tempFileContents, err := os.ReadFile(tempFile.Name())
4948
require.NoError(t, err)
5049
assert.Regexp(t, `{"log.level":"info","@timestamp":".*","log.origin":{"file.name":"extension/logger_test.go","file.line":.*},"message":"logger-test-info","ecs.version":"1.6.0"}`, string(tempFileContents))
5150
}
@@ -71,7 +70,7 @@ func TestLoggerParseLogLevel(t *testing.T) {
7170
}
7271

7372
func TestLoggerSetLogLevel(t *testing.T) {
74-
tempFile, err := ioutil.TempFile(t.TempDir(), "tempFileLoggerTest-")
73+
tempFile, err := os.CreateTemp(t.TempDir(), "tempFileLoggerTest-")
7574
require.NoError(t, err)
7675
defer tempFile.Close()
7776

@@ -83,13 +82,13 @@ func TestLoggerSetLogLevel(t *testing.T) {
8382
defer SetLogOutputPaths([]string{"stderr"})
8483

8584
Log.Debugf("%s", "logger-test-trace")
86-
tempFileContents, err := ioutil.ReadFile(tempFile.Name())
85+
tempFileContents, err := os.ReadFile(tempFile.Name())
8786
require.NoError(t, err)
8887
assert.Regexp(t, `{"log.level":"debug","@timestamp":".*","log.origin":{"file.name":"extension/logger_test.go","file.line":.*},"message":"logger-test-trace","ecs.version":"1.6.0"}`, string(tempFileContents))
8988
}
9089

9190
func TestLoggerSetOffLevel(t *testing.T) {
92-
tempFile, err := ioutil.TempFile(t.TempDir(), "tempFileLoggerTest-")
91+
tempFile, err := os.CreateTemp(t.TempDir(), "tempFileLoggerTest-")
9392
require.NoError(t, err)
9493
defer tempFile.Close()
9594

@@ -102,7 +101,7 @@ func TestLoggerSetOffLevel(t *testing.T) {
102101
defer SetLogOutputPaths([]string{"stderr"})
103102

104103
Log.Errorf("%s", "logger-test-trace")
105-
tempFileContents, err := ioutil.ReadFile(tempFile.Name())
104+
tempFileContents, err := os.ReadFile(tempFile.Name())
106105
require.NoError(t, err)
107106
assert.Equal(t, "", string(tempFileContents))
108107
}

apm-lambda-extension/main_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"context"
2424
"encoding/json"
2525
"fmt"
26-
"io/ioutil"
26+
"io"
2727
"net/http"
2828
"net/http/httptest"
2929
"os"
@@ -280,7 +280,7 @@ func processMockEvent(currId string, event MockEvent, extensionPort string, inte
280280
}
281281
var rawBytes []byte
282282
if res.Body != nil {
283-
rawBytes, _ = ioutil.ReadAll(res.Body)
283+
rawBytes, _ = io.ReadAll(res.Body)
284284
}
285285
internals.Data += string(rawBytes)
286286
extension.Log.Debugf("Response seen by the agent : %d", res.StatusCode)

0 commit comments

Comments
 (0)