Skip to content

Commit

Permalink
EVG-18584 Upgrade go to go1.19 (#6285)
Browse files Browse the repository at this point in the history
  • Loading branch information
ybrill committed Feb 27, 2023
1 parent 507da8c commit e1789d9
Show file tree
Hide file tree
Showing 169 changed files with 638 additions and 601 deletions.
6 changes: 0 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@ linters:
disable-all: true
enable:
- asciicheck
- deadcode
- errcheck
- ineffassign
- goimports
- gosimple
- govet
- misspell
- structcheck
- unconvert
- unused

linters-settings:
govet:
check-shadowing: false
5 changes: 2 additions & 3 deletions agent/agent_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package agent

import (
"context"
"io/ioutil"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -80,7 +79,7 @@ func (s *CommandSuite) TestPreErrorFailsWithSetup() {
}

func (s *CommandSuite) TestShellExec() {
f, err := ioutil.TempFile(s.tmpDirName, "shell-exec-")
f, err := os.CreateTemp(s.tmpDirName, "shell-exec-")
s.Require().NoError(err)
defer os.Remove(f.Name())

Expand Down Expand Up @@ -122,7 +121,7 @@ func (s *CommandSuite) TestShellExec() {
s.Contains(detail.Description, "shell.exec")
s.False(detail.TimedOut)

data, err := ioutil.ReadFile(tmpFile)
data, err := os.ReadFile(tmpFile)
s.Require().NoError(err)
s.Equal("shell.exec test message", strings.Trim(string(data), "\r\n"))

Expand Down
3 changes: 1 addition & 2 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package agent
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -75,7 +74,7 @@ func (s *AgentSuite) SetupTest() {
factory, ok := command.GetCommandFactory("setup.initial")
s.True(ok)
s.tc.setCurrentCommand(factory())
s.tmpDirName, err = ioutil.TempDir("", filepath.Base(s.T().Name()))
s.tmpDirName, err = os.MkdirTemp("", filepath.Base(s.T().Name()))
s.Require().NoError(err)
s.tc.taskDirectory = s.tmpDirName
sender, err := s.a.GetSender(ctx, evergreen.LocalLoggingOverride)
Expand Down
15 changes: 7 additions & 8 deletions agent/agent_timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package agent

import (
"context"
"io/ioutil"
"os"
"strings"
"testing"
Expand Down Expand Up @@ -43,7 +42,7 @@ func (s *TimeoutSuite) SetupTest() {
var err error

s.tmpDirName = s.T().TempDir()
s.tmpFile, err = ioutil.TempFile(s.tmpDirName, "timeout")
s.tmpFile, err = os.CreateTemp(s.tmpDirName, "timeout")
s.Require().NoError(err)

s.tmpFileName = s.tmpFile.Name()
Expand Down Expand Up @@ -115,7 +114,7 @@ func (s *TimeoutSuite) TestExecTimeoutProject() {
s.Equal(1*time.Second, detail.TimeoutDuration)
s.EqualValues(execTimeout, detail.TimeoutType)

data, err := ioutil.ReadFile(s.tmpFileName)
data, err := os.ReadFile(s.tmpFileName)
s.Require().NoError(err)
s.Equal("timeout test message", strings.Trim(string(data), "\r\n"))

Expand Down Expand Up @@ -183,7 +182,7 @@ func (s *TimeoutSuite) TestExecTimeoutTask() {
s.Equal(1*time.Second, detail.TimeoutDuration)
s.EqualValues(execTimeout, detail.TimeoutType)

data, err := ioutil.ReadFile(s.tmpFileName)
data, err := os.ReadFile(s.tmpFileName)
s.Require().NoError(err)
s.Equal("timeout test message", strings.Trim(string(data), "\r\n"))

Expand Down Expand Up @@ -250,7 +249,7 @@ func (s *TimeoutSuite) TestIdleTimeoutFunc() {
s.Equal(1*time.Second, detail.TimeoutDuration)
s.EqualValues(idleTimeout, detail.TimeoutType)

data, err := ioutil.ReadFile(s.tmpFileName)
data, err := os.ReadFile(s.tmpFileName)
s.Require().NoError(err)
s.Equal("timeout test message", strings.Trim(string(data), "\r\n"))

Expand Down Expand Up @@ -317,7 +316,7 @@ func (s *TimeoutSuite) TestIdleTimeoutCommand() {
s.Equal(1*time.Second, detail.TimeoutDuration)
s.EqualValues(idleTimeout, detail.TimeoutType)

data, err := ioutil.ReadFile(s.tmpFileName)
data, err := os.ReadFile(s.tmpFileName)
s.Require().NoError(err)
s.Equal("timeout test message", strings.Trim(string(data), "\r\n"))

Expand Down Expand Up @@ -384,7 +383,7 @@ func (s *TimeoutSuite) TestDynamicIdleTimeout() {
s.Equal(2*time.Second, detail.TimeoutDuration)
s.EqualValues(idleTimeout, detail.TimeoutType)

data, err := ioutil.ReadFile(s.tmpFileName)
data, err := os.ReadFile(s.tmpFileName)
s.Require().NoError(err)
s.Equal("timeout test message", strings.Trim(string(data), "\r\n"))

Expand Down Expand Up @@ -451,7 +450,7 @@ func (s *TimeoutSuite) TestDynamicExecTimeoutTask() {
s.Equal(2*time.Second, detail.TimeoutDuration)
s.EqualValues(execTimeout, detail.TimeoutType)

data, err := ioutil.ReadFile(s.tmpFileName)
data, err := os.ReadFile(s.tmpFileName)
s.Require().NoError(err)
s.Equal("timeout test message", strings.Trim(string(data), "\r\n"))

Expand Down
3 changes: 1 addition & 2 deletions agent/command/archive_tarball_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package command

import (
"context"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -101,7 +100,7 @@ func TestTarGzCommandMakeArchive(t *testing.T) {

Convey("the correct files should be included and excluded", func() {

target, err := ioutil.TempFile("", "target.tgz")
target, err := os.CreateTemp("", "target.tgz")
require.NoError(t, err)
defer func() {
assert.NoError(t, os.RemoveAll(target.Name()))
Expand Down
9 changes: 4 additions & 5 deletions agent/command/attach_artifacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package command

import (
"context"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -138,10 +137,10 @@ func (s *ArtifactsSuite) TestCommandParsesFile() {

func (s *ArtifactsSuite) TestPrefixectoryEmptySubDir() {
dir := s.T().TempDir()
err := ioutil.WriteFile(filepath.Join(dir, "foo"), []byte("[{}]"), 0644)
err := os.WriteFile(filepath.Join(dir, "foo"), []byte("[{}]"), 0644)
s.Require().NoError(err)
s.Require().NoError(os.Mkdir(filepath.Join(dir, "subDir"), 0755))
err = ioutil.WriteFile(filepath.Join(dir, "subDir", "bar"), []byte("[{}]"), 0644)
err = os.WriteFile(filepath.Join(dir, "subDir", "bar"), []byte("[{}]"), 0644)
s.Require().NoError(err)
s.conf.WorkDir = dir
s.cmd.Files = []string{"*"}
Expand All @@ -151,10 +150,10 @@ func (s *ArtifactsSuite) TestPrefixectoryEmptySubDir() {

func (s *ArtifactsSuite) TestPrefixectoryWithSubDir() {
dir := s.T().TempDir()
err := ioutil.WriteFile(filepath.Join(dir, "foo"), []byte("[{}]"), 0644)
err := os.WriteFile(filepath.Join(dir, "foo"), []byte("[{}]"), 0644)
s.Require().NoError(err)
s.Require().NoError(os.Mkdir(filepath.Join(dir, "subDir"), 0755))
err = ioutil.WriteFile(filepath.Join(dir, "subDir", "bar"), []byte("[{}]"), 0644)
err = os.WriteFile(filepath.Join(dir, "subDir", "bar"), []byte("[{}]"), 0644)
s.Require().NoError(err)
s.conf.WorkDir = dir
s.cmd.Files = []string{"*"}
Expand Down
4 changes: 2 additions & 2 deletions agent/command/command_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package command

import (
"io/ioutil"
"os"
"testing"

"github.com/evergreen-ci/evergreen"
Expand All @@ -12,7 +12,7 @@ import (

func setupTestPatchData(apiData *modelutil.TestModelData, patchPath string, t *testing.T) error {
if patchPath != "" {
modulePatchContent, err := ioutil.ReadFile(patchPath)
modulePatchContent, err := os.ReadFile(patchPath)
require.NoError(t, err)

patch := &patch.Patch{
Expand Down
3 changes: 1 addition & 2 deletions agent/command/downstream_expansions_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package command

import (
"context"
"io/ioutil"
"os"

"github.com/evergreen-ci/evergreen"
Expand Down Expand Up @@ -87,7 +86,7 @@ func (c *setDownstream) Execute(ctx context.Context,
}

func (c *setDownstream) ParseFromFile(filename string) error {
filedata, err := ioutil.ReadFile(filename)
filedata, err := os.ReadFile(filename)
if err != nil {
return err
}
Expand Down
7 changes: 3 additions & 4 deletions agent/command/expansion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package command

import (
"context"
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -93,21 +92,21 @@ func TestExpansionWriter(t *testing.T) {
"password": true,
},
}
f, err := ioutil.TempFile("", t.Name())
f, err := os.CreateTemp("", t.Name())
require.NoError(err)
defer os.Remove(f.Name())

writer := &expansionsWriter{File: f.Name()}
err = writer.Execute(ctx, comm, logger, tc)
assert.NoError(err)
out, err := ioutil.ReadFile(f.Name())
out, err := os.ReadFile(f.Name())
assert.NoError(err)
assert.Equal("baz: qux\nfoo: bar\n", string(out))

writer = &expansionsWriter{File: f.Name(), Redacted: true}
err = writer.Execute(ctx, comm, logger, tc)
assert.NoError(err)
out, err = ioutil.ReadFile(f.Name())
out, err = os.ReadFile(f.Name())
assert.NoError(err)
assert.Equal("baz: qux\nfoo: bar\npassword: hunter2\n", string(out))
}
4 changes: 2 additions & 2 deletions agent/command/expansion_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package command

import (
"context"
"io/ioutil"
"os"

"github.com/evergreen-ci/evergreen"
"github.com/evergreen-ci/evergreen/agent/internal"
Expand Down Expand Up @@ -60,7 +60,7 @@ func (c *expansionsWriter) Execute(ctx context.Context,
return errors.Wrap(err, "marshalling expansions")
}
fn := getJoinedWithWorkDir(conf, c.File)
if err := ioutil.WriteFile(fn, out, 0600); err != nil {
if err := os.WriteFile(fn, out, 0600); err != nil {
return errors.Wrapf(err, "writing expansions to file '%s'", fn)
}
logger.Task().Infof("Expansions written to file '%s'.", fn)
Expand Down
4 changes: 2 additions & 2 deletions agent/command/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package command
import (
"context"
"encoding/json"
"io/ioutil"
"io"
"os"
"strings"
"time"
Expand Down Expand Up @@ -146,7 +146,7 @@ func generateTaskForFile(fn string, conf *internal.TaskConfig) ([]byte, error) {
defer jsonFile.Close()

var data []byte
data, err = ioutil.ReadAll(jsonFile)
data, err = io.ReadAll(jsonFile)
if err != nil {
return nil, errors.Wrapf(err, "reading from file '%s'", fn)
}
Expand Down
9 changes: 4 additions & 5 deletions agent/command/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package command
import (
"context"
"encoding/json"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -92,7 +91,7 @@ func (s *generateSuite) TestExecuteFileDoesNotExist() {
}

func (s *generateSuite) TestExecuteFailsWithGeneratePollError() {
f, err := ioutil.TempFile(s.tmpDirName, "")
f, err := os.CreateTemp(s.tmpDirName, "")
s.Require().NoError(err)
tmpFile := f.Name()
tmpFileBase := filepath.Base(tmpFile)
Expand All @@ -109,7 +108,7 @@ func (s *generateSuite) TestExecuteFailsWithGeneratePollError() {
}

func (s *generateSuite) TestExecuteSuccess() {
f, err := ioutil.TempFile(s.tmpDirName, "")
f, err := os.CreateTemp(s.tmpDirName, "")
s.Require().NoError(err)
tmpFile := f.Name()
tmpFileBase := filepath.Base(tmpFile)
Expand All @@ -133,7 +132,7 @@ func (s *generateSuite) TestOptional() {
}

func (s *generateSuite) TestExecuteSuccessWithValidGlobbing() {
f, err := ioutil.TempFile(s.tmpDirName, "")
f, err := os.CreateTemp(s.tmpDirName, "")
s.Require().NoError(err)
tmpFile := f.Name()
defer os.Remove(tmpFile)
Expand Down Expand Up @@ -161,7 +160,7 @@ func (s *generateSuite) TestErrorWithInvalidExpansions() {
}

func (s *generateSuite) TestNoErrorWithValidExpansions() {
f, err := ioutil.TempFile(s.tmpDirName, "")
f, err := os.CreateTemp(s.tmpDirName, "")
s.Require().NoError(err)
tmpFile := f.Name()
tmpFileBase := filepath.Base(tmpFile)
Expand Down
5 changes: 2 additions & 3 deletions agent/command/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -920,11 +919,11 @@ func (c *gitFetchProject) applyPatch(ctx context.Context, logger client.LoggerPr

// create a temporary folder and store patch files on disk,
// for later use in shell script
tempFile, err := ioutil.TempFile("", "mcipatch_")
tempFile, err := os.CreateTemp("", "mcipatch_")
if err != nil {
return errors.WithStack(err)
}
defer func() { //nolint: evg-lint
defer func() { //nolint:evg-lint
grip.Error(tempFile.Close())
grip.Error(os.Remove(tempFile.Name()))
}()
Expand Down
8 changes: 4 additions & 4 deletions agent/command/git_push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"os"
"path"
"strings"
"testing"
Expand Down Expand Up @@ -97,8 +97,8 @@ func TestGitPush(t *testing.T) {
c.DryRun = true

repoDir := t.TempDir()
require.NoError(t, ioutil.WriteFile(path.Join(repoDir, "test1.txt"), []byte("test1"), 0644))
require.NoError(t, ioutil.WriteFile(path.Join(repoDir, "test2.txt"), []byte("test2"), 0644))
require.NoError(t, os.WriteFile(path.Join(repoDir, "test1.txt"), []byte("test1"), 0644))
require.NoError(t, os.WriteFile(path.Join(repoDir, "test2.txt"), []byte("test2"), 0644))

// create repo
createRepoCommands := []string{
Expand All @@ -109,7 +109,7 @@ func TestGitPush(t *testing.T) {
cmd := jpm.CreateCommand(ctx).Directory(repoDir).Append(createRepoCommands...)
require.NoError(t, cmd.Run(ctx))

require.NoError(t, ioutil.WriteFile(path.Join(repoDir, "test3.txt"), []byte("test3"), 0644))
require.NoError(t, os.WriteFile(path.Join(repoDir, "test3.txt"), []byte("test3"), 0644))
toApplyCommands := []string{
`git rm test1.txt`,
`git add test3.txt`,
Expand Down
4 changes: 2 additions & 2 deletions agent/command/host_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package command
import (
"context"
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -267,7 +267,7 @@ func (c *createHost) populateUserdata() error {
return errors.Wrap(err, "opening user data file")
}
defer file.Close()
fileData, err := ioutil.ReadAll(file)
fileData, err := io.ReadAll(file)
if err != nil {
return errors.Wrap(err, "reading user data file")
}
Expand Down

0 comments on commit e1789d9

Please sign in to comment.