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

test: remove not needed testutil.Setenv #1610

Merged
merged 1 commit into from
Sep 7, 2023
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
40 changes: 0 additions & 40 deletions internal/testutil/env_go1_16.go

This file was deleted.

18 changes: 0 additions & 18 deletions internal/testutil/env_go1_17.go

This file was deleted.

6 changes: 2 additions & 4 deletions util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (
"path/filepath"
"reflect"
"testing"

"github.com/spf13/viper/internal/testutil"
)

func TestCopyAndInsensitiviseMap(t *testing.T) {
Expand Down Expand Up @@ -64,8 +62,8 @@ func TestAbsPathify(t *testing.T) {
homer := filepath.Join(home, "homer")
wd, _ := os.Getwd()

testutil.Setenv(t, "HOMER_ABSOLUTE_PATH", homer)
testutil.Setenv(t, "VAR_WITH_RELATIVE_PATH", "relative")
t.Setenv("HOMER_ABSOLUTE_PATH", homer)
t.Setenv("VAR_WITH_RELATIVE_PATH", "relative")

tests := []struct {
input string
Expand Down
42 changes: 21 additions & 21 deletions viper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,10 +620,10 @@ func TestEnv(t *testing.T) {
BindEnv("id")
BindEnv("f", "FOOD", "OLD_FOOD")

testutil.Setenv(t, "ID", "13")
testutil.Setenv(t, "FOOD", "apple")
testutil.Setenv(t, "OLD_FOOD", "banana")
testutil.Setenv(t, "NAME", "crunk")
t.Setenv("ID", "13")
t.Setenv("FOOD", "apple")
t.Setenv("OLD_FOOD", "banana")
t.Setenv("NAME", "crunk")

assert.Equal(t, "13", Get("id"))
assert.Equal(t, "apple", Get("f"))
Expand All @@ -639,7 +639,7 @@ func TestMultipleEnv(t *testing.T) {

BindEnv("f", "FOOD", "OLD_FOOD")

testutil.Setenv(t, "OLD_FOOD", "banana")
t.Setenv("OLD_FOOD", "banana")

assert.Equal(t, "banana", Get("f"))
}
Expand All @@ -650,7 +650,7 @@ func TestEmptyEnv(t *testing.T) {
BindEnv("type") // Empty environment variable
BindEnv("name") // Bound, but not set environment variable

testutil.Setenv(t, "TYPE", "")
t.Setenv("TYPE", "")

assert.Equal(t, "donut", Get("type"))
assert.Equal(t, "Cake", Get("name"))
Expand All @@ -664,7 +664,7 @@ func TestEmptyEnv_Allowed(t *testing.T) {
BindEnv("type") // Empty environment variable
BindEnv("name") // Bound, but not set environment variable

testutil.Setenv(t, "TYPE", "")
t.Setenv("TYPE", "")

assert.Equal(t, "", Get("type"))
assert.Equal(t, "Cake", Get("name"))
Expand All @@ -677,9 +677,9 @@ func TestEnvPrefix(t *testing.T) {
BindEnv("id")
BindEnv("f", "FOOD") // not using prefix

testutil.Setenv(t, "FOO_ID", "13")
testutil.Setenv(t, "FOOD", "apple")
testutil.Setenv(t, "FOO_NAME", "crunk")
t.Setenv("FOO_ID", "13")
t.Setenv("FOOD", "apple")
t.Setenv("FOO_NAME", "crunk")

assert.Equal(t, "13", Get("id"))
assert.Equal(t, "apple", Get("f"))
Expand All @@ -695,7 +695,7 @@ func TestAutoEnv(t *testing.T) {

AutomaticEnv()

testutil.Setenv(t, "FOO_BAR", "13")
t.Setenv("FOO_BAR", "13")

assert.Equal(t, "13", Get("foo_bar"))
}
Expand All @@ -706,7 +706,7 @@ func TestAutoEnvWithPrefix(t *testing.T) {
AutomaticEnv()
SetEnvPrefix("Baz")

testutil.Setenv(t, "BAZ_BAR", "13")
t.Setenv("BAZ_BAR", "13")

assert.Equal(t, "13", Get("bar"))
}
Expand All @@ -716,7 +716,7 @@ func TestSetEnvKeyReplacer(t *testing.T) {

AutomaticEnv()

testutil.Setenv(t, "REFRESH_INTERVAL", "30s")
t.Setenv("REFRESH_INTERVAL", "30s")

replacer := strings.NewReplacer("-", "_")
SetEnvKeyReplacer(replacer)
Expand All @@ -729,7 +729,7 @@ func TestEnvKeyReplacer(t *testing.T) {

v.AutomaticEnv()

testutil.Setenv(t, "REFRESH_INTERVAL", "30s")
t.Setenv("REFRESH_INTERVAL", "30s")

assert.Equal(t, "30s", v.Get("refresh-interval"))
}
Expand All @@ -741,14 +741,14 @@ func TestEnvSubConfig(t *testing.T) {

v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))

testutil.Setenv(t, "CLOTHING_PANTS_SIZE", "small")
t.Setenv("CLOTHING_PANTS_SIZE", "small")
subv := v.Sub("clothing").Sub("pants")
assert.Equal(t, "small", subv.Get("size"))

// again with EnvPrefix
v.SetEnvPrefix("foo") // will be uppercased automatically
subWithPrefix := v.Sub("clothing").Sub("pants")
testutil.Setenv(t, "FOO_CLOTHING_PANTS_SIZE", "large")
t.Setenv("FOO_CLOTHING_PANTS_SIZE", "large")
assert.Equal(t, "large", subWithPrefix.Get("size"))
}

Expand Down Expand Up @@ -875,8 +875,8 @@ func TestAllKeysWithEnv(t *testing.T) {
v.BindEnv("foo.bar")
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))

testutil.Setenv(t, "ID", "13")
testutil.Setenv(t, "FOO_BAR", "baz")
t.Setenv("ID", "13")
t.Setenv("FOO_BAR", "baz")

expectedKeys := sort.StringSlice{"id", "foo.bar"}
expectedKeys.Sort()
Expand Down Expand Up @@ -1308,7 +1308,7 @@ func TestBoundCaseSensitivity(t *testing.T) {

BindEnv("eYEs", "TURTLE_EYES")

testutil.Setenv(t, "TURTLE_EYES", "blue")
t.Setenv("TURTLE_EYES", "blue")

assert.Equal(t, "blue", Get("eyes"))

Expand Down Expand Up @@ -1492,8 +1492,8 @@ func TestIsSet(t *testing.T) {
v.BindEnv("clothing.hat")
v.BindEnv("clothing.hats")

testutil.Setenv(t, "FOO", "bar")
testutil.Setenv(t, "CLOTHING_HAT", "bowler")
t.Setenv("FOO", "bar")
t.Setenv("CLOTHING_HAT", "bowler")

assert.True(t, v.IsSet("eyes")) // in the config file
assert.True(t, v.IsSet("foo")) // in the environment
Expand Down