github.com/verrazzano/verrazzano@v1.7.0/pkg/files/files_test.go (about) 1 // Copyright (c) 2022, Oracle and/or its affiliates. 2 // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. 3 4 package files 5 6 import ( 7 asserts "github.com/stretchr/testify/assert" 8 "regexp" 9 "testing" 10 ) 11 12 // TestGetMatchingFiles Tests that we can find the expected set of files with a matching expression 13 // GIVEN a call to GetMatchingFiles 14 // WHEN with a valid rootDirectory and regular expression 15 // THEN files that matched will be returned, if not returns nil 16 func TestGetMatchingFiles(t *testing.T) { 17 assert := asserts.New(t) 18 19 files1, err1 := GetMatchingFiles("../../tools/vz/pkg/analysis/test/json", regexp.MustCompile("bogus")) 20 assert.Nil(err1) 21 assert.Equal(len(files1), 1) 22 23 files2, err2 := GetMatchingFiles("../../tools/vz/pkg/analysis/test", regexp.MustCompile("json")) 24 assert.Nil(err2) 25 assert.True(len(files2) > 0) 26 27 files4, err4 := GetMatchingFiles("testdata", regexp.MustCompile("non-existing-file-regex")) 28 assert.Nil(err4) 29 assert.Equal(len(files4), 0) 30 31 files5, err5 := GetMatchingFiles("non-existing-directory", regexp.MustCompile("non-existing-file-regex")) 32 assert.Nil(err5) 33 assert.Empty(len(files5), 0) 34 }