Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
chore: replace os.Chdir with t.Chdir in test code
Signed-off-by: Joonas Bergius <[email protected]>
  • Loading branch information
joonas committed Nov 26, 2025
commit 7daf18e0928a4427248b03f67353e6d69db70e45
4 changes: 1 addition & 3 deletions test/cli/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
func Test_configLoading(t *testing.T) {
cwd, err := os.Getwd()
require.NoError(t, err)
defer func() { require.NoError(t, os.Chdir(cwd)) }()

configsDir := filepath.Join(cwd, "test-fixtures", "configs")
path := func(path string) string {
Expand Down Expand Up @@ -149,8 +148,7 @@ func Test_configLoading(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
require.NoError(t, os.Chdir(test.cwd))
defer func() { require.NoError(t, os.Chdir(cwd)) }()
t.Chdir(test.cwd)
env := map[string]string{
"HOME": test.home,
"XDG_CONFIG_HOME": test.home,
Expand Down
7 changes: 1 addition & 6 deletions test/cli/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,7 @@ func getGrypeBinaryLocationByOS(t testing.TB, goOS string) string {
}

func buildBinary(t testing.TB, loc string) {
wd, err := os.Getwd()
require.NoError(t, err)
require.NoError(t, os.Chdir(repoRoot(t)))
defer func() {
require.NoError(t, os.Chdir(wd))
}()
t.Chdir(repoRoot(t))
t.Log("Building grype...")
c := exec.Command("go", "build", "-o", loc, "./cmd/grype")
c.Stdout = os.Stdout
Expand Down
Loading