1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00

Remove support for test.yaml (#3442)

kyverno-test.yaml is now the only supported test file name

Signed-off-by: Aidan Delaney <adelaney21@bloomberg.net>
This commit is contained in:
Aidan Delaney 2022-03-22 08:39:08 +00:00 committed by GitHub
parent 9ed1872864
commit 4ec3b36f7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 19 deletions

View file

@ -295,7 +295,6 @@ func testCommandExecute(dirPath []string, fileName string, gitBranch string, tes
fs := memfs.New()
rc = &resultCounts{}
var testYamlCount int
var testYamlNameCount int
var tf = &testFilter{
enabled: true,
}
@ -397,11 +396,8 @@ func testCommandExecute(dirPath []string, fileName string, gitBranch string, tes
continue
}
if file.Name() == fileName || file.Name() == "test.yaml" {
if file.Name() == fileName {
testYamlCount++
if file.Name() == "test.yaml" {
testYamlNameCount++
}
policyresoucePath := strings.Trim(yamlFilePath, fileName)
bytes, err := ioutil.ReadAll(file)
if err != nil {
@ -424,22 +420,15 @@ func testCommandExecute(dirPath []string, fileName string, gitBranch string, tes
if testYamlCount == 0 {
fmt.Printf("\n No test yamls available \n")
}
if testYamlNameCount > 0 {
fmt.Printf("\n Note : test.yaml file name is deprecated in 1.6.0 release. Please provide test yaml file as kyverno-test.yaml \n")
}
} else {
var testFiles int
var deprecatedFiles int
path := filepath.Clean(dirPath[0])
errors = getLocalDirTestFiles(fs, path, fileName, rc, &testFiles, &deprecatedFiles, openAPIController, tf)
errors = getLocalDirTestFiles(fs, path, fileName, rc, &testFiles, openAPIController, tf)
if testFiles == 0 {
fmt.Printf("\n No test files found. Please provide test YAML files named kyverno-test.yaml \n")
}
if deprecatedFiles > 0 {
fmt.Printf("\n Note: The test.yaml file name is deprecated in 1.6.0 release. Please use kyverno-test.yaml instead. \n")
}
}
if len(errors) > 0 && log.Log.V(1).Enabled() {
@ -459,7 +448,7 @@ func testCommandExecute(dirPath []string, fileName string, gitBranch string, tes
return rc, nil
}
func getLocalDirTestFiles(fs billy.Filesystem, path, fileName string, rc *resultCounts, testFiles *int, deprecatedFiles *int, openAPIController *openapi.Controller, tf *testFilter) []error {
func getLocalDirTestFiles(fs billy.Filesystem, path, fileName string, rc *resultCounts, testFiles *int, openAPIController *openapi.Controller, tf *testFilter) []error {
var errors []error
files, err := ioutil.ReadDir(path)
@ -468,14 +457,11 @@ func getLocalDirTestFiles(fs billy.Filesystem, path, fileName string, rc *result
}
for _, file := range files {
if file.IsDir() {
getLocalDirTestFiles(fs, filepath.Join(path, file.Name()), fileName, rc, testFiles, deprecatedFiles, openAPIController, tf)
getLocalDirTestFiles(fs, filepath.Join(path, file.Name()), fileName, rc, testFiles, openAPIController, tf)
continue
}
if file.Name() == fileName || file.Name() == "test.yaml" {
if file.Name() == fileName {
*testFiles++
if strings.Compare(file.Name(), "test.yaml") == 0 {
*deprecatedFiles++
}
// We accept the risk of including files here as we read the test dir only.
yamlFile, err := ioutil.ReadFile(filepath.Join(path, file.Name())) // #nosec G304
if err != nil {