mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-11 04:15:54 +02:00
* pkg/cwhub: improve support for k8s config maps as custom items - allow links to links - ignore hidden ..data directories, but allow links to their content * allow any number of subdirectories in /etc/crowdsec/{hubtype} * item name as subdir/file.yaml * improve func test * lint
72 lines
1.5 KiB
Go
72 lines
1.5 KiB
Go
package cwhub
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestRelativePathComponents(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
path string
|
|
baseDir string
|
|
expected []string
|
|
}{
|
|
{
|
|
name: "Path within baseDir",
|
|
path: "/home/user/project/src/file.go",
|
|
baseDir: "/home/user/project",
|
|
expected: []string{"src", "file.go"},
|
|
},
|
|
{
|
|
name: "Path is baseDir",
|
|
path: "/home/user/project",
|
|
baseDir: "/home/user/project",
|
|
expected: []string{},
|
|
},
|
|
{
|
|
name: "Path outside baseDir",
|
|
path: "/home/user/otherproject/src/file.go",
|
|
baseDir: "/home/user/project",
|
|
expected: []string{},
|
|
},
|
|
{
|
|
name: "Path is subdirectory of baseDir",
|
|
path: "/home/user/project/src/",
|
|
baseDir: "/home/user/project",
|
|
expected: []string{"src"},
|
|
},
|
|
{
|
|
name: "Relative paths",
|
|
path: "project/src/file.go",
|
|
baseDir: "project",
|
|
expected: []string{"src", "file.go"},
|
|
},
|
|
{
|
|
name: "BaseDir with trailing slash",
|
|
path: "/home/user/project/src/file.go",
|
|
baseDir: "/home/user/project/",
|
|
expected: []string{"src", "file.go"},
|
|
},
|
|
{
|
|
name: "Empty baseDir",
|
|
path: "/home/user/project/src/file.go",
|
|
baseDir: "",
|
|
expected: []string{},
|
|
},
|
|
{
|
|
name: "Empty path",
|
|
path: "",
|
|
baseDir: "/home/user/project",
|
|
expected: []string{},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := relativePathComponents(tt.path, tt.baseDir)
|
|
assert.Equal(t, tt.expected, result)
|
|
})
|
|
}
|
|
}
|