Skip to content

Commit

Permalink
DEVPROD-7742 Fix current testifylint lint issues (autofix flag) (#8603)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZackarySantana authored Jan 13, 2025
1 parent cbc9cca commit 33d9ae0
Show file tree
Hide file tree
Showing 149 changed files with 1,443 additions and 1,446 deletions.
46 changes: 23 additions & 23 deletions agent/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func (s *AgentSuite) TestFinishTaskWithAbnormallyCompletedTask() {
s.Equal(evergreen.TaskFailed, s.mockCommunicator.EndTaskResult.Detail.Status, "task that failed due to non-task-related reasons should record the final status")
s.Equal(evergreen.CommandTypeSystem, s.mockCommunicator.EndTaskResult.Detail.Type)
s.NotEmpty(s.mockCommunicator.EndTaskResult.Detail.Description)
s.Equal(s.mockCommunicator.EndTaskResult.Detail.FailingCommand, "initial task setup")
s.Equal("initial task setup", s.mockCommunicator.EndTaskResult.Detail.FailingCommand)
s.NoError(s.tc.logger.Close())
checkMockLogs(s.T(), s.mockCommunicator, s.tc.taskConfig.Task.Id, []string{
"Task encountered unexpected task lifecycle system failure",
Expand Down Expand Up @@ -400,8 +400,8 @@ pre:
s.Error(err)
s.True(utility.IsContextError(errors.Cause(err)), "command should have stopped due to context cancellation")

s.True(cmdDuration > waitUntilAbort, "command should have only stopped when it received cancel")
s.True(cmdDuration < cmdSleepSecs*time.Second, "command should not block if it's taking too long to stop")
s.Greater(cmdDuration, waitUntilAbort, "command should have only stopped when it received cancel")
s.Less(cmdDuration, cmdSleepSecs*time.Second, "command should not block if it's taking too long to stop")
}

func (s *AgentSuite) TestCancelledRunCommandsIsNonBlocking() {
Expand Down Expand Up @@ -2664,15 +2664,15 @@ func (s *AgentSuite) TestUpsertCheckRun() {
checkRunOutput, err := buildCheckRun(s.ctx, s.tc)
s.NoError(err)
s.NotNil(checkRunOutput)
s.Equal(checkRunOutput.Title, "This is my report checkRun_value")
s.Equal(checkRunOutput.Summary, "We found 6 failures and 2 warnings")
s.Equal(checkRunOutput.Text, "It looks like there are some errors on lines 2 and 4.")
s.Assert().Len(checkRunOutput.Annotations, 1)
s.Equal(checkRunOutput.Annotations[0].Path, "README.md")
s.Equal(checkRunOutput.Annotations[0].AnnotationLevel, "warning")
s.Equal(checkRunOutput.Annotations[0].Title, "Error Detector")
s.Equal(checkRunOutput.Annotations[0].Message, "message")
s.Equal(checkRunOutput.Annotations[0].RawDetails, "Do you mean this other thing?")
s.Equal("This is my report checkRun_value", checkRunOutput.Title)
s.Equal("We found 6 failures and 2 warnings", checkRunOutput.Summary)
s.Equal("It looks like there are some errors on lines 2 and 4.", checkRunOutput.Text)
s.Len(checkRunOutput.Annotations, 1)
s.Equal("README.md", checkRunOutput.Annotations[0].Path)
s.Equal("warning", checkRunOutput.Annotations[0].AnnotationLevel)
s.Equal("Error Detector", checkRunOutput.Annotations[0].Title)
s.Equal("message", checkRunOutput.Annotations[0].Message)
s.Equal("Do you mean this other thing?", checkRunOutput.Annotations[0].RawDetails)
s.Equal(checkRunOutput.Annotations[0].StartLine, utility.ToIntPtr(2))
s.Equal(checkRunOutput.Annotations[0].EndLine, utility.ToIntPtr(4))
}
Expand Down Expand Up @@ -2762,8 +2762,8 @@ func (s *AgentSuite) TestClearsGitConfig() {
"Running task commands failed",
})

s.Assert().NoFileExists(gitConfigPath)
s.Assert().NoFileExists(gitCredentialsPath)
s.NoFileExists(gitConfigPath)
s.NoFileExists(gitCredentialsPath)
}

func (s *AgentSuite) TestShouldRunSetupGroup() {
Expand All @@ -2785,39 +2785,39 @@ func (s *AgentSuite) TestShouldRunSetupGroup() {
}

shouldRun := shouldRunSetupGroup(nextTask, tc)
s.Equal(true, shouldRun)
s.True(shouldRun)

tc.ranSetupGroup = true

shouldRun = shouldRunSetupGroup(nextTask, &taskContext{})
s.Equal(true, shouldRun)
s.True(shouldRun)

shouldRun = shouldRunSetupGroup(nextTask, tc)
s.Equal(true, shouldRun)
s.True(shouldRun)

nextTask.TaskGroup = "not same"
shouldRun = shouldRunSetupGroup(nextTask, tc)
s.Equal(true, shouldRun)
s.True(shouldRun)

nextTask.Build = "build1"
shouldRun = shouldRunSetupGroup(nextTask, tc)
s.Equal(true, shouldRun)
s.True(shouldRun)

nextTask.TaskGroup = "group1"
shouldRun = shouldRunSetupGroup(nextTask, tc)
s.Equal(false, shouldRun)
s.False(shouldRun)

nextTask.TaskExecution = 1
shouldRun = shouldRunSetupGroup(nextTask, tc)
s.Equal(true, shouldRun)
s.True(shouldRun)

tc.taskConfig.Task.Execution = 1
shouldRun = shouldRunSetupGroup(nextTask, tc)
s.Equal(false, shouldRun)
s.False(shouldRun)

tc.taskConfig.Task.Execution = 2
shouldRun = shouldRunSetupGroup(nextTask, tc)
s.Equal(false, shouldRun)
s.False(shouldRun)
}

// checkMockLogs checks the mock communicator's received task logs. Note that
Expand Down
4 changes: 2 additions & 2 deletions agent/command/archive_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestFindContentsToArchive(t *testing.T) {
expectedFileSize += int(info.Size())
}
}
assert.NotZero(t, len(expectedFiles))
assert.NotEmpty(t, expectedFiles)

foundFiles, totalSize, err := findContentsToArchive(ctx, thisDir, []string{"*.go"}, nil)
require.NoError(t, err)
Expand Down Expand Up @@ -72,7 +72,7 @@ func TestFindContentsToArchive(t *testing.T) {
expectedFileSize += int(info.Size())
}
}
assert.NotZero(t, len(expectedFiles))
assert.NotEmpty(t, expectedFiles)

foundFiles, totalSize, err := findContentsToArchive(ctx, thisDir, []string{"*.go", "*.go"}, nil)
require.NoError(t, err)
Expand Down
20 changes: 10 additions & 10 deletions agent/command/attach_artifacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ func (s *ArtifactsSuite) TestParseErrorsIfTypesDoNotMatch() {
}

func (s *ArtifactsSuite) TestParseErrorIfNothingIsSet() {
s.Len(s.cmd.Files, 0)
s.Empty(s.cmd.Files)
s.Error(s.cmd.ParseParams(map[string]interface{}{}))
}

func (s *ArtifactsSuite) TestArtifactErrorsWithInvalidExpansions() {
s.Len(s.cmd.Files, 0)
s.Empty(s.cmd.Files)
s.NoError(s.cmd.ParseParams(map[string]interface{}{
"files": []string{
"fo${bar",
Expand All @@ -112,25 +112,25 @@ func (s *ArtifactsSuite) TestArtifactErrorsWithInvalidExpansions() {
func (s *ArtifactsSuite) TestArtifactErrorsIfDoesNotExist() {
s.cmd.Files = []string{"foo"}
s.Error(s.cmd.Execute(s.ctx, s.comm, s.logger, s.conf))
s.Len(s.cmd.Files, 0)
s.Len(s.mock.AttachedFiles, 0)
s.Len(s.mock.AttachedFiles[s.conf.Task.Id], 0)
s.Empty(s.cmd.Files)
s.Empty(s.mock.AttachedFiles)
s.Empty(s.mock.AttachedFiles[s.conf.Task.Id])
}

func (s *ArtifactsSuite) TestArtifactNoErrorIfDoesNotExistWithExactNames() {
s.cmd.Files = []string{"foo"}
s.cmd.ExactFileNames = true
s.Error(s.cmd.Execute(s.ctx, s.comm, s.logger, s.conf))
s.Len(s.cmd.Files, 1)
s.Len(s.mock.AttachedFiles, 0)
s.Len(s.mock.AttachedFiles[s.conf.Task.Id], 0)
s.Empty(s.mock.AttachedFiles)
s.Empty(s.mock.AttachedFiles[s.conf.Task.Id])
}

func (s *ArtifactsSuite) TestArtifactSkipsErrorWithOptionalArgument() {
s.cmd.Files = []string{"foo"}
s.cmd.Optional = true
s.NoError(s.cmd.Execute(s.ctx, s.comm, s.logger, s.conf))
s.Len(s.cmd.Files, 0)
s.Empty(s.cmd.Files)
}

func (s *ArtifactsSuite) TestReadFileFailsIfTasksDoesNotExist() {
Expand All @@ -150,7 +150,7 @@ func (s *ArtifactsSuite) TestReadFileSucceeds() {
}

func (s *ArtifactsSuite) TestCommandParsesFile() {
s.Len(s.mock.AttachedFiles, 0)
s.Empty(s.mock.AttachedFiles)
s.cmd.Files = []string{"example*"}
s.NoError(s.cmd.Execute(s.ctx, s.comm, s.logger, s.conf))
s.Len(s.mock.AttachedFiles, 1)
Expand All @@ -159,7 +159,7 @@ func (s *ArtifactsSuite) TestCommandParsesFile() {

func (s *ArtifactsSuite) TestCommandParsesExactFileNames() {
s.cmd.ExactFileNames = true
s.Len(s.mock.AttachedFiles, 0)
s.Empty(s.mock.AttachedFiles)
s.cmd.Files = []string{"exactmatch.json", "example.json"}
s.NoError(s.cmd.Execute(s.ctx, s.comm, s.logger, s.conf))
s.Len(s.mock.AttachedFiles, 1)
Expand Down
6 changes: 3 additions & 3 deletions agent/command/downstream_expansions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ func TestDownstreamExpansions(t *testing.T) {
"FilenameIsExpanded": func(t *testing.T, ctx context.Context, comm *client.Mock, conf *internal.TaskConfig, logger client.LoggerProducer, path string) {
conf.Expansions = *util.NewExpansions(map[string]string{"foo": path})
cmd := &setDownstream{YamlFile: "${foo}"}
assert.Nil(t, cmd.Execute(ctx, comm, logger, conf))
assert.NoError(t, cmd.Execute(ctx, comm, logger, conf))
assert.Equal(t, cmd.YamlFile, path)
},
"ContentsAreStored": func(t *testing.T, ctx context.Context, comm *client.Mock, conf *internal.TaskConfig, logger client.LoggerProducer, path string) {
cmd := &setDownstream{YamlFile: path}
assert.Nil(t, cmd.Execute(ctx, comm, logger, conf))
assert.NoError(t, cmd.Execute(ctx, comm, logger, conf))
paramsCmd := map[string]string{}
paramsComm := map[string]string{}
for i := range cmd.downstreamParams {
Expand Down Expand Up @@ -63,7 +63,7 @@ func TestDownstreamExpansions(t *testing.T) {
path := filepath.Join(cwd, "testdata", "git", "test_expansions.yml")

cmd := &setDownstream{YamlFile: path}
assert.Nil(t, cmd.Execute(ctx, comm, logger, conf))
assert.NoError(t, cmd.Execute(ctx, comm, logger, conf))
paramsCmd := map[string]string{}
for i := range cmd.downstreamParams {
paramsCmd[cmd.downstreamParams[i].Key] = cmd.downstreamParams[i].Value
Expand Down
6 changes: 3 additions & 3 deletions agent/command/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (s *execCmdSuite) TestRunCommandPropagatesError() {
s.NoError(cmd.ParseParams(map[string]interface{}{}))
exec := cmd.getProc(s.ctx, cmd.Binary, &internal.TaskConfig{Task: task.Task{Id: "foo"}, Distro: &apimodels.DistroView{}}, s.logger)
err := cmd.runCommand(s.ctx, exec, s.logger)
s.Require().NotNil(err)
s.Require().Error(err)
s.Contains(err.Error(), "process encountered problem: exit code 1")
s.NotContains(err.Error(), "error waiting on process")
}
Expand Down Expand Up @@ -390,7 +390,7 @@ func (s *execCmdSuite) TestExpansionsForEnv() {
}

s.NoError(cmd.doExpansions(util.NewExpansions(map[string]string{})))
s.Len(cmd.Env, 0)
s.Empty(cmd.Env)
cmd.Env["one"] = "one"
s.NoError(cmd.doExpansions(util.NewExpansions(map[string]string{"two": "two"})))
s.Len(cmd.Env, 1)
Expand Down Expand Up @@ -487,7 +487,7 @@ func TestAddTemp(t *testing.T) {
} {
t.Run(name, func(t *testing.T) {
env := make(map[string]string)
require.Len(t, env, 0)
require.Empty(t, env)
test(t, env)
})
}
Expand Down
4 changes: 2 additions & 2 deletions agent/command/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (s *generateSuite) TestExecuteSuccessWithValidGlobbing() {
}

func (s *generateSuite) TestErrorWithInvalidExpansions() {
s.Len(s.g.Files, 0)
s.Empty(s.g.Files)
s.NoError(s.g.ParseParams(map[string]interface{}{
"files": []string{
"fo${bar",
Expand All @@ -173,7 +173,7 @@ func (s *generateSuite) TestNoErrorWithValidExpansions() {
s.Equal(len(s.json), n)
s.NoError(f.Close())

s.Len(s.g.Files, 0)
s.Empty(s.g.Files)
s.NoError(s.g.ParseParams(map[string]interface{}{
"files": []string{
"${bar}",
Expand Down
14 changes: 7 additions & 7 deletions agent/command/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func (s *GitGetProjectSuite) TestGitPlugin() {
s.comm.CreateInstallationTokenResult = "token"
s.comm.CreateGitHubDynamicAccessTokenResult = "token"
for _, task := range conf.Project.Tasks {
s.NotEqual(len(task.Commands), 0)
s.NotEmpty(task.Commands)
for _, command := range task.Commands {
pluginCmds, err := Render(command, &conf.Project, BlockInfo{})
s.NoError(err)
Expand Down Expand Up @@ -303,7 +303,7 @@ func (s *GitGetProjectSuite) TestTokenIsRedactedWhenGenerated() {

runCommands := func(logger client.LoggerProducer) {
for _, task := range conf.Project.Tasks {
s.NotEqual(len(task.Commands), 0)
s.NotEmpty(task.Commands)
for _, command := range task.Commands {
pluginCmds, err := Render(command, &conf.Project, BlockInfo{})
s.NoError(err)
Expand Down Expand Up @@ -380,7 +380,7 @@ func (s *GitGetProjectSuite) TestStdErrLogged() {
defer cancel()

for _, task := range conf.Project.Tasks {
s.NotEqual(len(task.Commands), 0)
s.NotEmpty(task.Commands)
for _, command := range task.Commands {
pluginCmds, err := Render(command, &conf.Project, BlockInfo{})
s.NoError(err)
Expand Down Expand Up @@ -710,7 +710,7 @@ func (s *GitGetProjectSuite) TestCorrectModuleRevisionSetModule() {
defer cancel()

for _, task := range conf.Project.Tasks {
s.NotEqual(len(task.Commands), 0)
s.NotEmpty(task.Commands)
for _, command := range task.Commands {
var pluginCmds []Command
pluginCmds, err = Render(command, &conf.Project, BlockInfo{})
Expand Down Expand Up @@ -759,7 +759,7 @@ func (s *GitGetProjectSuite) TestMultipleModules() {
s.comm.CreateGitHubDynamicAccessTokenResult = mockedGitHubAppToken

for _, task := range conf.Project.Tasks {
s.NotEqual(len(task.Commands), 0)
s.NotEmpty(task.Commands)
for _, command := range task.Commands {
pluginCmds, err = Render(command, &conf.Project, BlockInfo{})
s.NoError(err)
Expand Down Expand Up @@ -819,7 +819,7 @@ func (s *GitGetProjectSuite) TestCorrectModuleRevisionManifest() {
conf.Expansions.Put(moduleRevExpansionName("sample"), correctHash)

for _, task := range conf.Project.Tasks {
s.NotEqual(len(task.Commands), 0)
s.NotEmpty(task.Commands)
for _, command := range task.Commands {
var pluginCmds []Command
pluginCmds, err = Render(command, &conf.Project, BlockInfo{})
Expand Down Expand Up @@ -861,7 +861,7 @@ func (s *GitGetProjectSuite) TestCorrectModuleRevisionManifestWithExpansion() {
conf.Expansions.Put("sample_expansion_name", "sample")

for _, task := range conf.Project.Tasks {
s.NotEqual(len(task.Commands), 0)
s.NotEmpty(task.Commands)
for _, command := range task.Commands {
var pluginCmds []Command
pluginCmds, err = Render(command, &conf.Project, BlockInfo{})
Expand Down
4 changes: 2 additions & 2 deletions agent/command/github_generate_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func TestGitHubGenerateTokenExecute(t *testing.T) {
require.Len(t, conf.CommandCleanups, 1)
cleanup := conf.CommandCleanups[0]
assert.Equal(t, "github.generate_token", cleanup.Command)
assert.Nil(t, cleanup.Run(ctx))
assert.NoError(t, cleanup.Run(ctx))
},
"SucceedsWithEmptyOwnerAndRepoAndCreatesToken": func(ctx context.Context, t *testing.T, cmd *githubGenerateToken, client *client.Mock, logger client.LoggerProducer, conf *internal.TaskConfig) {
client.CreateGitHubDynamicAccessTokenResult = "token!"
Expand All @@ -133,7 +133,7 @@ func TestGitHubGenerateTokenExecute(t *testing.T) {
require.Len(t, conf.CommandCleanups, 1)
cleanup := conf.CommandCleanups[0]
assert.Equal(t, "github.generate_token", cleanup.Command)
assert.Nil(t, cleanup.Run(ctx))
assert.NoError(t, cleanup.Run(ctx))
},
} {
t.Run(tName, func(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions agent/command/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ func TestCommandRegistry(t *testing.T) {
assert.NotNil(r.mu)
assert.NotNil(evgRegistry)

assert.Len(r.cmds, 0)
assert.Empty(r.cmds)

factory := CommandFactory(func() Command { return nil })
assert.NotNil(factory)
assert.Error(r.registerCommand("", factory))
assert.Len(r.cmds, 0)
assert.Empty(r.cmds)
assert.Error(r.registerCommand("foo", nil))
assert.Len(r.cmds, 0)
assert.Empty(r.cmds)

assert.NoError(r.registerCommand("cmd.factory", factory))
assert.Len(r.cmds, 1)
Expand Down
2 changes: 1 addition & 1 deletion agent/command/results_xunit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func TestXUnitParseAndUpload(t *testing.T) {
assert.NoError(t, xr.parseAndUploadResults(ctx, conf, logger, comm))
assert.NoError(t, logger.Close())

assert.Len(t, cedarSrv.TestResults.Results, 0)
assert.Empty(t, cedarSrv.TestResults.Results)
},
"EmptyTestsForInvalidPathErrors": func(ctx context.Context, t *testing.T, cedarSrv *timberutil.MockCedarServer, conf *internal.TaskConfig, logger client.LoggerProducer) {
xr := xunitResults{
Expand Down
4 changes: 2 additions & 2 deletions agent/command/s3_put_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ func TestSignedUrlVisibility(t *testing.T) {
assert.Equal(t, file.AwsSecret, s.AwsSecret)

} else {
assert.Equal(t, file.AwsKey, "")
assert.Equal(t, file.AwsSecret, "")
assert.Equal(t, "", file.AwsKey)
assert.Equal(t, "", file.AwsSecret)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions agent/command/shell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (s *shellExecuteCommandSuite) TestCancellingContextShouldCancelCommand() {
time.Sleep(100 * time.Millisecond)

err := cmd.Execute(ctx, s.comm, s.logger, s.conf)
s.Require().NotNil(err)
s.Require().Error(err)
s.True(utility.IsContextError(errors.Cause(err)))
}

Expand Down Expand Up @@ -254,6 +254,6 @@ func (s *shellExecuteCommandSuite) TestFailingShellCommandErrors() {
}
cmd.SetJasperManager(s.jasper)
err := cmd.Execute(s.ctx, s.comm, s.logger, s.conf)
s.Require().NotNil(err)
s.Require().Error(err)
s.Contains(err.Error(), "shell script encountered problem: exit code 1")
}
Loading

0 comments on commit 33d9ae0

Please sign in to comment.