Improve test clean up

pull/4229/head
Medya Gh 2019-05-19 14:45:21 -07:00
parent c428ce5ebd
commit b6bf1dff8d
1 changed files with 5 additions and 0 deletions

View File

@ -89,6 +89,7 @@ func TestUpdateEnv(t *testing.T) {
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("%s in %s", tc.ip, tc.env), func(t *testing.T) {
origVal := os.Getenv(tc.env)
gotErr := false
err := updateEnv(tc.ip, tc.env)
if err != nil {
@ -97,6 +98,10 @@ func TestUpdateEnv(t *testing.T) {
if gotErr != tc.wantErr {
t.Errorf("updateEnv(%v,%v) got error is %v ; want error is %v", tc.ip, tc.env, gotErr, tc.wantErr)
}
err = os.Setenv(tc.env, origVal)
if err != nil && tc.env != "" {
t.Errorf("Error reverting the env var (%s) to its original value (%s)", tc.env, origVal)
}
})
}