@@ -21,8 +21,8 @@ import (
21
21
"errors"
22
22
"fmt"
23
23
"os"
24
- "path/filepath"
25
24
"reflect"
25
+ "runtime"
26
26
"sync"
27
27
"testing"
28
28
"time"
@@ -33,6 +33,7 @@ import (
33
33
"google.golang.org/grpc/status"
34
34
35
35
"sigs.k8s.io/secrets-store-csi-driver/pkg/test_utils/tmpdir"
36
+ "sigs.k8s.io/secrets-store-csi-driver/pkg/util/fileutil"
36
37
"sigs.k8s.io/secrets-store-csi-driver/provider/fake"
37
38
"sigs.k8s.io/secrets-store-csi-driver/provider/v1alpha1"
38
39
)
@@ -64,6 +65,7 @@ func TestMountContent(t *testing.T) {
64
65
files []* v1alpha1.File
65
66
// expectations
66
67
expectedFiles map [string ]os.FileMode
68
+ skipon string
67
69
}{
68
70
{
69
71
name : "provider successful response (no files)" ,
@@ -77,13 +79,13 @@ func TestMountContent(t *testing.T) {
77
79
files : []* v1alpha1.File {
78
80
{
79
81
Path : "foo" ,
80
- Mode : 0644 ,
82
+ Mode : 0666 ,
81
83
Contents : []byte ("foo" ),
82
84
},
83
85
},
84
86
objectVersions : map [string ]string {"foo" : "v1" },
85
87
expectedFiles : map [string ]os.FileMode {
86
- "foo" : 0644 ,
88
+ "foo" : 0666 ,
87
89
},
88
90
},
89
91
{
@@ -92,25 +94,87 @@ func TestMountContent(t *testing.T) {
92
94
files : []* v1alpha1.File {
93
95
{
94
96
Path : "foo" ,
95
- Mode : 0644 ,
97
+ Mode : 0666 ,
96
98
Contents : []byte ("foo" ),
97
99
},
98
100
{
99
101
Path : "bar" ,
102
+ Mode : 0444 ,
103
+ Contents : []byte ("bar" ),
104
+ },
105
+ },
106
+ objectVersions : map [string ]string {"foo" : "v1" },
107
+ expectedFiles : map [string ]os.FileMode {
108
+ "foo" : 0666 ,
109
+ "bar" : 0444 ,
110
+ },
111
+ },
112
+ {
113
+ name : "provider response with nested files (linux)" ,
114
+ permission : "777" ,
115
+ files : []* v1alpha1.File {
116
+ {
117
+ Path : "foo" ,
118
+ Mode : 0644 ,
119
+ Contents : []byte ("foo" ),
120
+ },
121
+ {
122
+ Path : "baz/bar" ,
100
123
Mode : 0777 ,
101
124
Contents : []byte ("bar" ),
102
125
},
126
+ {
127
+ Path : "baz/qux" ,
128
+ Mode : 0777 ,
129
+ Contents : []byte ("qux" ),
130
+ },
103
131
},
104
132
objectVersions : map [string ]string {"foo" : "v1" },
105
133
expectedFiles : map [string ]os.FileMode {
106
- "foo" : 0644 ,
107
- "bar" : 0777 ,
134
+ "foo" : 0644 ,
135
+ "baz/bar" : 0777 ,
136
+ "baz/qux" : 0777 ,
137
+ },
138
+ skipon : "windows" ,
139
+ },
140
+ {
141
+ // note: this is a bit weird because the path `baz\bar` on windows
142
+ // should be a file `bar` nested in a folder `baz`. it _actually_
143
+ // works on linux though because the `\` character is just treated
144
+ // as part of the filename.
145
+ name : "provider response with nested files (windows)" ,
146
+ permission : "777" ,
147
+ files : []* v1alpha1.File {
148
+ {
149
+ Path : "foo" ,
150
+ Mode : 0444 ,
151
+ Contents : []byte ("foo" ),
152
+ },
153
+ {
154
+ Path : "baz\\ bar" ,
155
+ Mode : 0444 ,
156
+ Contents : []byte ("bar" ),
157
+ },
158
+ {
159
+ Path : "baz\\ qux" ,
160
+ Mode : 0666 ,
161
+ Contents : []byte ("qux" ),
162
+ },
163
+ },
164
+ objectVersions : map [string ]string {"foo" : "v1" },
165
+ expectedFiles : map [string ]os.FileMode {
166
+ "foo" : 0444 ,
167
+ "baz\\ bar" : 0444 ,
168
+ "baz\\ qux" : 0666 ,
108
169
},
109
170
},
110
171
}
111
172
112
173
for _ , test := range cases {
113
174
t .Run (test .name , func (t * testing.T ) {
175
+ if test .skipon == runtime .GOOS {
176
+ t .SkipNow ()
177
+ }
114
178
socketPath := tmpdir .New (t , "" , "ut" )
115
179
targetPath := tmpdir .New (t , "" , "ut" )
116
180
@@ -140,18 +204,17 @@ func TestMountContent(t *testing.T) {
140
204
141
205
// check that file was written
142
206
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 )
207
+ paths , err := fileutil . GetMountedFiles ( targetPath )
208
+ if err != nil {
209
+ t . Fatalf ( "unable to read mounted files: %s" , err )
210
+ }
211
+ for rel , abs := range paths {
212
+ info , err := os . Lstat ( abs )
149
213
if err != nil {
150
- return err
214
+ t . Fatalf ( "unable to read mounted files: %s" , err )
151
215
}
152
216
gotFiles [rel ] = info .Mode ()
153
- return nil
154
- })
217
+ }
155
218
156
219
if diff := cmp .Diff (test .expectedFiles , gotFiles ); diff != "" {
157
220
t .Errorf ("MountContent() file mismatch (-want +got):\n %s" , diff )
0 commit comments