github.com/diggerhq/digger/libs@v0.0.0-20240604170430-9d61cdf01cc5/digger_config/utils_test.go (about) 1 package digger_config 2 3 import ( 4 "github.com/stretchr/testify/assert" 5 "testing" 6 ) 7 8 func TestMatchIncludeExcludePatternsToFile(t *testing.T) { 9 includePatterns := []string{"projects/dev/**/*"} 10 excludePatterns := []string{"projects/dev/project"} 11 result := MatchIncludeExcludePatternsToFile("/projects/dev/test1", includePatterns, excludePatterns) 12 assert.Equal(t, true, result) 13 14 result = MatchIncludeExcludePatternsToFile("/projects/dev/test/test1", includePatterns, excludePatterns) 15 assert.Equal(t, true, result) 16 17 result = MatchIncludeExcludePatternsToFile("/dev/test1", includePatterns, excludePatterns) 18 assert.Equal(t, false, result) 19 20 result = MatchIncludeExcludePatternsToFile("projects/dev/project", includePatterns, excludePatterns) 21 assert.Equal(t, false, result) 22 } 23 24 func TestGetPatternsRelativeToRepo(t *testing.T) { 25 projectDir := "myProject/terraform/environments/devel" 26 includePatterns := []string{"../../*.tf*"} 27 res, _ := GetPatternsRelativeToRepo(projectDir, includePatterns) 28 assert.Equal(t, "myProject/terraform/*.tf*", res[0]) 29 30 projectDir = "myProject/terraform/environments/devel" 31 includePatterns = []string{"*.tf"} 32 res, _ = GetPatternsRelativeToRepo(projectDir, includePatterns) 33 assert.Equal(t, "myProject/terraform/environments/devel/*.tf", res[0]) 34 35 projectDir = "myProject/terraform/environments/devel" 36 includePatterns = []string{"*.hcl"} 37 res, _ = GetPatternsRelativeToRepo(projectDir, includePatterns) 38 assert.Equal(t, "myProject/terraform/environments/devel/*.hcl", res[0]) 39 40 }