From 1d110cc88ae874ba321a91d33177f665dd7955e1 Mon Sep 17 00:00:00 2001 From: Michi Mutsuzaki Date: Wed, 10 May 2023 16:34:05 +0000 Subject: [PATCH] unit test: Restore the original env variable using defer Fixes: 840b570e4515 ("Add a function to check if the CLI is in Helm mode") Signed-off-by: Michi Mutsuzaki --- internal/utils/utils_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/utils/utils_test.go b/internal/utils/utils_test.go index 02c06f5cb9..9276b2c748 100644 --- a/internal/utils/utils_test.go +++ b/internal/utils/utils_test.go @@ -208,11 +208,13 @@ func TestBuildImagePath(t *testing.T) { func TestIsInHelmMode(t *testing.T) { orig := os.Getenv(CLIModeVariableName) + defer func() { + assert.NoError(t, os.Setenv(CLIModeVariableName, orig)) + }() assert.NoError(t, os.Setenv(CLIModeVariableName, "helm")) assert.True(t, IsInHelmMode()) assert.NoError(t, os.Setenv(CLIModeVariableName, "classic")) assert.False(t, IsInHelmMode()) assert.NoError(t, os.Setenv(CLIModeVariableName, "random")) assert.False(t, IsInHelmMode()) - assert.NoError(t, os.Setenv(CLIModeVariableName, orig)) }