mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-13 19:28:55 +00:00
chore: add cli path utils unit tests (#8167)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
parent
c5eb3d2525
commit
414c3c77dd
1 changed files with 95 additions and 0 deletions
95
cmd/cli/kubectl-kyverno/utils/path/path_test.go
Normal file
95
cmd/cli/kubectl-kyverno/utils/path/path_test.go
Normal file
|
@ -0,0 +1,95 @@
|
|||
package path
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetFullPath(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
path string
|
||||
basePath string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
name: "relative",
|
||||
path: "abc",
|
||||
basePath: "def",
|
||||
want: "def/abc",
|
||||
},
|
||||
{
|
||||
name: "absolute",
|
||||
path: "/abc",
|
||||
basePath: "def",
|
||||
want: "/abc",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := GetFullPath(tt.path, tt.basePath); got != tt.want {
|
||||
t.Errorf("GetFullPath() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetFullPaths(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
paths []string
|
||||
basePath string
|
||||
git bool
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "relative (non git)",
|
||||
paths: []string{"abc", "xyz"},
|
||||
basePath: "def",
|
||||
git: false,
|
||||
want: []string{"def/abc", "def/xyz"},
|
||||
},
|
||||
{
|
||||
name: "absolute (non git)",
|
||||
paths: []string{"/abc", "/xyz"},
|
||||
basePath: "def",
|
||||
git: false,
|
||||
want: []string{"/abc", "/xyz"},
|
||||
},
|
||||
{
|
||||
name: "mixed (non git)",
|
||||
paths: []string{"/abc", "xyz"},
|
||||
basePath: "def",
|
||||
git: false,
|
||||
want: []string{"/abc", "def/xyz"},
|
||||
},
|
||||
{
|
||||
name: "relative (git)",
|
||||
paths: []string{"abc", "xyz"},
|
||||
basePath: "def",
|
||||
git: true,
|
||||
want: []string{"abc", "xyz"},
|
||||
},
|
||||
{
|
||||
name: "absolute (git)",
|
||||
paths: []string{"/abc", "/xyz"},
|
||||
basePath: "def",
|
||||
git: true,
|
||||
want: []string{"/abc", "/xyz"},
|
||||
},
|
||||
{
|
||||
name: "mixed (git)",
|
||||
paths: []string{"/abc", "xyz"},
|
||||
basePath: "def",
|
||||
git: true,
|
||||
want: []string{"/abc", "xyz"},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := GetFullPaths(tt.paths, tt.basePath, tt.git); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("GetFullPaths() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue