github.com/blend/go-sdk@v1.20220411.3/profanity/glob_filter_test.go (about) 1 /* 2 3 Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file. 5 6 */ 7 8 package profanity 9 10 import ( 11 "fmt" 12 "testing" 13 14 "github.com/blend/go-sdk/assert" 15 ) 16 17 func Test_Glob_include(t *testing.T) { 18 its := assert.New(t) 19 20 testCases := [...]struct { 21 Input string 22 Expected bool 23 }{ 24 {Input: "foo.txt", Expected: false}, 25 {Input: "foo.go", Expected: true}, 26 {Input: "Dockerfile", Expected: true}, 27 {Input: "Dockerfile.unit-test", Expected: true}, 28 {Input: "project/path/foo.txt", Expected: false}, 29 {Input: "project/path/foo.go", Expected: true}, 30 {Input: "project/path/Dockerfile", Expected: true}, 31 {Input: "project/path/testing.Dockerfile", Expected: false}, 32 {Input: "project/path/Dockerfile.unit-test", Expected: true}, 33 {Input: "project/path/Dockerfiles/testing-file", Expected: false}, 34 } 35 36 filter := GlobFilter{ 37 Filter: Filter{ 38 Include: []string{"*.go", "Dockerfile", "Dockerfile.*", "**/Dockerfile", "**/Dockerfile.*"}, 39 }, 40 } 41 42 var actual bool 43 for _, tc := range testCases { 44 actual = filter.Allow(tc.Input) 45 its.Equal(tc.Expected, actual, fmt.Sprintf("%s should yield %v", tc.Input, tc.Expected)) 46 } 47 }