Files
trivy/pkg/x/path/path_test.go
Nikita Pivkin 067a0fcb9c fix(nodejs): do not detect lock file in node_modules as an app (#4949)
* fix(npm): do not detect lock file in node_modules as an app

* refactor: add x/path.Contains

---------

Co-authored-by: knqyf263 <knqyf263@gmail.com>
2023-08-06 08:59:18 +00:00

51 lines
806 B
Go

package path
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestContains(t *testing.T) {
type args struct {
filePath string
subpath string
}
tests := []struct {
name string
args args
want bool
}{
{
name: "file",
args: args{
filePath: "go.mod",
subpath: "go.mod",
},
want: true,
},
{
name: "dir",
args: args{
filePath: "app/node_modules/express/package.json",
subpath: "node_modules",
},
want: true,
},
{
name: "path",
args: args{
filePath: "app/node_modules/express/package.json",
subpath: "app/node_modules",
},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := Contains(tt.args.filePath, tt.args.subpath)
assert.Equal(t, tt.want, got)
})
}
}