Skip to content
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

Bump Go version to 1.19.1 #3398

Merged
merged 5 commits into from
Sep 26, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
deprecate ioutil
sparrc committed Sep 22, 2022
commit c06033173efe6857864b3bdc501ac4f219301ca6
33 changes: 16 additions & 17 deletions ecs-init/cache/cache_test.go
Original file line number Diff line number Diff line change
@@ -22,7 +22,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"testing"
@@ -102,7 +101,7 @@ func TestIsAgentCachedTrue(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

file := ioutil.NopCloser(bytes.NewBufferString(fmt.Sprintf("%d", StatusCached)))
file := io.NopCloser(bytes.NewBufferString(fmt.Sprintf("%d", StatusCached)))
mockFS := NewMockfileSystem(mockCtrl)
mockFSInfo := NewMockfileSizeInfo(mockCtrl)
mockFS.EXPECT().Stat(config.CacheState()).Return(mockFSInfo, nil)
@@ -138,7 +137,7 @@ func TestAgentCacheStatus(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

file := ioutil.NopCloser(bytes.NewBufferString(testcase.data))
file := io.NopCloser(bytes.NewBufferString(testcase.data))
mockFS := NewMockfileSystem(mockCtrl)
mockFSInfo := NewMockfileSizeInfo(mockCtrl)

@@ -227,7 +226,7 @@ func TestDownloadAgentReadPublishedMd5Failure(t *testing.T) {
mockS3Downloader := NewMocks3DownloaderAPI(mockCtrl)
mockMetadata := NewMockinstanceMetadata(mockCtrl)

tempMD5File, err := ioutil.TempFile("", "md5-test")
tempMD5File, err := os.CreateTemp("", "md5-test")
assert.NoError(t, err, "Expect to successfully create a temporary file")
defer tempMD5File.Close()

@@ -259,11 +258,11 @@ func TestDownloadAgentDownloadTarballFailure(t *testing.T) {
mockS3Downloader := NewMocks3DownloaderAPI(mockCtrl)
mockMetadata := NewMockinstanceMetadata(mockCtrl)

tempMD5File, err := ioutil.TempFile("", "md5-test")
tempMD5File, err := os.CreateTemp("", "md5-test")
assert.NoError(t, err, "Expect to successfully create a temporary file")
defer tempMD5File.Close()

tempAgentFile, err := ioutil.TempFile("", "agent-test")
tempAgentFile, err := os.CreateTemp("", "agent-test")
assert.NoError(t, err, "Expect to successfully create a temporary file")
defer tempAgentFile.Close()

@@ -296,15 +295,15 @@ func TestDownloadAgentCopyFailure(t *testing.T) {
mockS3Downloader := NewMocks3DownloaderAPI(mockCtrl)
mockMetadata := NewMockinstanceMetadata(mockCtrl)

tempMD5File, err := ioutil.TempFile("", "md5-test")
tempMD5File, err := os.CreateTemp("", "md5-test")
assert.NoError(t, err, "Expect to successfully create a temporary file")
defer tempMD5File.Close()

tempAgentFile, err := ioutil.TempFile("", "agent-test")
tempAgentFile, err := os.CreateTemp("", "agent-test")
assert.NoError(t, err, "Expect to successfully create a temporary file")
defer tempAgentFile.Close()

tempReader := ioutil.NopCloser(&bytes.Buffer{})
tempReader := io.NopCloser(&bytes.Buffer{})

gomock.InOrder(
mockFS.EXPECT().MkdirAll(config.CacheDirectory(), os.ModeDir|0700),
@@ -339,15 +338,15 @@ func TestDownloadAgentMD5Mismatch(t *testing.T) {
mockS3Downloader := NewMocks3DownloaderAPI(mockCtrl)
mockMetadata := NewMockinstanceMetadata(mockCtrl)

tempMD5File, err := ioutil.TempFile("", "md5-test")
tempMD5File, err := os.CreateTemp("", "md5-test")
assert.NoError(t, err, "Expect to successfully create a temporary file")
defer tempMD5File.Close()

tempAgentFile, err := ioutil.TempFile("", "agent-test")
tempAgentFile, err := os.CreateTemp("", "agent-test")
assert.NoError(t, err, "Expect to successfully create a temporary file")
defer tempAgentFile.Close()

tempReader := ioutil.NopCloser(&bytes.Buffer{})
tempReader := io.NopCloser(&bytes.Buffer{})

gomock.InOrder(
mockFS.EXPECT().MkdirAll(config.CacheDirectory(), os.ModeDir|0700),
@@ -377,14 +376,14 @@ func TestDownloadAgentSuccess(t *testing.T) {
defer mockCtrl.Finish()

tarballContents := "tarball contents"
tarballReader := ioutil.NopCloser(bytes.NewBufferString(tarballContents))
tarballReader := io.NopCloser(bytes.NewBufferString(tarballContents))
expectedMd5Sum := fmt.Sprintf("%x\n", md5.Sum([]byte(tarballContents)))

tempMD5File, err := ioutil.TempFile("", "md5-test")
tempMD5File, err := os.CreateTemp("", "md5-test")
assert.NoError(t, err, "Expect to successfully create a temporary file")
defer tempMD5File.Close()

tempAgentFile, err := ioutil.TempFile("", "agent-test")
tempAgentFile, err := os.CreateTemp("", "agent-test")
assert.NoError(t, err, "Expect to successfully create a temporary file")
defer tempAgentFile.Close()

@@ -440,7 +439,7 @@ func TestLoadDesiredAgentFailReadDesired(t *testing.T) {

mockFS := NewMockfileSystem(mockCtrl)

mockFS.EXPECT().Open(config.DesiredImageLocatorFile()).Return(ioutil.NopCloser(&bytes.Buffer{}), nil)
mockFS.EXPECT().Open(config.DesiredImageLocatorFile()).Return(io.NopCloser(&bytes.Buffer{}), nil)

d := &Downloader{
fs: mockFS,
@@ -472,7 +471,7 @@ func TestLoadDesiredAgent(t *testing.T) {

mockFS := NewMockfileSystem(mockCtrl)

mockFS.EXPECT().Open(config.DesiredImageLocatorFile()).Return(ioutil.NopCloser(bytes.NewBufferString(desiredImage+"\n")), nil)
mockFS.EXPECT().Open(config.DesiredImageLocatorFile()).Return(io.NopCloser(bytes.NewBufferString(desiredImage+"\n")), nil)
mockFS.EXPECT().Base(gomock.Any()).Return(desiredImage + "\n")
mockFS.EXPECT().Open(config.CacheDirectory() + "/" + desiredImage)

9 changes: 4 additions & 5 deletions ecs-init/cache/dependencies.go
Original file line number Diff line number Diff line change
@@ -22,7 +22,6 @@ package cache

import (
"io"
"io/ioutil"
"os"
"path/filepath"

@@ -118,7 +117,7 @@ func (d *s3Downloader) downloadFile(fileName string) (string, error) {
return "", errors.New("failed to download file from s3")
}

// fileSystem captures related functions from os, io, and io/ioutil packages
// fileSystem captures related functions from io and os packages
type fileSystem interface {
MkdirAll(path string, perm os.FileMode) error
TempFile(dir, prefix string) (f *os.File, err error)
@@ -156,7 +155,7 @@ func (s *standardFS) MkdirAll(path string, perm os.FileMode) error {
}

func (s *standardFS) TempFile(dir, prefix string) (*os.File, error) {
return ioutil.TempFile(dir, prefix)
return os.CreateTemp(dir, prefix)
}

func (s *standardFS) Remove(path string) {
@@ -176,7 +175,7 @@ func (s *standardFS) Rename(oldpath, newpath string) error {
}

func (s *standardFS) ReadAll(r io.Reader) ([]byte, error) {
return ioutil.ReadAll(r)
return io.ReadAll(r)
}

func (s *standardFS) Open(name string) (io.ReadCloser, error) {
@@ -192,5 +191,5 @@ func (s *standardFS) Base(path string) string {
}

func (s *standardFS) WriteFile(filename string, data []byte, perm os.FileMode) error {
return ioutil.WriteFile(filename, data, perm)
return os.WriteFile(filename, data, perm)
}
4 changes: 2 additions & 2 deletions ecs-init/docker/dependencies.go
Original file line number Diff line number Diff line change
@@ -16,10 +16,10 @@ package docker
//go:generate mockgen.sh $GOPACKAGE $GOFILE

import (
"io/ioutil"
"net"
"net/http"
"net/url"
"os"
"time"

"github.com/aws/amazon-ecs-agent/ecs-init/backoff"
@@ -142,7 +142,7 @@ type _standardFS struct{}
var standardFS = &_standardFS{}

func (s *_standardFS) ReadFile(filename string) ([]byte, error) {
return ioutil.ReadFile(filename)
return os.ReadFile(filename)
}

func isNetworkError(err error) bool {
5 changes: 2 additions & 3 deletions ecs-init/docker/docker_test.go
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@ package docker

import (
"errors"
"io/ioutil"
"os"
"path/filepath"
"testing"
@@ -945,13 +944,13 @@ func TestGetCapabilityExecBinds(t *testing.T) {
}

func TestDefaultIsPathValid(t *testing.T) {
rootDir, err := ioutil.TempDir(os.TempDir(), testTempDirPrefix)
rootDir, err := os.MkdirTemp(os.TempDir(), testTempDirPrefix)
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(rootDir)

file, err := ioutil.TempFile(rootDir, "file")
file, err := os.CreateTemp(rootDir, "file")
if err != nil {
t.Fatal(err)
}
12 changes: 6 additions & 6 deletions ecs-init/engine/engine_test.go
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"io"
"os"
"testing"

@@ -79,7 +79,7 @@ func TestPreStartReloadNeeded(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

cachedAgentBuffer := ioutil.NopCloser(&bytes.Buffer{})
cachedAgentBuffer := io.NopCloser(&bytes.Buffer{})

mockDocker := NewMockdockerClient(mockCtrl)
defer getDockerClientMock(mockDocker)()
@@ -117,7 +117,7 @@ func TestPreStartImageNotLoadedCached(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

cachedAgentBuffer := ioutil.NopCloser(&bytes.Buffer{})
cachedAgentBuffer := io.NopCloser(&bytes.Buffer{})

mockDocker := NewMockdockerClient(mockCtrl)
mockDownloader := NewMockdownloader(mockCtrl)
@@ -152,7 +152,7 @@ func TestPreStartImageNotCached(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

cachedAgentBuffer := ioutil.NopCloser(&bytes.Buffer{})
cachedAgentBuffer := io.NopCloser(&bytes.Buffer{})

mockDocker := NewMockdockerClient(mockCtrl)
defer getDockerClientMock(mockDocker)()
@@ -431,7 +431,7 @@ func TestReloadCacheNotCached(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

cachedAgentBuffer := ioutil.NopCloser(&bytes.Buffer{})
cachedAgentBuffer := io.NopCloser(&bytes.Buffer{})

mockDocker := NewMockdockerClient(mockCtrl)
defer getDockerClientMock(mockDocker)()
@@ -456,7 +456,7 @@ func TestReloadCacheCached(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()

cachedAgentBuffer := ioutil.NopCloser(&bytes.Buffer{})
cachedAgentBuffer := io.NopCloser(&bytes.Buffer{})

mockDocker := NewMockdockerClient(mockCtrl)
defer getDockerClientMock(mockDocker)()
3 changes: 1 addition & 2 deletions ecs-init/gpu/nvidia_gpu_manager.go
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@ package gpu

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"

@@ -219,5 +218,5 @@ func WriteToFile(filename string, data []byte, perm os.FileMode) error {
if err != nil {
return err
}
return ioutil.WriteFile(filename, data, perm)
return os.WriteFile(filename, data, perm)
}
5 changes: 2 additions & 3 deletions ecs-init/volumes/state_manager.go
Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@ package volumes
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"sync"
@@ -94,7 +93,7 @@ var saveStateToDisk = saveState
func saveState(b []byte) error {
// Make our temp-file on the same volume as our data-file to ensure we can
// actually move it atomically; cross-device renaming will error out
tmpfile, err := ioutil.TempFile(PluginStatePath, "tmp_ecs_volume_plugin")
tmpfile, err := os.CreateTemp(PluginStatePath, "tmp_ecs_volume_plugin")
if err != nil {
return fmt.Errorf("failed to create temp file: %v", err)
}
@@ -154,5 +153,5 @@ func (s *StateManager) load(a interface{}) error {
var readStateFile = readFile

func readFile() ([]byte, error) {
return ioutil.ReadFile(PluginStateFileAbsPath)
return os.ReadFile(PluginStateFileAbsPath)
}