Skip to content

Commit a4ce30b

Browse files
committed
Add additional test coverage for helper functions in Util
Currently helper functions in Util lacks test coverage This commit fixes the following functions by addressing the review feedback. - setEnvVar: Fixed setting env to original value using t.Cleanup() Signed-off-by: Kugamoorthy Gajananan <[email protected]>
1 parent af6a40c commit a4ce30b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

internal/util/helpers_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ func setEnvVar(t *testing.T, env string, value string) {
3939
envLock.Lock()
4040
t.Cleanup(envLock.Unlock)
4141

42-
originalEnvToken := os.Getenv(env)
42+
originalEnvVal := os.Getenv(env)
4343
err := os.Setenv(env, value)
4444
if err != nil {
4545
t.Errorf("error setting %v: %v", env, err)
4646
}
47-
defer os.Setenv(env, originalEnvToken)
47+
48+
t.Cleanup(func() { _ = os.Setenv(env, originalEnvVal) })
49+
4850
}
4951

5052
// TestGetConfigDirPath tests the GetConfigDirPath function
@@ -163,9 +165,7 @@ func TestGetGrpcConnection(t *testing.T) {
163165
for _, tt := range tests {
164166
t.Run(tt.name, func(t *testing.T) {
165167
t.Parallel()
166-
167168
setEnvVar(t, util.MinderAuthTokenEnvVar, tt.envToken)
168-
169169
conn, err := util.GetGrpcConnection(tt.grpcHost, tt.grpcPort, tt.allowInsecure, tt.issuerUrl, tt.clientId)
170170
if (err != nil) != tt.expectedError {
171171
t.Errorf("expected error: %v, got: %v", tt.expectedError, err)

0 commit comments

Comments
 (0)