@@ -15,7 +15,7 @@ func TestFindFiles(t *testing.T) {
15
15
tests := []struct {
16
16
name string
17
17
files []string
18
- extension string
18
+ extension [] string
19
19
prefix string
20
20
want []string
21
21
err error
@@ -62,46 +62,53 @@ func TestFindFiles(t *testing.T) {
62
62
{
63
63
name : "test 3 extension json files" ,
64
64
files : []string {"file1.json" , "file2.txt" , "file3.json" , "file4.json" },
65
- extension : "json" ,
65
+ extension : [] string { "json" } ,
66
66
want : []string {"file1.json" , "file3.json" , "file4.json" },
67
67
err : nil ,
68
68
},
69
69
{
70
70
name : "test 3 extension json files with subfolder" ,
71
71
files : []string {"testdata/file1.json" , "file2.txt" , "foo/file3.json" , "file4.json" },
72
- extension : "json" ,
72
+ extension : [] string { "json" } ,
73
73
want : []string {"testdata/file1.json" , "foo/file3.json" , "file4.json" },
74
74
err : nil ,
75
75
},
76
76
{
77
77
name : "test 1 extension txt files" ,
78
78
files : []string {"file1.json" , "file2.txt" , "file3.json" , "file4.json" },
79
- extension : "txt" ,
79
+ extension : [] string { "txt" } ,
80
80
want : []string {"file2.txt" },
81
81
err : nil ,
82
82
},
83
83
{
84
84
name : "test 1 extension json files" ,
85
85
files : []string {"file1.json" },
86
- extension : "json" ,
86
+ extension : [] string { "json" } ,
87
87
want : []string {"file1.json" },
88
88
err : nil ,
89
89
},
90
90
{
91
91
name : "test invalid files extension" ,
92
92
files : []string {"file1.json" , "file2.json" , "file3.json" , "file4.json" },
93
- extension : "txt" ,
93
+ extension : [] string { "txt" } ,
94
94
want : []string {},
95
95
err : nil ,
96
96
},
97
97
{
98
98
name : "test file prefix and extension" ,
99
99
files : []string {"test.file1.json" , "test.file2.txt" , "test.file3.json" },
100
100
prefix : "test.file" ,
101
- extension : "json" ,
101
+ extension : [] string { "json" } ,
102
102
want : []string {"test.file1.json" , "test.file3.json" },
103
103
err : nil ,
104
104
},
105
+ {
106
+ name : "test 2 different extensions" ,
107
+ files : []string {"file1.json" , "file2.txt" , "file3.json" , "file4.json" , "file.yaml" },
108
+ extension : []string {"txt" , "yaml" },
109
+ want : []string {"file2.txt" , "file.yaml" },
110
+ err : nil ,
111
+ },
105
112
}
106
113
for _ , tt := range tests {
107
114
t .Run (tt .name , func (t * testing.T ) {
@@ -124,8 +131,9 @@ func TestFindFiles(t *testing.T) {
124
131
if tt .prefix != "" {
125
132
opts = append (opts , xos .WithPrefix (tt .prefix ))
126
133
}
127
- if tt .extension != "" {
128
- opts = append (opts , xos .WithExtension (tt .extension ))
134
+
135
+ for _ , ext := range tt .extension {
136
+ opts = append (opts , xos .WithExtension (ext ))
129
137
}
130
138
131
139
gotFiles , err := xos .FindFiles (tempDir , opts ... )
0 commit comments