github.com/verrazzano/verrazzano@v1.7.1/pkg/files/files_test.go (about)

     1  // Copyright (c) 2022, 2024, 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  	"regexp"
     8  	"testing"
     9  
    10  	asserts "github.com/stretchr/testify/assert"
    11  )
    12  
    13  // TestGetMatchingFiles Tests that we can find the expected set of files with a matching expression
    14  // GIVEN a call to GetMatchingFiles
    15  // WHEN with a valid rootDirectory and regular expression
    16  // THEN files that matched will be returned, if not returns nil
    17  func TestGetMatchingFiles(t *testing.T) {
    18  	assert := asserts.New(t)
    19  
    20  	files1, err1 := GetMatchingFiles("../../tools/vz/pkg/internal/test/json", regexp.MustCompile("bogus"))
    21  	assert.Nil(err1)
    22  	assert.Equal(len(files1), 1)
    23  
    24  	files2, err2 := GetMatchingFiles("../../tools/vz/pkg/internal/test", regexp.MustCompile("json"))
    25  	assert.Nil(err2)
    26  	assert.True(len(files2) > 0)
    27  
    28  	files4, err4 := GetMatchingFiles("testdata", regexp.MustCompile("non-existing-file-regex"))
    29  	assert.Nil(err4)
    30  	assert.Equal(len(files4), 0)
    31  
    32  	files5, err5 := GetMatchingFiles("non-existing-directory", regexp.MustCompile("non-existing-file-regex"))
    33  	assert.Nil(err5)
    34  	assert.Empty(len(files5), 0)
    35  }