Skip to content

Commit

Permalink
tests: fix: testifylint warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
fho committed Dec 14, 2023
1 parent f73babd commit e53230e
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 39 deletions.
4 changes: 2 additions & 2 deletions internal/command/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func baurCSVStatusCmd(t *testing.T, cmd *statusCmd) []*csvStatus {
result := make([]*csvStatus, 0, len(statusOut))

for _, line := range statusOut {
require.Equal(t, 5, len(line))
require.Len(t, line, 5)
result = append(result, &csvStatus{
taskID: line[0],
status: line[3],
Expand Down Expand Up @@ -168,7 +168,7 @@ func TestRunningPendingTasksChangesStatus(t *testing.T) {
gittest.CommitFilesToGit(t, ".")

res, err := exec.Command("git", "rev-parse", "HEAD").ExpectSuccess().Run()
assert.NoError(t, err)
require.NoError(t, err)

commit = strings.TrimSpace(res.StrOutput())
}
Expand Down
8 changes: 4 additions & 4 deletions internal/command/diff_inputs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func Test2ArgsRequired(t *testing.T) {
diffInputsCmd.SetArgs(tc.args)
err := diffInputsCmd.Execute()

assert.EqualError(t, err, fmt.Sprintf("accepts 2 args, received %d", len(tc.args)))
require.EqualError(t, err, fmt.Sprintf("accepts 2 args, received %d", len(tc.args)))
})
}
}
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestWildCardsNotAllowed(t *testing.T) {
diffInputsCmd.SetArgs([]string{tc.appTask, "app.task"})
err := diffInputsCmd.Execute()

assert.EqualError(t, err, fmt.Sprintf("invalid argument: \"%s\"", tc.appTask))
require.EqualError(t, err, fmt.Sprintf("invalid argument: \"%s\"", tc.appTask))
})
}
}
Expand Down Expand Up @@ -127,7 +127,7 @@ func TestAppAndTaskRequired(t *testing.T) {
diffInputsCmd.SetArgs([]string{tc.appTask, "app.task"})
err := diffInputsCmd.Execute()

assert.EqualError(t, err, fmt.Sprintf("invalid argument: \"%s\"", tc.appTask))
require.EqualError(t, err, fmt.Sprintf("invalid argument: \"%s\"", tc.appTask))
})
}
}
Expand Down Expand Up @@ -455,5 +455,5 @@ func execCmd(t *testing.T, cmd *diffInputsCmd, expectedExitCode int) {
}()

err := cmd.Execute()
assert.Nil(t, err)
require.NoError(t, err)
}
2 changes: 1 addition & 1 deletion internal/command/upgrade_configs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestUpgrade(t *testing.T) {
var err error
if runtime.GOOS == "windows" {
originalDir, err = os.Getwd()
assert.NoError(t, err)
require.NoError(t, err)
}

tempDir := t.TempDir()
Expand Down
6 changes: 3 additions & 3 deletions internal/exec/pdeathsig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ func TestProcessTerminatesWithParent(t *testing.T) {
cmd.Env = append(os.Environ(), "BAUR_EXEC_DEATHSIG_TEST_PARENT=1")

stdoutReader, err := cmd.StdoutPipe()
assert.NoError(t, err, "opening stdout pipe for new cmd failed")
require.NoError(t, err, "opening stdout pipe for new cmd failed")
cmd.Stderr = cmd.Stdout

err = cmd.Start()
assert.NoError(t, err, "starting parent process failed")
require.NoError(t, err, "starting parent process failed")

t.Log("started parent process, waiting for it to print that it started the child")

Expand Down Expand Up @@ -112,7 +112,7 @@ func TestProcessTerminatesWithParent(t *testing.T) {

t.Log("killing parent process")
err = cmd.Process.Kill()
assert.NoError(t, err, "killing parent process failed")
require.NoError(t, err, "killing parent process failed")

time.Sleep(2 * time.Second)
out, err := io.ReadAll(stdoutReader)
Expand Down
3 changes: 2 additions & 1 deletion internal/fs/fileglob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/simplesurance/baur/v3/internal/testutils/fstest"
"github.com/simplesurance/baur/v3/internal/testutils/strtest"
Expand Down Expand Up @@ -184,7 +185,7 @@ func TestGlobMatch(t *testing.T) {
for _, tc := range tcs {
t.Run(fmt.Sprintf("pattern:%s,path:%s", tc.pattern, tc.path), func(t *testing.T) {
match, err := MatchGlob(tc.pattern, tc.path)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, tc.expectMatch, match)
})
}
Expand Down
5 changes: 3 additions & 2 deletions internal/fs/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/simplesurance/baur/v3/internal/testutils/fstest"
)

func TestFindFileInParentDirsOnRoot(t *testing.T) {
_, err := FindFileInParentDirs(filepath.FromSlash("/"), "mytestfile-which-must-not-exist-1234")
assert.ErrorIs(t, err, os.ErrNotExist)
require.ErrorIs(t, err, os.ErrNotExist)
}

func TestFindFileInParentDirWithExcessivePathSeperator(t *testing.T) {
Expand All @@ -27,6 +28,6 @@ func TestFindFileInParentDirWithExcessivePathSeperator(t *testing.T) {
fstest.WriteToFile(t, []byte("hello"), filepath.Join(tempdir, subdir1, wantedFilename))

foundPath, err := FindFileInParentDirs(subdir2AbsPath+string(os.PathSeparator), wantedFilename)
assert.NoError(t, err)
require.NoError(t, err)
assert.Equal(t, wantedFileAbsPath, foundPath)
}
2 changes: 1 addition & 1 deletion internal/resolve/gosource/gosource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestResolve(t *testing.T) {
fileContent, err := os.ReadFile(testCfgFilename)
require.NoError(t, err)

require.NoError(t, err, json.Unmarshal(fileContent, &testCfg))
require.ErrorIs(t, err, json.Unmarshal(fileContent, &testCfg))

cwd, err := os.Getwd()
require.NoError(t, err)
Expand Down
12 changes: 6 additions & 6 deletions internal/upload/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ func TestGetAuth(t *testing.T) {
auth := client.getAuth(DefaultRegistry)
require.NotNil(t, auth)

assert.Equal(t, auth.ServerAddress, DefaultRegistry)
assert.Equal(t, auth.Password, defRegistryPasswd)
assert.Equal(t, auth.Username, defRegistryUser)
assert.Equal(t, DefaultRegistry, auth.ServerAddress)
assert.Equal(t, defRegistryPasswd, auth.Password)
assert.Equal(t, defRegistryUser, auth.Username)
})

t.Run("example-url", func(t *testing.T) {
Expand All @@ -81,9 +81,9 @@ func TestGetAuth(t *testing.T) {
auth := client.getAuth(exampleURL)
require.NotNil(t, auth)

assert.Equal(t, auth.ServerAddress, exampleURL)
assert.Equal(t, auth.Password, examplePasswd)
assert.Equal(t, auth.Username, exampleUser)
assert.Equal(t, exampleURL, auth.ServerAddress)
assert.Equal(t, examplePasswd, auth.Password)
assert.Equal(t, exampleUser, auth.Username)
})

// when a URL is used as server and the image is tagged without url
Expand Down
2 changes: 1 addition & 1 deletion pkg/baur/inputresolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ func TestGoResolverFilesAreExcluded(t *testing.T) {
Directory: baseDir,
},
)
assert.NoError(t, err)
require.NoError(t, err)

strResult := toStrSlice(result)
assert.ElementsMatch(t, strResult, []string{filepath.Join("atm", "atm.go")})
Expand Down
8 changes: 4 additions & 4 deletions pkg/baur/inputresolver_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,31 @@ func TestResolveSymlink(t *testing.T) {
inputPath: "symlink",
validateFn: func(t *testing.T, err error, result []Input) {
require.ErrorContains(t, err, "file does not exist")
require.Len(t, result, 0)
require.Empty(t, result)
},
},
{
testdir: "directory_broken",
inputPath: "**",
validateFn: func(t *testing.T, err error, result []Input) {
require.ErrorContains(t, err, "no such file or directory")
require.Len(t, result, 0)
require.Empty(t, result)
},
},
{
testdir: "file_broken",
inputPath: "symlink",
validateFn: func(t *testing.T, err error, result []Input) {
require.ErrorContains(t, err, "file does not exist")
require.Len(t, result, 0)
require.Empty(t, result)
},
},
{
testdir: "file_broken",
inputPath: "**",
validateFn: func(t *testing.T, err error, result []Input) {
require.ErrorContains(t, err, "no such file or directory")
require.Len(t, result, 0)
require.Empty(t, result)
},
},
{
Expand Down
3 changes: 1 addition & 2 deletions pkg/cfg/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -114,5 +113,5 @@ func TestEnsureValidateFailsOnDuplicateTaskNames(t *testing.T) {
err = loadedApp.Merge(includeDB, &mockResolver{})
require.NoError(t, err)

assert.Error(t, loadedApp.Validate())
require.Error(t, loadedApp.Validate())
}
4 changes: 2 additions & 2 deletions pkg/cfg/includedb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func taskInclude() TaskIncludes {
}

// TestLoadTaskIncludeWithIncludesInSameFile validates that:
// - TaskIncludes can refer Input/Output includes in the same file.
// - TaskIncludes can refer )Input/Output includes in the same file.
// - The loaded TaskInclude contains all data from the config.
func TestLoadTaskIncludeWithIncludesInSameFile(t *testing.T) {
const inclFilePath = "include.toml"
Expand Down Expand Up @@ -615,7 +615,7 @@ func TestTaskIncludeFailsForNonExistingIncludeName(t *testing.T) {

includeDB := NewIncludeDB(t.Logf)
err = loadedApp.Merge(includeDB, &mockResolver{})
require.True(t, errors.Is(err, ErrIncludeIDNotFound), "merge did not return ErrIncludeIDNotFound: %v", err)
require.ErrorIs(t, err, ErrIncludeIDNotFound, "merge did not return ErrIncludeIDNotFound: %v", err)
}

// TestVarsInIncludeFiles ensures vars are correctly replaced when they
Expand Down
4 changes: 2 additions & 2 deletions pkg/cfg/resolver/gotemplate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ func TestResolve(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(tt *testing.T) {
result, err := subject.Resolve(tc.input)
assert.NoError(t, err)
require.NoError(t, err)

if tc.expectedResult != "" {
assert.Equal(tt, tc.expectedResult, result)
}

if tc.validator != nil {
assert.NoError(tt, tc.validator(result))
require.NoError(tt, tc.validator(result))
}
})
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/cfg/tasks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package cfg
import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestAppsWithoutAnyTasksAreValid(t *testing.T) {
app := App{Name: "testapp"}

err := app.Validate()
assert.NoError(t, err)
require.NoError(t, err)
}

func TestTaskNameValidation(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/storage/postgres/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"testing"

"github.com/jackc/pgx/v4/pgxpool"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/simplesurance/baur/v3/internal/testutils/dbtest"
Expand Down Expand Up @@ -37,7 +36,7 @@ func newTestClient(t *testing.T) (*Client, func()) {

return &client, func() {
err := tx.Rollback(ctx)
assert.NoError(t, err)
require.NoError(t, err)

con.Close()
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/postgres/insert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ func TestSaveTaskRun(t *testing.T) {
id, err := client.SaveTaskRun(ctx, taskRun)

if expectedResult {
assert.NoError(t, err)
assert.NoError(t, err) //nolint: testifylint
assert.Greater(t, id, 0)

return
}

assert.Error(t, err)
require.Error(t, err)
}
})
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/storage/postgres/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package postgres
import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/simplesurance/baur/v3/pkg/storage"
Expand Down Expand Up @@ -50,7 +49,7 @@ func TestIsCompatible_SchemaVersionDoesNotMatch(t *testing.T) {
require.NoError(t, err)

err = client.IsCompatible(ctx)
assert.Error(t, err, "database schema version is not compatible")
require.Error(t, err, "database schema version is not compatible")
}

func TestApplyMigrations(t *testing.T) {
Expand Down

0 comments on commit e53230e

Please sign in to comment.