1- // Copyright (c) 2019-2022 , Sylabs Inc. All rights reserved.
1+ // Copyright (c) 2019-2025 , Sylabs Inc. All rights reserved.
22// This software is licensed under a 3-clause BSD license. Please consult the
33// LICENSE.md file distributed with the sources of this project regarding your
44// rights to use or distribute this software.
@@ -7,6 +7,7 @@ package singularity
77
88import (
99 "os"
10+ "path/filepath"
1011 "testing"
1112
1213 "github.com/sylabs/singularity/v4/internal/pkg/remote"
@@ -23,12 +24,7 @@ const (
2324)
2425
2526func createInvalidCfgFile (t * testing.T ) string {
26- f , err := os .CreateTemp ("" , "" )
27- if err != nil {
28- t .Fatalf ("cannot create temporary configuration file for testing: %s\n " , err )
29- }
30-
31- path := f .Name ()
27+ path := filepath .Join (t .TempDir (), "invalid.yml" )
3228
3329 // Set an invalid configuration
3430 type aDummyStruct struct {
@@ -40,24 +36,18 @@ func createInvalidCfgFile(t *testing.T) string {
4036
4137 yaml , err := yaml .Marshal (cfg )
4238 if err != nil {
43- f .Close ()
44- os .Remove (path )
4539 t .Fatalf ("cannot marshal YAML: %s\n " , err )
4640 }
4741
48- f .Write (yaml )
49- f .Close ()
42+ if err := os .WriteFile (path , yaml , 0o644 ); err != nil {
43+ t .Fatal (err )
44+ }
5045
5146 return path
5247}
5348
5449func createValidCfgFile (t * testing.T ) string {
55- f , err := os .CreateTemp ("" , "" )
56- if err != nil {
57- t .Fatalf ("cannot create temporary configuration file for testing: %s\n " , err )
58- }
59-
60- path := f .Name ()
50+ path := filepath .Join (t .TempDir (), "valid.yml" )
6151
6252 // Set a valid configuration
6353 cfg := remote.Config {
@@ -76,13 +66,12 @@ func createValidCfgFile(t *testing.T) string {
7666
7767 yaml , err := yaml .Marshal (cfg )
7868 if err != nil {
79- f .Close ()
80- os .Remove (path )
8169 t .Fatalf ("cannot marshal YAML: %s\n " , err )
8270 }
8371
84- f .Write (yaml )
85- f .Close ()
72+ if err := os .WriteFile (path , yaml , 0o644 ); err != nil {
73+ t .Fatal (err )
74+ }
8675
8776 return path
8877}
0 commit comments