@@ -37,7 +37,7 @@ func Test_getCacheExcludedObjectsTypes(t *testing.T) {
3737func Test_readConfig (t * testing.T ) {
3838 createTempFileWithContent := func (t * testing.T , fileContent string ) * os.File {
3939 tempFile , err := os .CreateTemp ("" , "config-test-*.txt" )
40- t .Cleanup (func () { os .Remove (tempFile .Name ()) })
40+ t .Cleanup (func () { _ = os .Remove (tempFile .Name ()) })
4141 g .Expect (err ).ToNot (g .HaveOccurred ())
4242 _ , err = tempFile .Write ([]byte (fileContent ))
4343 g .Expect (err ).ToNot (g .HaveOccurred ())
@@ -51,8 +51,7 @@ func Test_readConfig(t *testing.T) {
5151
5252 envVarName := "TEST_CONFIG_VAR"
5353 envVarValue := "env-value"
54- os .Setenv (envVarName , envVarValue )
55- defer os .Unsetenv (envVarName )
54+ t .Setenv (envVarName , envVarValue )
5655
5756 result , err := readConfig (envVarName , "/nonexistent/path" )
5857 g .Expect (err ).ToNot (g .HaveOccurred ())
@@ -78,8 +77,7 @@ func Test_readConfig(t *testing.T) {
7877 // Set environment variable with different value
7978 envVarName := "TEST_CONFIG_VAR"
8079 envVarValue := "env-value"
81- os .Setenv (envVarName , envVarValue )
82- defer os .Unsetenv (envVarName )
80+ t .Setenv (envVarName , envVarValue )
8381
8482 result , err := readConfig (envVarName , tempFile .Name ())
8583 g .Expect (err ).ToNot (g .HaveOccurred ())
@@ -102,8 +100,7 @@ func Test_readConfig(t *testing.T) {
102100
103101 envVarName := "TEST_CONFIG_VAR"
104102 envVarValue := " \n \t env-value \t \n "
105- os .Setenv (envVarName , envVarValue )
106- defer os .Unsetenv (envVarName )
103+ t .Setenv (envVarName , envVarValue )
107104
108105 result , err := readConfig (envVarName , "/nonexistent/path" )
109106 g .Expect (err ).ToNot (g .HaveOccurred ())
@@ -134,7 +131,7 @@ func Test_readConfig(t *testing.T) {
134131
135132 tempDir , err := os .MkdirTemp ("" , "config-test-dir-*" )
136133 g .Expect (err ).ToNot (g .HaveOccurred ())
137- defer os .Remove (tempDir )
134+ defer func () { _ = os .Remove (tempDir ) }( )
138135
139136 _ , err = readConfig ("" , tempDir )
140137 g .Expect (err ).To (g .HaveOccurred ())
@@ -145,7 +142,7 @@ func Test_readConfig(t *testing.T) {
145142 g .RegisterTestingT (t )
146143
147144 envVarName := "NONEXISTENT_CONFIG_VAR"
148- os .Unsetenv (envVarName )
145+ _ = os .Unsetenv (envVarName )
149146
150147 result , err := readConfig (envVarName , "/nonexistent/path" )
151148 g .Expect (err ).ToNot (g .HaveOccurred ())
@@ -169,8 +166,7 @@ func Test_readConfig(t *testing.T) {
169166 tempFile := createTempFileWithContent (t , fileContent )
170167
171168 envVarName := "TEST_CONFIG_VAR"
172- os .Setenv (envVarName , "" )
173- defer os .Unsetenv (envVarName )
169+ t .Setenv (envVarName , "" )
174170
175171 result , err := readConfig (envVarName , tempFile .Name ())
176172 g .Expect (err ).ToNot (g .HaveOccurred ())
@@ -184,7 +180,7 @@ func Test_readConfig(t *testing.T) {
184180 tempFile := createTempFileWithContent (t , fileContent )
185181
186182 envVarName := "NONEXISTENT_CONFIG_VAR"
187- os .Unsetenv (envVarName )
183+ _ = os .Unsetenv (envVarName )
188184
189185 result , err := readConfig (envVarName , tempFile .Name ())
190186 g .Expect (err ).ToNot (g .HaveOccurred ())
@@ -196,15 +192,9 @@ func Test_readQuayConfig(t *testing.T) {
196192 t .Run ("SuccessWithEnvVars" , func (t * testing.T ) {
197193 g .RegisterTestingT (t )
198194
199- // Set environment variables
200- os .Setenv ("QUAY_API_URL" , "https://test-quay.io/api/v1" )
201- os .Setenv ("QUAY_ORG" , "test-org" )
202- os .Setenv ("QUAY_TOKEN" , "test-token" )
203- defer func () {
204- os .Unsetenv ("QUAY_API_URL" )
205- os .Unsetenv ("QUAY_ORG" )
206- os .Unsetenv ("QUAY_TOKEN" )
207- }()
195+ t .Setenv ("QUAY_API_URL" , "https://test-quay.io/api/v1" )
196+ t .Setenv ("QUAY_ORG" , "test-org" )
197+ t .Setenv ("QUAY_TOKEN" , "test-token" )
208198
209199 apiUrl , org , buildQuayClientFunc , err := readQuayConfig ()
210200 g .Expect (err ).ToNot (g .HaveOccurred ())
@@ -222,18 +212,17 @@ func Test_readQuayConfig(t *testing.T) {
222212 g .RegisterTestingT (t )
223213
224214 // Clean env vars
225- os .Unsetenv ("QUAY_API_URL" )
226- os .Unsetenv ("QUAY_ORG" )
227- os .Unsetenv ("QUAY_TOKEN" )
228- os .Unsetenv ("QUAY_ADDITIONAL_CA" )
215+ _ = os .Unsetenv ("QUAY_API_URL" )
216+ _ = os .Unsetenv ("QUAY_ORG" )
217+ _ = os .Unsetenv ("QUAY_TOKEN" )
218+ _ = os .Unsetenv ("QUAY_ADDITIONAL_CA" )
229219
230220 // Create temp files
231221 tempDir , err := os .MkdirTemp ("" , "quay-config-*" )
232222 g .Expect (err ).ToNot (g .HaveOccurred ())
233- defer os .RemoveAll (tempDir )
223+ defer func () { _ = os .RemoveAll (tempDir ) }( )
234224
235- os .Setenv ("QUAY_SECRET_MOUNT_POINT" , tempDir )
236- defer func () { os .Unsetenv ("QUAY_SECRET_MOUNT_POINT" ) }()
225+ t .Setenv ("QUAY_SECRET_MOUNT_POINT" , tempDir )
237226
238227 apiUrlFile := tempDir + "/quayapiurl"
239228 orgFile := tempDir + "/organization"
@@ -257,13 +246,9 @@ func Test_readQuayConfig(t *testing.T) {
257246 g .RegisterTestingT (t )
258247
259248 // Don't set QUAY_API_URL
260- os .Unsetenv ("QUAY_API_URL" )
261- os .Setenv ("QUAY_ORG" , "test-org" )
262- os .Setenv ("QUAY_TOKEN" , "test-token" )
263- defer func () {
264- os .Unsetenv ("QUAY_ORG" )
265- os .Unsetenv ("QUAY_TOKEN" )
266- }()
249+ _ = os .Unsetenv ("QUAY_API_URL" )
250+ t .Setenv ("QUAY_ORG" , "test-org" )
251+ t .Setenv ("QUAY_TOKEN" , "test-token" )
267252
268253 apiUrl , org , buildQuayClientFunc , err := readQuayConfig ()
269254 g .Expect (err ).ToNot (g .HaveOccurred ())
@@ -275,35 +260,23 @@ func Test_readQuayConfig(t *testing.T) {
275260 t .Run ("FailsIfOrgIsNotSet" , func (t * testing.T ) {
276261 g .RegisterTestingT (t )
277262
278- os .Setenv ("QUAY_SECRET_MOUNT_POINT" , "/nonexistent" )
279-
280- os .Setenv ("QUAY_API_URL" , "https://test-quay.io/api/v1" )
281- os .Setenv ("QUAY_ORG" , "" )
282- os .Setenv ("QUAY_TOKEN" , "test-token" )
283- defer func () {
284- os .Unsetenv ("QUAY_API_URL" )
285- os .Unsetenv ("QUAY_ORG" )
286- os .Unsetenv ("QUAY_TOKEN" )
287- }()
263+ t .Setenv ("QUAY_SECRET_MOUNT_POINT" , "/nonexistent" )
264+ t .Setenv ("QUAY_API_URL" , "https://test-quay.io/api/v1" )
265+ t .Setenv ("QUAY_ORG" , "" )
266+ t .Setenv ("QUAY_TOKEN" , "test-token" )
288267
289268 _ , _ , _ , err := readQuayConfig ()
290269 g .Expect (err ).To (g .HaveOccurred ())
291270 g .Expect (err .Error ()).To (g .ContainSubstring ("Quay Org is not set" ))
292271 })
293272
294- t .Run ("FailsIfOrgIsNotSet " , func (t * testing.T ) {
273+ t .Run ("FailsIfTokenIsNotSet " , func (t * testing.T ) {
295274 g .RegisterTestingT (t )
296275
297- os .Setenv ("QUAY_SECRET_MOUNT_POINT" , "/nonexistent" )
298-
299- os .Setenv ("QUAY_API_URL" , "https://test-quay.io/api/v1" )
300- os .Setenv ("QUAY_ORG" , "test-org" )
301- os .Setenv ("QUAY_TOKEN" , "" )
302- defer func () {
303- os .Unsetenv ("QUAY_API_URL" )
304- os .Unsetenv ("QUAY_ORG" )
305- os .Unsetenv ("QUAY_TOKEN" )
306- }()
276+ t .Setenv ("QUAY_SECRET_MOUNT_POINT" , "/nonexistent" )
277+ t .Setenv ("QUAY_API_URL" , "https://test-quay.io/api/v1" )
278+ t .Setenv ("QUAY_ORG" , "test-org" )
279+ t .Setenv ("QUAY_TOKEN" , "" )
307280
308281 _ , _ , _ , err := readQuayConfig ()
309282 g .Expect (err ).To (g .HaveOccurred ())
@@ -314,16 +287,10 @@ func Test_readQuayConfig(t *testing.T) {
314287 g .RegisterTestingT (t )
315288
316289 // Set an invalid CA path to trigger error in buildQuayHttpClient
317- os .Setenv ("QUAY_ADDITIONAL_CA" , "/nonexistent/ca/path.pem" )
318- os .Setenv ("QUAY_API_URL" , "https://test-quay.io/api/v1" )
319- os .Setenv ("QUAY_ORG" , "test-org" )
320- os .Setenv ("QUAY_TOKEN" , "test-token" )
321- defer func () {
322- os .Unsetenv ("QUAY_ADDITIONAL_CA" )
323- os .Unsetenv ("QUAY_API_URL" )
324- os .Unsetenv ("QUAY_ORG" )
325- os .Unsetenv ("QUAY_TOKEN" )
326- }()
290+ t .Setenv ("QUAY_ADDITIONAL_CA" , "/nonexistent/ca/path.pem" )
291+ t .Setenv ("QUAY_API_URL" , "https://test-quay.io/api/v1" )
292+ t .Setenv ("QUAY_ORG" , "test-org" )
293+ t .Setenv ("QUAY_TOKEN" , "test-token" )
327294
328295 _ , _ , _ , err := readQuayConfig ()
329296 g .Expect (err ).To (g .HaveOccurred ())
@@ -334,14 +301,9 @@ func Test_readQuayConfig(t *testing.T) {
334301 g .RegisterTestingT (t )
335302
336303 // Set initial token
337- os .Setenv ("QUAY_API_URL" , "https://test-quay.io/api/v1" )
338- os .Setenv ("QUAY_ORG" , "test-org" )
339- os .Setenv ("QUAY_TOKEN" , "initial-token" )
340- defer func () {
341- os .Unsetenv ("QUAY_API_URL" )
342- os .Unsetenv ("QUAY_ORG" )
343- os .Unsetenv ("QUAY_TOKEN" )
344- }()
304+ t .Setenv ("QUAY_API_URL" , "https://test-quay.io/api/v1" )
305+ t .Setenv ("QUAY_ORG" , "test-org" )
306+ t .Setenv ("QUAY_TOKEN" , "initial-token" )
345307
346308 _ , _ , buildQuayClientFunc , err := readQuayConfig ()
347309 g .Expect (err ).ToNot (g .HaveOccurred ())
@@ -354,7 +316,7 @@ func Test_readQuayConfig(t *testing.T) {
354316 g .Expect (c1 .AuthToken ).To (g .Equal ("initial-token" ))
355317
356318 // Change token (simulating rotation)
357- os .Setenv ("QUAY_TOKEN" , "rotated-token" )
319+ t .Setenv ("QUAY_TOKEN" , "rotated-token" )
358320
359321 // Get second client - should use new token
360322 client2 , err := buildQuayClientFunc ()
@@ -367,16 +329,15 @@ func Test_readQuayConfig(t *testing.T) {
367329 t .Run ("TokenRotationViaFile" , func (t * testing.T ) {
368330 g .RegisterTestingT (t )
369331
370- os .Unsetenv ("QUAY_API_URL" )
371- os .Unsetenv ("QUAY_ORG" )
372- os .Unsetenv ("QUAY_TOKEN" )
332+ _ = os .Unsetenv ("QUAY_API_URL" )
333+ _ = os .Unsetenv ("QUAY_ORG" )
334+ _ = os .Unsetenv ("QUAY_TOKEN" )
373335
374336 tempDir , err := os .MkdirTemp ("" , "quay-config-*" )
375337 g .Expect (err ).ToNot (g .HaveOccurred ())
376- defer os .RemoveAll (tempDir )
338+ defer func () { _ = os .RemoveAll (tempDir ) }( )
377339
378- os .Setenv ("QUAY_SECRET_MOUNT_POINT" , tempDir )
379- defer func () { os .Unsetenv ("QUAY_SECRET_MOUNT_POINT" ) }()
340+ t .Setenv ("QUAY_SECRET_MOUNT_POINT" , tempDir )
380341
381342 apiUrlFile := tempDir + "/quayapiurl"
382343 orgFile := tempDir + "/organization"
@@ -417,7 +378,7 @@ func Test_buildQuayHttpClient(t *testing.T) {
417378 g .RegisterTestingT (t )
418379
419380 // Ensure no custom CA is set
420- os .Unsetenv ("QUAY_ADDITIONAL_CA" )
381+ _ = os .Unsetenv ("QUAY_ADDITIONAL_CA" )
421382
422383 client , err := buildQuayHttpClient ()
423384 g .Expect (err ).ToNot (g .HaveOccurred ())
@@ -448,17 +409,16 @@ cG3Kp1aafIjtenvEY2y9gYClEx7q4OIsN1Lw/OUQsUbTm50=
448409-----END CERTIFICATE-----`
449410
450411 tempCaCertFile , err := os .CreateTemp ("" , "ca-cert-*.pem" )
451- defer os .Remove (tempCaCertFile .Name ())
452412 g .Expect (err ).ToNot (g .HaveOccurred (), "failed to create CA cert test file" )
413+ defer func () { _ = os .Remove (tempCaCertFile .Name ()) }()
453414
454415 _ , err = tempCaCertFile .Write ([]byte (caCert ))
455416 g .Expect (err ).ToNot (g .HaveOccurred (), "failed to write to CA cert test file" )
456417 err = tempCaCertFile .Close ()
457418 g .Expect (err ).ToNot (g .HaveOccurred ())
458419
459420 // Set the environment variable
460- os .Setenv ("QUAY_ADDITIONAL_CA" , tempCaCertFile .Name ())
461- defer os .Unsetenv ("QUAY_ADDITIONAL_CA" )
421+ t .Setenv ("QUAY_ADDITIONAL_CA" , tempCaCertFile .Name ())
462422
463423 client , err := buildQuayHttpClient ()
464424
@@ -497,8 +457,7 @@ cG3Kp1aafIjtenvEY2y9gYClEx7q4OIsN1Lw/OUQsUbTm50=
497457 g .RegisterTestingT (t )
498458
499459 // Set an invalid CA path
500- os .Setenv ("QUAY_ADDITIONAL_CA" , "/nonexistent/path/to/ca.pem" )
501- defer os .Unsetenv ("QUAY_ADDITIONAL_CA" )
460+ t .Setenv ("QUAY_ADDITIONAL_CA" , "/nonexistent/path/to/ca.pem" )
502461
503462 _ , err := buildQuayHttpClient ()
504463 g .Expect (err ).To (g .HaveOccurred (), "should have failed due to invalid CA cert path" )
@@ -510,16 +469,15 @@ cG3Kp1aafIjtenvEY2y9gYClEx7q4OIsN1Lw/OUQsUbTm50=
510469 const caCertInvalid = "invalid certificate content"
511470
512471 tempCaCertFile , err := os .CreateTemp ("" , "ca-cert-*.pem" )
513- defer os .Remove (tempCaCertFile .Name ())
514472 g .Expect (err ).ToNot (g .HaveOccurred (), "failed to create CA cert test file" )
473+ defer func () { _ = os .Remove (tempCaCertFile .Name ()) }()
515474
516475 _ , err = tempCaCertFile .Write ([]byte (caCertInvalid ))
517476 g .Expect (err ).ToNot (g .HaveOccurred (), "failed to write to CA cert test file" )
518477 err = tempCaCertFile .Close ()
519478 g .Expect (err ).ToNot (g .HaveOccurred ())
520479
521- os .Setenv ("QUAY_ADDITIONAL_CA" , tempCaCertFile .Name ())
522- defer os .Unsetenv ("QUAY_ADDITIONAL_CA" )
480+ t .Setenv ("QUAY_ADDITIONAL_CA" , tempCaCertFile .Name ())
523481
524482 _ , err = buildQuayHttpClient ()
525483 g .Expect (err ).To (g .HaveOccurred (), "should have failed due to invalid CA cert" )
0 commit comments