@@ -633,36 +633,43 @@ func TestSafeMakeDir(t *testing.T) {
633
633
},
634
634
}
635
635
636
- for _ , test := range tests {
637
- klog .V (4 ).Infof ("test %q" , test .name )
638
- base , err := ioutil .TempDir ("" , "safe-make-dir-" + test .name + "-" )
639
- if err != nil {
640
- t .Fatalf (err .Error ())
641
- }
642
- test .prepare (base )
643
- pathToCreate := filepath .Join (base , test .path )
644
- err = doSafeMakeDir (pathToCreate , base , test .perm )
645
- if err != nil && ! test .expectError {
646
- t .Errorf ("test %q: %s" , test .name , err )
647
- }
648
- if err != nil {
649
- klog .Infof ("got error: %s" , err )
650
- }
651
- if err == nil && test .expectError {
652
- t .Errorf ("test %q: expected error, got none" , test .name )
653
- }
654
-
655
- if test .checkPath != "" {
656
- st , err := os .Stat (filepath .Join (base , test .checkPath ))
636
+ for i := range tests {
637
+ test := tests [i ]
638
+ t .Run (test .name , func (t * testing.T ) {
639
+ base , err := ioutil .TempDir ("" , "safe-make-dir-" + test .name + "-" )
657
640
if err != nil {
658
- t .Errorf ( "test %q: cannot read path %s" , test . name , test . checkPath )
641
+ t .Fatalf ( err . Error () )
659
642
}
660
- if st .Mode () != test .perm {
661
- t .Errorf ("test %q: expected permissions %o, got %o" , test .name , test .perm , st .Mode ())
643
+ defer os .RemoveAll (base )
644
+ test .prepare (base )
645
+ pathToCreate := filepath .Join (base , test .path )
646
+ err = doSafeMakeDir (pathToCreate , base , test .perm )
647
+ if err != nil && ! test .expectError {
648
+ t .Fatal (err )
649
+ }
650
+ if err != nil {
651
+ t .Logf ("got error: %s" , err )
652
+ }
653
+ if err == nil && test .expectError {
654
+ t .Fatalf ("expected error, got none" )
662
655
}
663
- }
664
656
665
- os .RemoveAll (base )
657
+ if test .checkPath != "" {
658
+ st , err := os .Stat (filepath .Join (base , test .checkPath ))
659
+ if err != nil {
660
+ t .Fatalf ("cannot read path %s" , test .checkPath )
661
+ }
662
+ actualMode := st .Mode ()
663
+ if actualMode != test .perm {
664
+ if actualMode ^ test .perm == os .ModeSetgid && test .perm & os .ModeSetgid == 0 {
665
+ // when TMPDIR is a kubernetes emptydir, the sticky gid bit is set due to fsgroup
666
+ t .Logf ("masking bit from %o" , actualMode )
667
+ } else {
668
+ t .Errorf ("expected permissions %o, got %o (%b)" , test .perm , actualMode , test .perm ^ actualMode )
669
+ }
670
+ }
671
+ }
672
+ })
666
673
}
667
674
}
668
675
0 commit comments