@@ -18,7 +18,6 @@ package util
18
18
19
19
import (
20
20
"encoding/base64"
21
- "io/ioutil"
22
21
"os"
23
22
"path/filepath"
24
23
"reflect"
@@ -130,7 +129,7 @@ func TestPathsToRemove(t *testing.T) {
130
129
name string
131
130
payload1 map [string ]FileProjection
132
131
payload2 map [string ]FileProjection
133
- expected sets.String
132
+ expected sets.Set [ string ]
134
133
}{
135
134
{
136
135
name : "simple" ,
@@ -141,7 +140,7 @@ func TestPathsToRemove(t *testing.T) {
141
140
payload2 : map [string ]FileProjection {
142
141
"foo.txt" : {Mode : 0644 , Data : []byte ("foo" )},
143
142
},
144
- expected : sets .NewString ("bar.txt" ),
143
+ expected : sets .New ("bar.txt" ),
145
144
},
146
145
{
147
146
name : "simple 2" ,
@@ -152,7 +151,7 @@ func TestPathsToRemove(t *testing.T) {
152
151
payload2 : map [string ]FileProjection {
153
152
"foo.txt" : {Mode : 0644 , Data : []byte ("foo" )},
154
153
},
155
- expected : sets .NewString ("zip/bar.txt" , "zip" ),
154
+ expected : sets .New ("zip/bar.txt" , "zip" ),
156
155
},
157
156
{
158
157
name : "subdirs 1" ,
@@ -163,7 +162,7 @@ func TestPathsToRemove(t *testing.T) {
163
162
payload2 : map [string ]FileProjection {
164
163
"foo.txt" : {Mode : 0644 , Data : []byte ("foo" )},
165
164
},
166
- expected : sets .NewString ("zip/zap/bar.txt" , "zip" , "zip/zap" ),
165
+ expected : sets .New ("zip/zap/bar.txt" , "zip" , "zip/zap" ),
167
166
},
168
167
{
169
168
name : "subdirs 2" ,
@@ -174,7 +173,7 @@ func TestPathsToRemove(t *testing.T) {
174
173
payload2 : map [string ]FileProjection {
175
174
"foo.txt" : {Mode : 0644 , Data : []byte ("foo" )},
176
175
},
177
- expected : sets .NewString ("zip/1/2/3/4/bar.txt" , "zip" , "zip/1" , "zip/1/2" , "zip/1/2/3" , "zip/1/2/3/4" ),
176
+ expected : sets .New ("zip/1/2/3/4/bar.txt" , "zip" , "zip/1" , "zip/1/2" , "zip/1/2/3" , "zip/1/2/3/4" ),
178
177
},
179
178
{
180
179
name : "subdirs 3" ,
@@ -186,7 +185,7 @@ func TestPathsToRemove(t *testing.T) {
186
185
payload2 : map [string ]FileProjection {
187
186
"foo.txt" : {Mode : 0644 , Data : []byte ("foo" )},
188
187
},
189
- expected : sets .NewString ("zip/1/2/3/4/bar.txt" , "zip" , "zip/1" , "zip/1/2" , "zip/1/2/3" , "zip/1/2/3/4" , "zap" , "zap/a" , "zap/a/b" , "zap/a/b/c" , "zap/a/b/c/bar.txt" ),
188
+ expected : sets .New ("zip/1/2/3/4/bar.txt" , "zip" , "zip/1" , "zip/1/2" , "zip/1/2/3" , "zip/1/2/3/4" , "zap" , "zap/a" , "zap/a/b" , "zap/a/b/c" , "zap/a/b/c/bar.txt" ),
190
189
},
191
190
{
192
191
name : "subdirs 4" ,
@@ -200,7 +199,7 @@ func TestPathsToRemove(t *testing.T) {
200
199
"foo.txt" : {Mode : 0644 , Data : []byte ("foo" )},
201
200
"zap/1/2/magic.txt" : {Mode : 0644 , Data : []byte ("indigo" )},
202
201
},
203
- expected : sets .NewString ("zap/1/2/3/4/bar.txt" , "zap/1/2/3" , "zap/1/2/3/4" , "zap/1/2/3/4/bar.txt" , "zap/1/2/c" , "zap/1/2/c/bar.txt" ),
202
+ expected : sets .New ("zap/1/2/3/4/bar.txt" , "zap/1/2/3" , "zap/1/2/3/4" , "zap/1/2/3/4/bar.txt" , "zap/1/2/c" , "zap/1/2/c/bar.txt" ),
204
203
},
205
204
{
206
205
name : "subdirs 5" ,
@@ -213,7 +212,7 @@ func TestPathsToRemove(t *testing.T) {
213
212
"foo.txt" : {Mode : 0644 , Data : []byte ("foo" )},
214
213
"zap/1/2/magic.txt" : {Mode : 0644 , Data : []byte ("indigo" )},
215
214
},
216
- expected : sets .NewString ("zap/1/2/3/4/bar.txt" , "zap/1/2/3" , "zap/1/2/3/4" , "zap/1/2/3/4/bar.txt" , "zap/1/2/c" , "zap/1/2/c/bar.txt" ),
215
+ expected : sets .New ("zap/1/2/3/4/bar.txt" , "zap/1/2/3" , "zap/1/2/3/4" , "zap/1/2/3/4/bar.txt" , "zap/1/2/c" , "zap/1/2/c/bar.txt" ),
217
216
},
218
217
}
219
218
@@ -762,7 +761,7 @@ func checkVolumeContents(targetDir, tcName string, payload map[string]FileProjec
762
761
return nil
763
762
}
764
763
765
- content , err := ioutil .ReadFile (path )
764
+ content , err := os .ReadFile (path )
766
765
if err != nil {
767
766
return err
768
767
}
@@ -777,15 +776,21 @@ func checkVolumeContents(targetDir, tcName string, payload map[string]FileProjec
777
776
return nil
778
777
}
779
778
780
- d , err := ioutil .ReadDir (targetDir )
779
+ d , err := os .ReadDir (targetDir )
781
780
if err != nil {
782
781
t .Errorf ("Unable to read dir %v: %v" , targetDir , err )
783
782
return
784
783
}
785
- for _ , info := range d {
786
- if strings .HasPrefix (info .Name (), ".." ) {
784
+ for _ , entry := range d {
785
+ if strings .HasPrefix (entry .Name (), ".." ) {
787
786
continue
788
787
}
788
+
789
+ info , err := entry .Info ()
790
+ if err != nil {
791
+ continue
792
+ }
793
+
789
794
if info .Mode ()& os .ModeSymlink != 0 {
790
795
p := filepath .Join (targetDir , info .Name ())
791
796
actual , err := os .Readlink (p )
@@ -815,7 +820,7 @@ func TestValidatePayload(t *testing.T) {
815
820
cases := []struct {
816
821
name string
817
822
payload map [string ]FileProjection
818
- expected sets.String
823
+ expected sets.Set [ string ]
819
824
valid bool
820
825
}{
821
826
{
@@ -825,7 +830,7 @@ func TestValidatePayload(t *testing.T) {
825
830
"bar" : {},
826
831
},
827
832
valid : true ,
828
- expected : sets .NewString ("foo" , "bar" ),
833
+ expected : sets .New ("foo" , "bar" ),
829
834
},
830
835
{
831
836
name : "payload with path length > 4096 is invalid" ,
@@ -868,11 +873,11 @@ func TestValidatePayload(t *testing.T) {
868
873
"foo////bar" : {},
869
874
},
870
875
valid : true ,
871
- expected : sets .NewString ("foo/bar" ),
876
+ expected : sets .New ("foo/bar" ),
872
877
},
873
878
}
874
- getPayloadPaths := func (payload map [string ]FileProjection ) sets.String {
875
- paths := sets .NewString ()
879
+ getPayloadPaths := func (payload map [string ]FileProjection ) sets.Set [ string ] {
880
+ paths := sets .New [ string ] ()
876
881
for path := range payload {
877
882
paths .Insert (path )
878
883
}
0 commit comments