Skip to content

Commit eba47c0

Browse files
committed
vendor atomic_writer and use it to write files returned by grpc
1 parent 46665ab commit eba47c0

File tree

7 files changed

+1846
-219
lines changed

7 files changed

+1846
-219
lines changed

pkg/secrets-store/provider_client_test.go

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"errors"
2222
"fmt"
2323
"os"
24-
"path/filepath"
2524
"reflect"
2625
"sync"
2726
"testing"
@@ -33,6 +32,7 @@ import (
3332
"google.golang.org/grpc/status"
3433

3534
"sigs.k8s.io/secrets-store-csi-driver/pkg/test_utils/tmpdir"
35+
"sigs.k8s.io/secrets-store-csi-driver/pkg/util/fileutil"
3636
"sigs.k8s.io/secrets-store-csi-driver/provider/fake"
3737
"sigs.k8s.io/secrets-store-csi-driver/provider/v1alpha1"
3838
)
@@ -107,6 +107,33 @@ func TestMountContent(t *testing.T) {
107107
"bar": 0777,
108108
},
109109
},
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+
},
110137
}
111138

112139
for _, test := range cases {
@@ -140,18 +167,17 @@ func TestMountContent(t *testing.T) {
140167

141168
// check that file was written
142169
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)
149176
if err != nil {
150-
return err
177+
t.Fatalf("unable to read mounted files: %s", err)
151178
}
152179
gotFiles[rel] = info.Mode()
153-
return nil
154-
})
180+
}
155181

156182
if diff := cmp.Diff(test.expectedFiles, gotFiles); diff != "" {
157183
t.Errorf("MountContent() file mismatch (-want +got):\n%s", diff)

0 commit comments

Comments
 (0)