@@ -167,3 +167,208 @@ func TestCheckFileContainsCommands(t *testing.T) {
167167 })
168168 }
169169}
170+
171+ func Test_isMatchingPath (t * testing.T ) {
172+ t .Parallel ()
173+ type args struct {
174+ pattern string
175+ fullpath string
176+ caseSensitive bool
177+ }
178+ tests := []struct {
179+ name string
180+ args args
181+ want bool
182+ wantErr bool
183+ }{
184+ {
185+ name : "matching path" ,
186+ args : args {
187+ pattern : "Dockerfile" ,
188+ fullpath : "Dockerfile" ,
189+ caseSensitive : true ,
190+ },
191+ want : true ,
192+ },
193+ {
194+ name : "matching path with case insensitive" ,
195+ args : args {
196+ pattern : "Dockerfile" ,
197+ fullpath : "dockerfile" ,
198+ caseSensitive : false ,
199+ },
200+ want : true ,
201+ },
202+ {
203+ name : "matching path with case insensitive" ,
204+ args : args {
205+ pattern : "Dockerfile" ,
206+ fullpath : "dockerfile" ,
207+ caseSensitive : true ,
208+ },
209+ want : false ,
210+ },
211+ {
212+ name : "matching path with case insensitive" ,
213+ args : args {
214+ pattern : "Dockerfile" ,
215+ fullpath : "Dockerfile.template" ,
216+ caseSensitive : false ,
217+ },
218+ want : false ,
219+ },
220+ {
221+ name : "matching path with case insensitive" ,
222+ args : args {
223+ pattern : "Dockerfile" ,
224+ fullpath : "Dockerfile.template" ,
225+ caseSensitive : true ,
226+ },
227+ want : false ,
228+ },
229+ {
230+ name : "matching path with case insensitive" ,
231+ args : args {
232+ pattern : "Dockerfile" ,
233+ fullpath : "Dockerfile.template" ,
234+ caseSensitive : false ,
235+ },
236+ want : false ,
237+ },
238+ {
239+ name : "matching path with case insensitive" ,
240+ args : args {
241+ pattern : "Dockerfile" ,
242+ fullpath : "Dockerfile.template" ,
243+ caseSensitive : true ,
244+ },
245+ },
246+ {
247+ name : "matching path with case insensitive" ,
248+ args : args {
249+ pattern : "Dockerfile" ,
250+ fullpath : "Dockerfile.template" ,
251+ caseSensitive : false ,
252+ },
253+ },
254+ {
255+ name : "matching path with case insensitive" ,
256+ args : args {
257+ pattern : "Dockerfile" ,
258+ fullpath : "Dockerfile.template" ,
259+ caseSensitive : true ,
260+ },
261+ },
262+ {
263+ name : "matching path with case insensitive" ,
264+ args : args {
265+ pattern : "Dockerfile" ,
266+ fullpath : "Dockerfile.template" ,
267+ caseSensitive : false ,
268+ },
269+ },
270+ {
271+ name : "matching path with case insensitive" ,
272+ args : args {
273+ pattern : "Dockerfile" ,
274+ fullpath : "Dockerfile.template" ,
275+ caseSensitive : true ,
276+ },
277+ },
278+ {
279+ name : "matching path with case insensitive" ,
280+ args : args {
281+ pattern : "Dockerfile" ,
282+ fullpath : "Dockerfile.template" ,
283+ caseSensitive : false ,
284+ },
285+ },
286+ {
287+ name : "matching path with case insensitive" ,
288+ args : args {
289+ pattern : "Dockerfile" ,
290+ fullpath : "Dockerfile.template" ,
291+ caseSensitive : true ,
292+ },
293+ },
294+ {
295+ name : "matching path with case insensitive" ,
296+ args : args {
297+ pattern : "Dockerfile" ,
298+ fullpath : "Dockerfile.template" ,
299+ caseSensitive : false ,
300+ },
301+ },
302+ }
303+ for _ , tt := range tests {
304+ tt := tt // Re-initializing variable so it is not changed while executing the closure below
305+ t .Run (tt .name , func (t * testing.T ) {
306+ t .Parallel ()
307+ got , err := isMatchingPath (tt .args .pattern , tt .args .fullpath , tt .args .caseSensitive )
308+ if (err != nil ) != tt .wantErr {
309+ t .Errorf ("isMatchingPath() error = %v, wantErr %v" , err , tt .wantErr )
310+ return
311+ }
312+ if got != tt .want {
313+ t .Errorf ("isMatchingPath() = %v, want %v" , got , tt .want )
314+ }
315+ })
316+ }
317+ }
318+
319+ func Test_isTestdataFile (t * testing.T ) {
320+ t .Parallel ()
321+ type args struct {
322+ fullpath string
323+ }
324+ tests := []struct {
325+ name string
326+ args args
327+ want bool
328+ }{
329+ {
330+ name : "testdata file" ,
331+ args : args {
332+ fullpath : "testdata/Dockerfile" ,
333+ },
334+ want : true ,
335+ },
336+ {
337+ name : "testdata file" ,
338+ args : args {
339+ fullpath : "testdata/Dockerfile.template" ,
340+ },
341+ want : true ,
342+ },
343+ {
344+ name : "testdata file" ,
345+ args : args {
346+ fullpath : "testdata/Dockerfile.template.template" ,
347+ },
348+ want : true ,
349+ },
350+ {
351+ name : "testdata file" ,
352+ args : args {
353+ fullpath : "testdata/Dockerfile.template.template.template" ,
354+ },
355+ want : true ,
356+ },
357+ {
358+ name : "testdata file" ,
359+ args : args {
360+ fullpath : "testdata/Dockerfile.template.template.template.template" ,
361+ },
362+ want : true ,
363+ },
364+ }
365+ for _ , tt := range tests {
366+ tt := tt // Re-initializing variable so it is not changed while executing the closure below
367+ t .Run (tt .name , func (t * testing.T ) {
368+ t .Parallel ()
369+ if got := isTestdataFile (tt .args .fullpath ); got != tt .want {
370+ t .Errorf ("isTestdataFile() = %v, want %v" , got , tt .want )
371+ }
372+ })
373+ }
374+ }
0 commit comments