Skip to content

Conversation

alexandear
Copy link
Contributor

usetesting tells that we can replace os.Setenv with t.Setenv and os.MkdirTemp with t.TempDir. As a result, this slightly simplifies tests.

$ golangci-lint run
pkg/dbmate/db_test.go:112:14: os.MkdirTemp() could be replaced by t.TempDir() in TestDumpSchema (usetesting)
        dir, err := os.MkdirTemp("", "dbmate")
                    ^
pkg/dbmate/db_test.go:146:14: os.MkdirTemp() could be replaced by t.TempDir() in TestAutoDumpSchema (usetesting)
        dir, err := os.MkdirTemp("", "dbmate")
                    ^
pkg/dbmate/db_test.go:190:14: os.MkdirTemp() could be replaced by t.TempDir() in TestLoadSchema (usetesting)
        dir, err := os.MkdirTemp("", "dbmate")
                    ^
pkg/dbmate/db_test.go:559:15: os.MkdirTemp() could be replaced by t.TempDir() in TestFindMigrationsAbsolute (usetesting)
                dir, err := os.MkdirTemp("", "dbmate")
                            ^
main_test.go:15:21: os.Setenv() could be replaced by t.Setenv() in TestGetDatabaseUrl (usetesting)
        require.NoError(t, os.Setenv("DATABASE_URL", "foo://example.org/one"))
                           ^
main_test.go:16:21: os.Setenv() could be replaced by t.Setenv() in TestGetDatabaseUrl (usetesting)
        require.NoError(t, os.Setenv("CUSTOM_URL", "foo://example.org/two"))
                           ^
main_test.go:88:5: os.Setenv() could be replaced by t.Setenv() in TestLoadEnvFiles (usetesting)
                                os.Setenv(pair[0], pair[1])
                                ^
main_test.go:134:3: os.Setenv() could be replaced by t.Setenv() in TestLoadEnvFiles (usetesting)
                os.Setenv("FIRST", "not one")
                ^

Copy link
Collaborator

@dossy dossy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, looks good, and tests still pass. :shipit:

@dossy dossy merged commit 2eaa8fa into amacneil:main Mar 17, 2025
10 checks passed
@alexandear alexandear deleted the enable-usetesting branch March 18, 2025 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants