Skip to content

Commit

Permalink
contrib/internal/httptrace: discard panic() in option tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Hellzy committed Jun 9, 2022
1 parent adc7b28 commit 1007006
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions contrib/internal/httptrace/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,16 @@ func TestConfig(t *testing.T) {

func cleanEnv() func() {
val := os.Getenv(clientIPHeaderEnvVar)
if err := os.Unsetenv(clientIPHeaderEnvVar); err != nil {
panic(err)
}
os.Unsetenv(clientIPHeaderEnvVar)
return func() {
restoreEnv(clientIPHeaderEnvVar, val)
}
}

func restoreEnv(key, value string) {
if value != "" {
if err := os.Setenv(key, value); err != nil {
panic(err)
}
os.Setenv(key, value)
} else {
if err := os.Unsetenv(key); err != nil {
panic(err)
}
os.Unsetenv(key)
}
}

0 comments on commit 1007006

Please sign in to comment.