@@ -180,30 +180,24 @@ var _ = Describe("Config", func() {
180
180
181
181
Describe ("readStorageTmp" , func () {
182
182
It ("test image_copy_tmp_dir='storage'" , func () {
183
+ t := GinkgoT ()
183
184
// Reload from new configuration file
184
- testFile := "testdata /temp.conf"
185
+ testFile := t . TempDir () + " /temp.conf"
185
186
content := `[engine]
186
187
image_copy_tmp_dir="storage"`
187
188
err := os .WriteFile (testFile , []byte (content ), os .ModePerm )
188
189
// Then
189
190
gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
190
- defer os .Remove (testFile )
191
191
192
192
config , _ := NewConfig (testFile )
193
193
path , err := config .ImageCopyTmpDir ()
194
194
gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
195
195
gomega .Expect (path ).To (gomega .ContainSubstring ("containers/storage/tmp" ))
196
196
// Given we do
197
- oldTMPDIR , set := os .LookupEnv ("TMPDIR" )
198
- os .Setenv ("TMPDIR" , "/var/tmp/foobar" )
197
+ t .Setenv ("TMPDIR" , "/var/tmp/foobar" )
199
198
path , err = config .ImageCopyTmpDir ()
200
199
gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
201
200
gomega .Expect (path ).To (gomega .BeEquivalentTo ("/var/tmp/foobar" ))
202
- if set {
203
- os .Setenv ("TMPDIR" , oldTMPDIR )
204
- } else {
205
- os .Unsetenv ("TMPDIR" )
206
- }
207
201
})
208
202
})
209
203
@@ -360,27 +354,15 @@ image_copy_tmp_dir="storage"`
360
354
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" ,
361
355
}
362
356
httpEnvs := append ([]string {"HTTP_PROXY=1.2.3.4" }, envs ... )
363
- oldProxy , proxyEnvSet := os .LookupEnv ("HTTP_PROXY" )
364
- os .Setenv ("HTTP_PROXY" , "1.2.3.4" )
365
- oldFoo , fooEnvSet := os .LookupEnv ("foo" )
366
- os .Setenv ("foo" , "bar" )
357
+ t := GinkgoT ()
358
+ t .Setenv ("HTTP_PROXY" , "1.2.3.4" )
359
+ t .Setenv ("foo" , "bar" )
367
360
368
361
defaultConfig , _ := defaultConfig ()
369
362
gomega .Expect (defaultConfig .GetDefaultEnvEx (false , false )).To (gomega .BeEquivalentTo (envs ))
370
363
gomega .Expect (defaultConfig .GetDefaultEnvEx (false , true )).To (gomega .BeEquivalentTo (httpEnvs ))
371
364
gomega .Expect (strings .Join (defaultConfig .GetDefaultEnvEx (true , true ), "," )).To (gomega .ContainSubstring ("HTTP_PROXY" ))
372
365
gomega .Expect (strings .Join (defaultConfig .GetDefaultEnvEx (true , true ), "," )).To (gomega .ContainSubstring ("foo" ))
373
- // Undo that
374
- if proxyEnvSet {
375
- os .Setenv ("HTTP_PROXY" , oldProxy )
376
- } else {
377
- os .Unsetenv ("HTTP_PROXY" )
378
- }
379
- if fooEnvSet {
380
- os .Setenv ("foo" , oldFoo )
381
- } else {
382
- os .Unsetenv ("foo" )
383
- }
384
366
})
385
367
386
368
It ("should succeed with commented out configuration" , func () {
@@ -461,16 +443,9 @@ image_copy_tmp_dir="storage"`
461
443
}
462
444
463
445
// Given we do
464
- oldContainersConf , envSet := os .LookupEnv (containersConfEnv )
465
- os .Setenv (containersConfEnv , "/dev/null" )
446
+ GinkgoT ().Setenv (containersConfEnv , "/dev/null" )
466
447
// When
467
448
config , err := NewConfig ("" )
468
- // Undo that
469
- if envSet {
470
- os .Setenv (containersConfEnv , oldContainersConf )
471
- } else {
472
- os .Unsetenv (containersConfEnv )
473
- }
474
449
// Then
475
450
gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
476
451
gomega .Expect (config .Containers .ApparmorProfile ).To (gomega .Equal (apparmor .Profile ))
@@ -529,16 +504,9 @@ image_copy_tmp_dir="storage"`
529
504
530
505
It ("contents of passed-in file should override others" , func () {
531
506
// Given we do
532
- oldContainersConf , envSet := os .LookupEnv (containersConfEnv )
533
- os .Setenv (containersConfEnv , "containers.conf" )
507
+ GinkgoT ().Setenv (containersConfEnv , "containers.conf" )
534
508
// When
535
509
config , err := NewConfig ("testdata/containers_override.conf" )
536
- // Undo that
537
- if envSet {
538
- os .Setenv (containersConfEnv , oldContainersConf )
539
- } else {
540
- os .Unsetenv (containersConfEnv )
541
- }
542
510
543
511
crunWasm := "crun-wasm"
544
512
PlatformToOCIRuntimeMap := map [string ]string {
@@ -698,24 +666,12 @@ image_copy_tmp_dir="storage"`
698
666
})
699
667
700
668
Describe ("Service Destinations" , func () {
701
- ConfPath := struct {
702
- Value string
703
- IsSet bool
704
- }{}
705
-
706
669
BeforeEach (func () {
707
- ConfPath .Value , ConfPath .IsSet = os .LookupEnv (containersConfEnv )
708
- conf , _ := os .CreateTemp ("" , "containersconf" )
709
- os .Setenv (containersConfEnv , conf .Name ())
710
- })
711
-
712
- AfterEach (func () {
713
- os .Remove (os .Getenv (containersConfEnv ))
714
- if ConfPath .IsSet {
715
- os .Setenv (containersConfEnv , ConfPath .Value )
716
- } else {
717
- os .Unsetenv (containersConfEnv )
718
- }
670
+ t := GinkgoT ()
671
+ name := t .TempDir () + "/containersconf"
672
+ err := os .WriteFile (name , []byte {}, os .ModePerm )
673
+ gomega .Expect (err ).ShouldNot (gomega .HaveOccurred ())
674
+ t .Setenv (containersConfEnv , name )
719
675
})
720
676
721
677
It ("test addConfigs" , func () {
@@ -786,36 +742,24 @@ image_copy_tmp_dir="storage"`
786
742
787
743
Describe ("Reload" , func () {
788
744
It ("test new config from reload" , func () {
745
+ t := GinkgoT ()
789
746
// Default configuration
790
747
defaultTestFile := "testdata/containers_default.conf"
791
- oldEnv , set := os .LookupEnv (containersConfEnv )
792
- os .Setenv (containersConfEnv , defaultTestFile )
748
+ t .Setenv (containersConfEnv , defaultTestFile )
793
749
cfg , err := Default ()
794
750
gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
795
- if set {
796
- os .Setenv (containersConfEnv , oldEnv )
797
- } else {
798
- os .Unsetenv (containersConfEnv )
799
- }
800
751
801
752
// Reload from new configuration file
802
- testFile := "testdata /temp.conf"
753
+ testFile := t . TempDir () + " /temp.conf"
803
754
content := `[containers]
804
755
env=["foo=bar"]`
805
756
err = os .WriteFile (testFile , []byte (content ), os .ModePerm )
806
- defer os .Remove (testFile )
807
757
gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
808
- oldEnv , set = os .LookupEnv (containersConfEnv )
809
- os .Setenv (containersConfEnv , testFile )
758
+ t .Setenv (containersConfEnv , testFile )
810
759
_ , err = Reload ()
811
760
gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
812
761
newCfg , err := Default ()
813
762
gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
814
- if set {
815
- os .Setenv (containersConfEnv , oldEnv )
816
- } else {
817
- os .Unsetenv (containersConfEnv )
818
- }
819
763
820
764
expectOldEnv := []string {"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" }
821
765
expectNewEnv := []string {"foo=bar" }
@@ -837,15 +781,14 @@ env=["foo=bar"]`
837
781
})
838
782
839
783
It ("CONTAINERS_CONF_OVERRIDE" , func () {
840
- os . Setenv ( "CONTAINERS_CONF_OVERRIDE" , "testdata/containers_override.conf" )
841
- defer os . Unsetenv ("CONTAINERS_CONF_OVERRIDE" )
784
+ t := GinkgoT ( )
785
+ t . Setenv ("CONTAINERS_CONF_OVERRIDE" , "testdata/containers_override.conf " )
842
786
config , err := NewConfig ("" )
843
787
gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
844
788
gomega .Expect (config .Containers .ApparmorProfile ).To (gomega .Equal ("overridden-default" ))
845
789
846
790
// Make sure that _OVERRIDE is loaded even when CONTAINERS_CONF is set.
847
- os .Setenv (containersConfEnv , "testdata/containers_default.conf" )
848
- defer os .Unsetenv (containersConfEnv )
791
+ t .Setenv (containersConfEnv , "testdata/containers_default.conf" )
849
792
config , err = NewConfig ("" )
850
793
gomega .Expect (err ).ToNot (gomega .HaveOccurred ())
851
794
gomega .Expect (config .Containers .ApparmorProfile ).To (gomega .Equal ("overridden-default" ))
0 commit comments