github.com/devseccon/trivy@v0.47.1-0.20231123133102-bd902a0bd996/pkg/x/path/path_test.go (about) 1 package path 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestContains(t *testing.T) { 10 type args struct { 11 filePath string 12 subpath string 13 } 14 tests := []struct { 15 name string 16 args args 17 want bool 18 }{ 19 { 20 name: "file", 21 args: args{ 22 filePath: "go.mod", 23 subpath: "go.mod", 24 }, 25 want: true, 26 }, 27 { 28 name: "dir", 29 args: args{ 30 filePath: "app/node_modules/express/package.json", 31 subpath: "node_modules", 32 }, 33 want: true, 34 }, 35 { 36 name: "path", 37 args: args{ 38 filePath: "app/node_modules/express/package.json", 39 subpath: "app/node_modules", 40 }, 41 want: false, 42 }, 43 } 44 for _, tt := range tests { 45 t.Run(tt.name, func(t *testing.T) { 46 got := Contains(tt.args.filePath, tt.args.subpath) 47 assert.Equal(t, tt.want, got) 48 }) 49 } 50 }