mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
refactor: cli packages structure (#8257)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
parent
0ec76e7165
commit
0b33ae2b06
28 changed files with 87 additions and 133 deletions
|
@ -12,9 +12,9 @@ import (
|
||||||
"github.com/go-git/go-billy/v5/memfs"
|
"github.com/go-git/go-billy/v5/memfs"
|
||||||
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
||||||
"github.com/kyverno/kyverno/api/kyverno/v1beta1"
|
"github.com/kyverno/kyverno/api/kyverno/v1beta1"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/output/color"
|
||||||
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
||||||
cobrautils "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/cobra"
|
cobrautils "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/cobra"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/color"
|
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/common"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/common"
|
||||||
reportutils "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/report"
|
reportutils "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/report"
|
||||||
sanitizederror "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/sanitizedError"
|
sanitizederror "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/sanitizedError"
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package apply
|
package apply
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/output/color"
|
||||||
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/output/table"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/policy/annotations"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/policy/annotations"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/color"
|
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/output/table"
|
|
||||||
engineapi "github.com/kyverno/kyverno/pkg/engine/api"
|
engineapi "github.com/kyverno/kyverno/pkg/engine/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -9,8 +9,8 @@ import (
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/oci"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/oci"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/version"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/version"
|
||||||
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/experimental"
|
||||||
cobrautils "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/cobra"
|
cobrautils "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/cobra"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/experimental"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/create/templates"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/create/templates"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
||||||
cobrautils "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/cobra"
|
cobrautils "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/cobra"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,86 +0,0 @@
|
||||||
package api
|
|
||||||
|
|
||||||
import (
|
|
||||||
policyreportv1alpha2 "github.com/kyverno/kyverno/api/policyreport/v1alpha2"
|
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Test struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Policies []string `json:"policies"`
|
|
||||||
Resources []string `json:"resources"`
|
|
||||||
Variables string `json:"variables,omitempty"`
|
|
||||||
UserInfo string `json:"userinfo,omitempty"`
|
|
||||||
Results []TestResults `json:"results"`
|
|
||||||
Values *Values `json:"values,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type TestResults struct {
|
|
||||||
// Policy mentions the name of the policy.
|
|
||||||
Policy string `json:"policy"`
|
|
||||||
// Rule mentions the name of the rule in the policy.
|
|
||||||
// It's required in case policy is a kyverno policy.
|
|
||||||
// +optional
|
|
||||||
Rule string `json:"rule,omitempty"`
|
|
||||||
// IsValidatingAdmissionPolicy indicates if the policy is a validating admission policy.
|
|
||||||
// It's required in case policy is a validating admission policy.
|
|
||||||
// +optional
|
|
||||||
IsValidatingAdmissionPolicy bool `json:"isValidatingAdmissionPolicy,omitempty"`
|
|
||||||
// Result mentions the result that the user is expecting.
|
|
||||||
// Possible values are pass, fail and skip.
|
|
||||||
Result policyreportv1alpha2.PolicyResult `json:"result"`
|
|
||||||
// Status mentions the status that the user is expecting.
|
|
||||||
// Possible values are pass, fail and skip.
|
|
||||||
Status policyreportv1alpha2.PolicyResult `json:"status,omitempty"`
|
|
||||||
// Resource mentions the name of the resource on which the policy is to be applied.
|
|
||||||
Resource string `json:"resource,omitempty"`
|
|
||||||
// Resources gives us the list of resources on which the policy is going to be applied.
|
|
||||||
Resources []string `json:"resources"`
|
|
||||||
// Kind mentions the kind of the resource on which the policy is to be applied.
|
|
||||||
Kind string `json:"kind"`
|
|
||||||
// Namespace mentions the namespace of the policy which has namespace scope.
|
|
||||||
Namespace string `json:"namespace,omitempty"`
|
|
||||||
// PatchedResource takes a resource configuration file in yaml format from
|
|
||||||
// the user to compare it against the Kyverno mutated resource configuration.
|
|
||||||
PatchedResource string `json:"patchedResource,omitempty"`
|
|
||||||
// GeneratedResource takes a resource configuration file in yaml format from
|
|
||||||
// the user to compare it against the Kyverno generated resource configuration.
|
|
||||||
GeneratedResource string `json:"generatedResource,omitempty"`
|
|
||||||
// CloneSourceResource takes the resource configuration file in yaml format
|
|
||||||
// from the user which is meant to be cloned by the generate rule.
|
|
||||||
CloneSourceResource string `json:"cloneSourceResource,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Policy struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Resources []Resource `json:"resources"`
|
|
||||||
Rules []Rule `json:"rules"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Rule struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Values map[string]interface{} `json:"values"`
|
|
||||||
ForeachValues map[string][]interface{} `json:"foreachValues"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Values struct {
|
|
||||||
Policies []Policy `json:"policies"`
|
|
||||||
GlobalValues map[string]string `json:"globalValues"`
|
|
||||||
NamespaceSelectors []NamespaceSelector `json:"namespaceSelector"`
|
|
||||||
Subresources []Subresource `json:"subresources"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Resource struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Values map[string]interface{} `json:"values"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type Subresource struct {
|
|
||||||
APIResource metav1.APIResource `json:"subresource"`
|
|
||||||
ParentResource metav1.APIResource `json:"parentResource"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type NamespaceSelector struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Labels map[string]string `json:"labels"`
|
|
||||||
}
|
|
|
@ -7,11 +7,11 @@ import (
|
||||||
|
|
||||||
"github.com/go-git/go-billy/v5"
|
"github.com/go-git/go-billy/v5"
|
||||||
policyreportv1alpha2 "github.com/kyverno/kyverno/api/policyreport/v1alpha2"
|
policyreportv1alpha2 "github.com/kyverno/kyverno/api/policyreport/v1alpha2"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/output/color"
|
||||||
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/output/table"
|
||||||
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
||||||
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/filter"
|
||||||
cobrautils "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/cobra"
|
cobrautils "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/cobra"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/color"
|
|
||||||
filterutils "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/filter"
|
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/output/table"
|
|
||||||
reportutils "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/report"
|
reportutils "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/report"
|
||||||
sanitizederror "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/sanitizedError"
|
sanitizederror "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/sanitizedError"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/store"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/store"
|
||||||
|
@ -80,7 +80,7 @@ func testCommandExecute(
|
||||||
return rc, sanitizederror.NewWithError("a directory is required", err)
|
return rc, sanitizederror.NewWithError("a directory is required", err)
|
||||||
}
|
}
|
||||||
// parse filter
|
// parse filter
|
||||||
filter, errors := filterutils.ParseFilter(testCase)
|
filter, errors := filter.ParseFilter(testCase)
|
||||||
if len(errors) > 0 {
|
if len(errors) > 0 {
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Println("Filter errors:")
|
fmt.Println("Filter errors:")
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/go-git/go-billy/v5/memfs"
|
"github.com/go-git/go-billy/v5/memfs"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/common"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/common"
|
||||||
"gotest.tools/assert"
|
"gotest.tools/assert"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
func getAndCompareResource(actualResource unstructured.Unstructured, fs billy.Filesystem, path string) (bool, error) {
|
func getAndCompareResource(actualResource unstructured.Unstructured, fs billy.Filesystem, path string) (bool, error) {
|
||||||
expectedResource, err := resource.GetResourceFromPath(fs, path)
|
expectedResource, err := resource.GetResourceFromPath(fs, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf("Error: failed to load resources (%s)", err)
|
return false, fmt.Errorf("Error: failed to load resource (%s)", err)
|
||||||
}
|
}
|
||||||
unstructuredutils.FixupGenerateLabels(actualResource)
|
unstructuredutils.FixupGenerateLabels(actualResource)
|
||||||
unstructuredutils.FixupGenerateLabels(*expectedResource)
|
unstructuredutils.FixupGenerateLabels(*expectedResource)
|
||||||
|
|
|
@ -7,9 +7,9 @@ import (
|
||||||
"github.com/go-git/go-billy/v5"
|
"github.com/go-git/go-billy/v5"
|
||||||
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
||||||
"github.com/kyverno/kyverno/api/kyverno/v1beta1"
|
"github.com/kyverno/kyverno/api/kyverno/v1beta1"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
||||||
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/filter"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/common"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/common"
|
||||||
filterutils "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/filter"
|
|
||||||
pathutils "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/path"
|
pathutils "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/path"
|
||||||
sanitizederror "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/sanitizedError"
|
sanitizederror "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/sanitizedError"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/store"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/store"
|
||||||
|
@ -32,7 +32,7 @@ func applyPoliciesFromPath(
|
||||||
policyResourcePath string,
|
policyResourcePath string,
|
||||||
rc *resultCounts,
|
rc *resultCounts,
|
||||||
openApiManager openapi.Manager,
|
openApiManager openapi.Manager,
|
||||||
filter filterutils.Filter,
|
filter filter.Filter,
|
||||||
auditWarn bool,
|
auditWarn bool,
|
||||||
) ([]api.TestResults, []engineapi.EngineResponse, error) {
|
) ([]api.TestResults, []engineapi.EngineResponse, error) {
|
||||||
engineResponses := make([]engineapi.EngineResponse, 0)
|
engineResponses := make([]engineapi.EngineResponse, 0)
|
||||||
|
|
|
@ -3,10 +3,14 @@ package table
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/color"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/output/color"
|
||||||
"github.com/lensesio/tableprinter"
|
"github.com/lensesio/tableprinter"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func rowsLength(length int) bool {
|
||||||
|
return length > 10
|
||||||
|
}
|
||||||
|
|
||||||
func NewTablePrinter() *tableprinter.Printer {
|
func NewTablePrinter() *tableprinter.Printer {
|
||||||
printer := tableprinter.New(os.Stdout)
|
printer := tableprinter.New(os.Stdout)
|
||||||
printer.BorderTop, printer.BorderBottom, printer.BorderLeft, printer.BorderRight = true, true, true, true
|
printer.BorderTop, printer.BorderBottom, printer.BorderLeft, printer.BorderRight = true, true, true, true
|
||||||
|
@ -16,8 +20,6 @@ func NewTablePrinter() *tableprinter.Printer {
|
||||||
printer.RowCharLimit = 300
|
printer.RowCharLimit = 300
|
||||||
printer.HeaderBgColor = color.HeaderBgColor
|
printer.HeaderBgColor = color.HeaderBgColor
|
||||||
printer.HeaderFgColor = color.HeaderFgColor
|
printer.HeaderFgColor = color.HeaderFgColor
|
||||||
printer.RowLengthTitle = func(rowsLength int) bool {
|
printer.RowLengthTitle = rowsLength
|
||||||
return rowsLength > 10
|
|
||||||
}
|
|
||||||
return printer
|
return printer
|
||||||
}
|
}
|
42
cmd/cli/kubectl-kyverno/output/table/printer_test.go
Normal file
42
cmd/cli/kubectl-kyverno/output/table/printer_test.go
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
package table
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewTablePrinter(t *testing.T) {
|
||||||
|
if got := NewTablePrinter(); got == nil {
|
||||||
|
t.Errorf("NewTablePrinter() return nill")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Test_rowsLength(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
length int
|
||||||
|
want bool
|
||||||
|
}{{
|
||||||
|
name: "0",
|
||||||
|
length: 0,
|
||||||
|
want: false,
|
||||||
|
}, {
|
||||||
|
name: "10",
|
||||||
|
length: 10,
|
||||||
|
want: false,
|
||||||
|
}, {
|
||||||
|
name: "11",
|
||||||
|
length: 11,
|
||||||
|
want: true,
|
||||||
|
}, {
|
||||||
|
name: "20",
|
||||||
|
length: 20,
|
||||||
|
want: true,
|
||||||
|
}}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := rowsLength(tt.length); got != tt.want {
|
||||||
|
t.Errorf("rowsLength() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
||||||
"github.com/kyverno/kyverno/pkg/utils/wildcard"
|
"github.com/kyverno/kyverno/pkg/utils/wildcard"
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_policy_Apply(t *testing.T) {
|
func Test_policy_Apply(t *testing.T) {
|
||||||
|
@ -313,9 +313,7 @@ func TestParseFilter(t *testing.T) {
|
||||||
errors.New("Invalid test-case-selector (foo=bar). Parameter can only be policy, rule or resource."),
|
errors.New("Invalid test-case-selector (foo=bar). Parameter can only be policy, rule or resource."),
|
||||||
errors.New("Invalid test-case-selector argument (policy). Parameter must be in the form `<key>=<value>`."),
|
errors.New("Invalid test-case-selector argument (policy). Parameter must be in the form `<key>=<value>`."),
|
||||||
},
|
},
|
||||||
},
|
}}
|
||||||
// TODO: Add test cases.
|
|
||||||
}
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
got, got1 := ParseFilter(tt.in)
|
got, got1 := ParseFilter(tt.in)
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/go-git/go-billy/v5"
|
"github.com/go-git/go-billy/v5"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
||||||
"k8s.io/apimachinery/pkg/util/yaml"
|
"k8s.io/apimachinery/pkg/util/yaml"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
policyreportv1alpha2 "github.com/kyverno/kyverno/api/policyreport/v1alpha2"
|
policyreportv1alpha2 "github.com/kyverno/kyverno/api/policyreport/v1alpha2"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTestCases_Errors(t *testing.T) {
|
func TestTestCases_Errors(t *testing.T) {
|
||||||
|
@ -196,9 +196,7 @@ func TestLoadTests(t *testing.T) {
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
},
|
}}
|
||||||
// TODO: Add test cases.
|
|
||||||
}
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
got, err := LoadTests(tt.dirPath, tt.fileName)
|
got, err := LoadTests(tt.dirPath, tt.fileName)
|
||||||
|
|
|
@ -14,9 +14,9 @@ import (
|
||||||
"github.com/go-git/go-billy/v5"
|
"github.com/go-git/go-billy/v5"
|
||||||
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
||||||
kyvernov1beta1 "github.com/kyverno/kyverno/api/kyverno/v1beta1"
|
kyvernov1beta1 "github.com/kyverno/kyverno/api/kyverno/v1beta1"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/policy/annotations"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/policy/annotations"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/resource"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/resource"
|
||||||
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
||||||
sanitizederror "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/sanitizedError"
|
sanitizederror "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/sanitizedError"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/source"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/source"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/store"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/store"
|
||||||
|
|
|
@ -4,8 +4,8 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/kyverno/kyverno/api/kyverno/v1beta1"
|
"github.com/kyverno/kyverno/api/kyverno/v1beta1"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/resource"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/resource"
|
||||||
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
||||||
yamlutils "github.com/kyverno/kyverno/pkg/utils/yaml"
|
yamlutils "github.com/kyverno/kyverno/pkg/utils/yaml"
|
||||||
"gotest.tools/assert"
|
"gotest.tools/assert"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
|
|
@ -9,8 +9,8 @@ import (
|
||||||
|
|
||||||
"github.com/go-git/go-billy/v5"
|
"github.com/go-git/go-billy/v5"
|
||||||
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/resource"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/resource"
|
||||||
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
||||||
"github.com/kyverno/kyverno/pkg/autogen"
|
"github.com/kyverno/kyverno/pkg/autogen"
|
||||||
"github.com/kyverno/kyverno/pkg/clients/dclient"
|
"github.com/kyverno/kyverno/pkg/clients/dclient"
|
||||||
kubeutils "github.com/kyverno/kyverno/pkg/utils/kube"
|
kubeutils "github.com/kyverno/kyverno/pkg/utils/kube"
|
||||||
|
|
|
@ -2,7 +2,7 @@ package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
||||||
"github.com/kyverno/kyverno/pkg/autogen"
|
"github.com/kyverno/kyverno/pkg/autogen"
|
||||||
"github.com/kyverno/kyverno/pkg/clients/dclient"
|
"github.com/kyverno/kyverno/pkg/clients/dclient"
|
||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package common
|
package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
||||||
"github.com/kyverno/kyverno/pkg/clients/dclient"
|
"github.com/kyverno/kyverno/pkg/clients/dclient"
|
||||||
"k8s.io/api/admissionregistration/v1alpha1"
|
"k8s.io/api/admissionregistration/v1alpha1"
|
||||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||||
|
|
|
@ -8,10 +8,10 @@ import (
|
||||||
|
|
||||||
"github.com/go-git/go-billy/v5"
|
"github.com/go-git/go-billy/v5"
|
||||||
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
kyvernov1 "github.com/kyverno/kyverno/api/kyverno/v1"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
||||||
sanitizederror "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/sanitizedError"
|
sanitizederror "github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/sanitizedError"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/store"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/store"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/utils/values"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/values"
|
||||||
"github.com/kyverno/kyverno/pkg/autogen"
|
"github.com/kyverno/kyverno/pkg/autogen"
|
||||||
"github.com/kyverno/kyverno/pkg/engine/variables/regex"
|
"github.com/kyverno/kyverno/pkg/engine/variables/regex"
|
||||||
datautils "github.com/kyverno/kyverno/pkg/utils/data"
|
datautils "github.com/kyverno/kyverno/pkg/utils/data"
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/go-git/go-billy/v5"
|
"github.com/go-git/go-billy/v5"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
||||||
"k8s.io/apimachinery/pkg/util/yaml"
|
"k8s.io/apimachinery/pkg/util/yaml"
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/go-git/go-billy/v5"
|
"github.com/go-git/go-billy/v5"
|
||||||
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/commands/test/api"
|
"github.com/kyverno/kyverno/cmd/cli/kubectl-kyverno/test/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_readFile(t *testing.T) {
|
func Test_readFile(t *testing.T) {
|
||||||
|
@ -31,18 +31,18 @@ func Test_readFile(t *testing.T) {
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
}, {
|
}, {
|
||||||
name: "does not exist",
|
name: "does not exist",
|
||||||
filepath: "../../testdata/values/doesnotexist",
|
filepath: "../testdata/values/doesnotexist",
|
||||||
want: nil,
|
want: nil,
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
}, {
|
}, {
|
||||||
name: "bad format",
|
name: "bad format",
|
||||||
filepath: "../../testdata/values/bad-format.yaml",
|
filepath: "../testdata/values/bad-format.yaml",
|
||||||
want: mustReadFile("../../testdata/values/bad-format.yaml"),
|
want: mustReadFile("../testdata/values/bad-format.yaml"),
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
}, {
|
}, {
|
||||||
name: "valid",
|
name: "valid",
|
||||||
filepath: "../../testdata/values/valid.yaml",
|
filepath: "../testdata/values/valid.yaml",
|
||||||
want: mustReadFile("../../testdata/values/valid.yaml"),
|
want: mustReadFile("../testdata/values/valid.yaml"),
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
}}
|
}}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
@ -73,17 +73,17 @@ func TestLoad(t *testing.T) {
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
}, {
|
}, {
|
||||||
name: "does not exist",
|
name: "does not exist",
|
||||||
filepath: "../../testdata/values/doesnotexist",
|
filepath: "../testdata/values/doesnotexist",
|
||||||
want: nil,
|
want: nil,
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
}, {
|
}, {
|
||||||
name: "bad format",
|
name: "bad format",
|
||||||
filepath: "../../testdata/values/bad-format.yaml",
|
filepath: "../testdata/values/bad-format.yaml",
|
||||||
want: nil,
|
want: nil,
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
}, {
|
}, {
|
||||||
name: "valid",
|
name: "valid",
|
||||||
filepath: "../../testdata/values/valid.yaml",
|
filepath: "../testdata/values/valid.yaml",
|
||||||
want: &api.Values{
|
want: &api.Values{
|
||||||
NamespaceSelectors: []api.NamespaceSelector{{
|
NamespaceSelectors: []api.NamespaceSelector{{
|
||||||
Name: "test1",
|
Name: "test1",
|
Loading…
Add table
Reference in a new issue