[#1309] test: Clean up config after tests
All checks were successful
DCO action / DCO (pull_request) Successful in 2m38s
Tests and linters / Run gofumpt (pull_request) Successful in 2m52s
Vulncheck / Vulncheck (pull_request) Successful in 3m3s
Build / Build Components (1.23) (pull_request) Successful in 3m51s
Build / Build Components (1.22) (pull_request) Successful in 3m57s
Pre-commit hooks / Pre-commit (pull_request) Successful in 4m6s
Tests and linters / Staticcheck (pull_request) Successful in 4m15s
Tests and linters / Tests (1.22) (pull_request) Successful in 4m21s
Tests and linters / Tests (1.23) (pull_request) Successful in 4m21s
Tests and linters / Tests with -race (pull_request) Successful in 4m39s
Tests and linters / Lint (pull_request) Successful in 4m48s
Tests and linters / gopls check (pull_request) Successful in 4m54s

Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
This commit is contained in:
Aleksey Savchuk 2024-08-21 17:08:44 +03:00
parent 7bca428db0
commit 5443c62e63
2 changed files with 11 additions and 0 deletions

View file

@ -24,6 +24,8 @@ var testCmd = &cobra.Command{
}
func Test_getOrGenerate(t *testing.T) {
t.Cleanup(viper.Reset)
dir := t.TempDir()
wallPath := filepath.Join(dir, "wallet.json")

View file

@ -40,6 +40,15 @@ func ForEachFileType(pref string, f func(*config.Config)) {
// ForEnvFileType creates config from `<pref>.env` file.
func ForEnvFileType(t testing.TB, pref string, f func(*config.Config)) {
envs := os.Environ()
t.Cleanup(func() {
os.Clearenv()
for _, env := range envs {
keyValue := strings.Split(env, "=")
os.Setenv(keyValue[0], keyValue[1])
}
})
f(fromEnvFile(t, pref+".env"))
}