@@ -17,6 +17,8 @@ limitations under the License.
17
17
package fileutil
18
18
19
19
import (
20
+ "os"
21
+ "path/filepath"
20
22
"testing"
21
23
22
24
"sigs.k8s.io/secrets-store-csi-driver/pkg/test_utils/tmpdir"
@@ -27,27 +29,56 @@ func TestGetMountedFiles(t *testing.T) {
27
29
name string
28
30
targetPath func (t * testing.T ) string
29
31
expectedErr bool
32
+ expectedKey string
30
33
}{
31
34
{
32
35
name : "target path not found" ,
33
36
targetPath : func (t * testing.T ) string { return "" },
34
37
expectedErr : true ,
38
+ expectedKey : "" ,
35
39
},
36
40
{
37
41
name : "target path dir found" ,
38
42
targetPath : func (t * testing.T ) string {
39
43
return tmpdir .New (t , "" , "ut" )
40
44
},
41
45
expectedErr : false ,
46
+ expectedKey : "" ,
47
+ },
48
+ {
49
+ name : "target path dir/file found" ,
50
+ targetPath : func (t * testing.T ) string {
51
+ dir := tmpdir .New (t , "" , "ut" )
52
+ os .Create (filepath .Join (dir , "secret.txt" ))
53
+ return dir
54
+ },
55
+ expectedErr : false ,
56
+ expectedKey : "secret.txt" ,
57
+ },
58
+ {
59
+ name : "target path dir/dir/file found" ,
60
+ targetPath : func (t * testing.T ) string {
61
+ dir := tmpdir .New (t , "" , "ut" )
62
+ os .MkdirAll (filepath .Join (dir , "subdir" ), 0700 )
63
+ os .Create (filepath .Join (dir , "subdir" , "secret.txt" ))
64
+ return dir
65
+ },
66
+ expectedErr : false ,
67
+ expectedKey : "subdir/secret.txt" ,
42
68
},
43
69
}
44
70
45
71
for _ , test := range tests {
46
72
t .Run (test .name , func (t * testing.T ) {
47
- _ , err := GetMountedFiles (test .targetPath (t ))
73
+ got , err := GetMountedFiles (test .targetPath (t ))
48
74
if test .expectedErr != (err != nil ) {
49
75
t .Fatalf ("expected err: %v, got: %+v" , test .expectedErr , err )
50
76
}
77
+ if ! test .expectedErr && test .expectedKey != "" {
78
+ if _ , ok := got [test .expectedKey ]; ! ok {
79
+ t .Fatalf ("expected key not found: %s" , test .expectedKey )
80
+ }
81
+ }
51
82
})
52
83
}
53
84
}
0 commit comments