@@ -21,7 +21,6 @@ import (
21
21
"errors"
22
22
"fmt"
23
23
"os"
24
- "path/filepath"
25
24
"reflect"
26
25
"sync"
27
26
"testing"
@@ -33,6 +32,7 @@ import (
33
32
"google.golang.org/grpc/status"
34
33
35
34
"sigs.k8s.io/secrets-store-csi-driver/pkg/test_utils/tmpdir"
35
+ "sigs.k8s.io/secrets-store-csi-driver/pkg/util/fileutil"
36
36
"sigs.k8s.io/secrets-store-csi-driver/provider/fake"
37
37
"sigs.k8s.io/secrets-store-csi-driver/provider/v1alpha1"
38
38
)
@@ -107,6 +107,33 @@ func TestMountContent(t *testing.T) {
107
107
"bar" : 0777 ,
108
108
},
109
109
},
110
+ {
111
+ name : "provider response with nested files" ,
112
+ permission : "777" ,
113
+ files : []* v1alpha1.File {
114
+ {
115
+ Path : "foo" ,
116
+ Mode : 0644 ,
117
+ Contents : []byte ("foo" ),
118
+ },
119
+ {
120
+ Path : "baz/bar" ,
121
+ Mode : 0777 ,
122
+ Contents : []byte ("bar" ),
123
+ },
124
+ {
125
+ Path : "baz/qux" ,
126
+ Mode : 0777 ,
127
+ Contents : []byte ("qux" ),
128
+ },
129
+ },
130
+ objectVersions : map [string ]string {"foo" : "v1" },
131
+ expectedFiles : map [string ]os.FileMode {
132
+ "foo" : 0644 ,
133
+ "baz/bar" : 0777 ,
134
+ "baz/qux" : 0777 ,
135
+ },
136
+ },
110
137
}
111
138
112
139
for _ , test := range cases {
@@ -140,18 +167,17 @@ func TestMountContent(t *testing.T) {
140
167
141
168
// check that file was written
142
169
gotFiles := make (map [string ]os.FileMode )
143
- filepath . Walk ( targetPath , func ( path string , info os. FileInfo , err error ) error {
144
- // skip mount folder
145
- if path == targetPath {
146
- return nil
147
- }
148
- rel , err := filepath . Rel ( targetPath , path )
170
+ paths , err := fileutil . GetMountedFiles ( targetPath )
171
+ if err != nil {
172
+ t . Fatalf ( "unable to read mounted files: %s" , err )
173
+ }
174
+ for rel , abs := range paths {
175
+ info , err := os . Lstat ( abs )
149
176
if err != nil {
150
- return err
177
+ t . Fatalf ( "unable to read mounted files: %s" , err )
151
178
}
152
179
gotFiles [rel ] = info .Mode ()
153
- return nil
154
- })
180
+ }
155
181
156
182
if diff := cmp .Diff (test .expectedFiles , gotFiles ); diff != "" {
157
183
t .Errorf ("MountContent() file mismatch (-want +got):\n %s" , diff )
0 commit comments