Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: Replace os.Setenv() usage in testing with (testing.T).Setenv() #45

Merged
merged 3 commits into from
Nov 30, 2021
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
7 changes: 1 addition & 6 deletions fs/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package fs

import (
"context"
"os"
"testing"

"github.com/hashicorp/go-version"
Expand All @@ -25,11 +24,7 @@ func TestExactVersion(t *testing.T) {

// TODO: mock out command execution?

originalPath := os.Getenv("PATH")
os.Setenv("PATH", "")
t.Cleanup(func() {
os.Setenv("PATH", originalPath)
})
t.Setenv("PATH", "")

ev := &ExactVersion{
Product: product.Terraform,
Expand Down
16 changes: 2 additions & 14 deletions fs/fs_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@ import (
func TestAnyVersion_notExecutable(t *testing.T) {
testutil.EndToEndTest(t)

originalPath := os.Getenv("PATH")
os.Setenv("PATH", "")
t.Cleanup(func() {
os.Setenv("PATH", originalPath)
})

dirPath, fileName := testutil.CreateTempFile(t, "")
os.Setenv("PATH", dirPath)
t.Setenv("PATH", dirPath)

av := &AnyVersion{
Product: &product.Product{
Expand All @@ -41,14 +35,8 @@ func TestAnyVersion_notExecutable(t *testing.T) {
func TestAnyVersion_executable(t *testing.T) {
testutil.EndToEndTest(t)

originalPath := os.Getenv("PATH")
os.Setenv("PATH", "")
t.Cleanup(func() {
os.Setenv("PATH", originalPath)
})

dirPath, fileName := testutil.CreateTempFile(t, "")
os.Setenv("PATH", dirPath)
t.Setenv("PATH", dirPath)

fullPath := filepath.Join(dirPath, fileName)
err := os.Chmod(fullPath, 0700)
Expand Down
8 changes: 1 addition & 7 deletions fs/fs_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,8 @@ import (
func TestAnyVersion_executable(t *testing.T) {
testutil.EndToEndTest(t)

originalPath := os.Getenv("path")
os.Setenv("path", "")
t.Cleanup(func() {
os.Setenv("path", originalPath)
})

dirPath, fileName := testutil.CreateTempFile(t, "")
os.Setenv("path", dirPath)
t.Setenv("path", dirPath)

av := &AnyVersion{
Product: &product.Product{
Expand Down