Skip to content

lint: remove io/ioutil #496

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ jobs:
- "1.18"
- "1.17"
- "1.16"
- "1.15"
- "1.14"
- "1.13"

steps:
- name: Set up Go ${{ matrix.go }}
Expand Down
4 changes: 2 additions & 2 deletions cfn/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package cfn

import (
"encoding/json"
"io/ioutil" //nolint: staticcheck
"os"
"testing"

"github.com/aws/aws-lambda-go/events/test"
Expand All @@ -13,7 +13,7 @@ import (
func TestCloudFormationEventMarshaling(t *testing.T) {

// read json from file
inputJSON, err := ioutil.ReadFile("./testdata/cloudformation-event.json")
inputJSON, err := os.ReadFile("./testdata/cloudformation-event.json")
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cfn/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil" //nolint: staticcheck
"io"
"log"
"net/http"
)
Expand Down Expand Up @@ -67,7 +67,7 @@ func (r *Response) sendWith(client httpClient) error {
return err
}

body, err = ioutil.ReadAll(res.Body)
body, err = io.ReadAll(res.Body)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cfn/wrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"context"
"encoding/json"
"errors"
"io/ioutil" //nolint: staticcheck
"io"
"net/http"
"testing"

Expand Down Expand Up @@ -151,7 +151,7 @@ func TestWrappedSendFailure(t *testing.T) {
func extractResponseBody(t *testing.T, req *http.Request) Response {
assert.NotContains(t, req.Header, "Content-Type")

body, err := ioutil.ReadAll(req.Body)
body, err := io.ReadAll(req.Body)
assert.NoError(t, err)
var response Response
err = json.Unmarshal(body, &response)
Expand Down
5 changes: 2 additions & 3 deletions cmd/build-lambda-zip/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"archive/zip"
"flag"
"fmt"
"io/ioutil" //nolint: staticcheck
"log"
"os"
"path/filepath"
Expand Down Expand Up @@ -82,7 +81,7 @@ func compressExeAndArgs(outZipPath string, exePath string, args []string) error

zipWriter := zip.NewWriter(zipFile)
defer zipWriter.Close()
data, err := ioutil.ReadFile(exePath)
data, err := os.ReadFile(exePath)
if err != nil {
return err
}
Expand All @@ -97,7 +96,7 @@ func compressExeAndArgs(outZipPath string, exePath string, args []string) error
if err != nil {
return err
}
data, err := ioutil.ReadFile(arg)
data, err := os.ReadFile(arg)
if err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/build-lambda-zip/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package main
import (
"archive/zip"
"fmt"
"io/ioutil" //nolint: staticcheck
"io"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -34,7 +34,7 @@ func TestSizes(t *testing.T) {
}
testDir, err := os.Getwd()
require.NoError(t, err)
tempDir, err := ioutil.TempDir("/tmp", "build-lambda-zip")
tempDir, err := os.MkdirTemp("/tmp", "build-lambda-zip")
require.NoError(t, err)
for _, test := range cases {
require.NoError(t, os.Chdir(testDir))
Expand Down Expand Up @@ -66,7 +66,7 @@ func TestSizes(t *testing.T) {
}

func TestCompressExeAndArgs(t *testing.T) {
tempDir, err := ioutil.TempDir("/tmp", "build-lambda-zip")
tempDir, err := os.MkdirTemp("/tmp", "build-lambda-zip")
require.NoError(t, err)
defer os.RemoveAll(tempDir)

Expand Down Expand Up @@ -117,7 +117,7 @@ func TestCompressExeAndArgs(t *testing.T) {
link, err := bootstrap.Open()
require.NoError(t, err)
defer link.Close()
linkTarget, err := ioutil.ReadAll(link)
linkTarget, err := io.ReadAll(link)
require.NoError(t, err)
assert.Equal(t, filepath.Base(filePaths[0]), string(linkTarget))
})
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestCompressExeAndArgs(t *testing.T) {
f, err := zf.Open()
require.NoError(t, err)
defer f.Close()
content, err := ioutil.ReadAll(f)
content, err := io.ReadAll(f)
require.NoError(t, err)
assert.Equal(t, fmt.Sprintf("Hello file %d!", expectedIndex), string(content), "in file: %s", zf.Name)
expectedIndex++
Expand Down
6 changes: 3 additions & 3 deletions events/alb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package events

import (
"encoding/json"
"io/ioutil" //nolint: staticcheck
"os"
"testing"

"github.com/aws/aws-lambda-go/events/test"
Expand All @@ -16,7 +16,7 @@ func TestALBTargetRequestMarshaling(t *testing.T) {

for _, filename := range inputFiles {
// read json from file
inputJSON, err := ioutil.ReadFile(filename)
inputJSON, err := os.ReadFile(filename)
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}
Expand All @@ -43,7 +43,7 @@ func TestALBTargetRequestMalformedJson(t *testing.T) {
func TestALBTargetResponseMarshaling(t *testing.T) {

// read json from file
inputJSON, err := ioutil.ReadFile("./testdata/alb-lambda-target-response.json")
inputJSON, err := os.ReadFile("./testdata/alb-lambda-target-response.json")
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}
Expand Down
28 changes: 14 additions & 14 deletions events/apigw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package events

import (
"encoding/json"
"io/ioutil" //nolint: staticcheck
"os"
"testing"

"github.com/aws/aws-lambda-go/events/test"
Expand All @@ -14,7 +14,7 @@ import (
func TestApiGatewayRequestMarshaling(t *testing.T) {

// read json from file
inputJSON, err := ioutil.ReadFile("./testdata/apigw-request.json")
inputJSON, err := os.ReadFile("./testdata/apigw-request.json")
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}
Expand Down Expand Up @@ -49,7 +49,7 @@ func TestApiGatewayRequestMalformedJson(t *testing.T) {
func TestApiGatewayResponseMarshaling(t *testing.T) {

// read json from file
inputJSON, err := ioutil.ReadFile("./testdata/apigw-response.json")
inputJSON, err := os.ReadFile("./testdata/apigw-response.json")
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}
Expand All @@ -76,7 +76,7 @@ func TestApiGatewayResponseMalformedJson(t *testing.T) {
func TestApiGatewayCustomAuthorizerRequestMarshaling(t *testing.T) {

// read json from file
inputJSON, err := ioutil.ReadFile("./testdata/apigw-custom-auth-request.json")
inputJSON, err := os.ReadFile("./testdata/apigw-custom-auth-request.json")
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}
Expand All @@ -99,7 +99,7 @@ func TestApiGatewayCustomAuthorizerRequestMarshaling(t *testing.T) {
func TestApiGatewayCustomAuthorizerRequestTypeRequestMarshaling(t *testing.T) {

// read json from file
inputJSON, err := ioutil.ReadFile("./testdata/apigw-custom-auth-request-type-request.json")
inputJSON, err := os.ReadFile("./testdata/apigw-custom-auth-request-type-request.json")
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}
Expand Down Expand Up @@ -130,7 +130,7 @@ func TestApiGatewayCustomAuthorizerRequestTypeRequestMalformedJson(t *testing.T)
func TestApiGatewayWebsocketRequestMarshaling(t *testing.T) {

// read json from file
inputJSON, err := ioutil.ReadFile("./testdata/apigw-websocket-request.json")
inputJSON, err := os.ReadFile("./testdata/apigw-websocket-request.json")
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}
Expand All @@ -157,7 +157,7 @@ func TestApiGatewayWebsocketRequestMalformedJson(t *testing.T) {
func TestApiGatewayCustomAuthorizerResponseMarshaling(t *testing.T) {

// read json from file
inputJSON, err := ioutil.ReadFile("./testdata/apigw-custom-auth-response.json")
inputJSON, err := os.ReadFile("./testdata/apigw-custom-auth-response.json")
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}
Expand Down Expand Up @@ -245,7 +245,7 @@ func TestApiGatewayCustomAuthorizerResponseMalformedJson(t *testing.T) {
func TestApiGatewayRestApiOpenApiRequestMarshaling(t *testing.T) {

// read json from file
inputJSON, err := ioutil.ReadFile("./testdata/apigw-restapi-openapi-request.json")
inputJSON, err := os.ReadFile("./testdata/apigw-restapi-openapi-request.json")
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}
Expand Down Expand Up @@ -274,7 +274,7 @@ func TestApiGatewayRestApiOpenApiRequestMarshaling(t *testing.T) {
func TestApiGatewayV2HTTPRequestJWTAuthorizerMarshaling(t *testing.T) {

// read json from file
inputJSON, err := ioutil.ReadFile("./testdata/apigw-v2-request-jwt-authorizer.json")
inputJSON, err := os.ReadFile("./testdata/apigw-v2-request-jwt-authorizer.json")
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}
Expand Down Expand Up @@ -309,7 +309,7 @@ func TestApiGatewayV2HTTPRequestJWTAuthorizerMarshaling(t *testing.T) {
func TestApiGatewayV2HTTPRequestLambdaAuthorizerMarshaling(t *testing.T) {

// read json from file
inputJSON, err := ioutil.ReadFile("./testdata/apigw-v2-request-lambda-authorizer.json")
inputJSON, err := os.ReadFile("./testdata/apigw-v2-request-lambda-authorizer.json")
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}
Expand Down Expand Up @@ -344,7 +344,7 @@ func TestApiGatewayV2HTTPRequestLambdaAuthorizerMarshaling(t *testing.T) {
func TestApiGatewayV2HTTPRequestIAMMarshaling(t *testing.T) {

// read json from file
inputJSON, err := ioutil.ReadFile("./testdata/apigw-v2-request-iam.json")
inputJSON, err := os.ReadFile("./testdata/apigw-v2-request-iam.json")
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}
Expand Down Expand Up @@ -403,7 +403,7 @@ func TestApiGatewayV2HTTPRequestIAMMarshaling(t *testing.T) {
func TestApiGatewayV2HTTPRequestNoAuthorizerMarshaling(t *testing.T) {

// read json from file
inputJSON, err := ioutil.ReadFile("./testdata/apigw-v2-request-no-authorizer.json")
inputJSON, err := os.ReadFile("./testdata/apigw-v2-request-no-authorizer.json")
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}
Expand Down Expand Up @@ -436,7 +436,7 @@ func TestApiGatewayV2HTTPRequestNoAuthorizerMarshaling(t *testing.T) {
}

func TestApiGatewayV2CustomAuthorizerV1RequestMarshaling(t *testing.T) {
inputJSON, err := ioutil.ReadFile("./testdata/apigw-v2-custom-authorizer-v1-request.json")
inputJSON, err := os.ReadFile("./testdata/apigw-v2-custom-authorizer-v1-request.json")
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}
Expand All @@ -457,7 +457,7 @@ func TestApiGatewayV2CustomAuthorizerV1RequestMarshaling(t *testing.T) {
}

func TestApiGatewayV2CustomAuthorizerV2RequestMarshaling(t *testing.T) {
inputJSON, err := ioutil.ReadFile("./testdata/apigw-v2-custom-authorizer-v2-request.json")
inputJSON, err := os.ReadFile("./testdata/apigw-v2-custom-authorizer-v2-request.json")
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}
Expand Down
10 changes: 5 additions & 5 deletions events/appsync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package events

import (
"encoding/json"
"io/ioutil" //nolint: staticcheck
"os"
"testing"

"github.com/aws/aws-lambda-go/events/test"
"github.com/stretchr/testify/assert"
)

func TestAppSyncIdentity_IAM(t *testing.T) {
inputJSON, err := ioutil.ReadFile("./testdata/appsync-identity-iam.json")
inputJSON, err := os.ReadFile("./testdata/appsync-identity-iam.json")
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}
Expand All @@ -29,7 +29,7 @@ func TestAppSyncIdentity_IAM(t *testing.T) {
}

func TestAppSyncIdentity_Cognito(t *testing.T) {
inputJSON, err := ioutil.ReadFile("./testdata/appsync-identity-cognito.json")
inputJSON, err := os.ReadFile("./testdata/appsync-identity-cognito.json")
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}
Expand All @@ -48,7 +48,7 @@ func TestAppSyncIdentity_Cognito(t *testing.T) {
}

func TestAppSyncLambdaAuthorizerRequestMarshalling(t *testing.T) {
inputJSON, err := ioutil.ReadFile("./testdata/appsync-lambda-auth-request.json")
inputJSON, err := os.ReadFile("./testdata/appsync-lambda-auth-request.json")
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}
Expand All @@ -71,7 +71,7 @@ func TestAppSyncLambdaAuthorizerRequestMalformedJson(t *testing.T) {
}

func TestAppSyncLambdaAuthorizerResponseMarshalling(t *testing.T) {
inputJSON, err := ioutil.ReadFile("./testdata/appsync-lambda-auth-response.json")
inputJSON, err := os.ReadFile("./testdata/appsync-lambda-auth-response.json")
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions events/clientvpn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package events

import (
"encoding/json"
"io/ioutil" //nolint: staticcheck
"os"
"testing"

"github.com/aws/aws-lambda-go/events/test"
Expand All @@ -11,7 +11,7 @@ import (

func TestClientVPNConnectionHandlerRequestMarshaling(t *testing.T) {
// read json from file
inputJSON, err := ioutil.ReadFile("./testdata/clientvpn-connectionhandler-request.json")
inputJSON, err := os.ReadFile("./testdata/clientvpn-connectionhandler-request.json")
if err != nil {
t.Errorf("could not open test file. details: %v", err)
}
Expand Down
4 changes: 2 additions & 2 deletions events/codebuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package events

import (
"encoding/json"
"io/ioutil" //nolint: staticcheck
"os"
"testing"
"time"

Expand Down Expand Up @@ -301,7 +301,7 @@ func TestUnmarshalCodeBuildEvent(t *testing.T) {
}

for _, testcase := range tests {
data, err := ioutil.ReadFile(testcase.input)
data, err := os.ReadFile(testcase.input)
require.NoError(t, err)

var actual CodeBuildEvent
Expand Down
4 changes: 2 additions & 2 deletions events/codedeploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package events
import (
"encoding/json"
"github.com/stretchr/testify/require"
"io/ioutil" //nolint: staticcheck
"os"
"testing"
"time"
)
Expand Down Expand Up @@ -67,7 +67,7 @@ func TestUnmarshalCodeDeployEvent(t *testing.T) {
}

for _, testcase := range tests {
data, err := ioutil.ReadFile(testcase.input)
data, err := os.ReadFile(testcase.input)
require.NoError(t, err)

var actual CodeDeployEvent
Expand Down
Loading