-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: derive jsonschema and fix up issues, validate examples dir… (#4611)
Signed-off-by: Paul Brabban <paul.brabban@gmail.com>
- Loading branch information
Showing
14 changed files
with
247 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ spec: | |
arguments: | ||
parameters: | ||
- name: lines-count | ||
value: 3 | ||
value: '3' | ||
artifacts: | ||
- name: text | ||
raw: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,4 @@ spec: | |
mirrorVolumeMounts: true | ||
volumes: | ||
- name: foo | ||
emptyDir: | ||
emptyDir: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package validation | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestValidateExamples(t *testing.T) { | ||
failures, err := ValidateArgoYamlRecursively(".", []string{"testvolume.yaml", "memoize-simple.yaml"}) | ||
if err != nil { | ||
t.Errorf("There was an error: %s", err) | ||
} | ||
if len(failures) > 0 { | ||
var fails = []string{} | ||
for path, fail := range failures { | ||
fails = append(fails, fmt.Sprintf("Validation failed - %s: %s", path, strings.Join(fail, "\n"))) | ||
} | ||
t.Errorf("There were validation failures:\n%s", strings.Join(fails, "\n")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package validation | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/xeipuuv/gojsonschema" | ||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
// https://stackoverflow.com/questions/10485743/contains-method-for-a-slice | ||
func contains(s []string, e string) bool { | ||
for _, a := range s { | ||
if a == e { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func ValidateArgoYamlRecursively(fromPath string, skipFileNames []string) (map[string][]string, error) { | ||
|
||
schemaBytes, err := ioutil.ReadFile("../api/jsonschema/schema.json") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
schemaLoader := gojsonschema.NewStringLoader(string(schemaBytes)) | ||
|
||
failed := map[string][]string{} | ||
|
||
err = filepath.Walk(fromPath, func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
if contains(skipFileNames, info.Name()) { | ||
//fmt.Printf("skipping %+v \n", info.Name()) | ||
return filepath.SkipDir | ||
} | ||
if info.IsDir() { | ||
return nil | ||
} | ||
if filepath.Ext(path) != ".yaml" { | ||
return nil | ||
} | ||
yamlBytes, err := ioutil.ReadFile(path) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
jsonDoc, err := yaml.YAMLToJSON(yamlBytes) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
documentLoader := gojsonschema.NewStringLoader(string(jsonDoc)) | ||
|
||
result, err := gojsonschema.Validate(schemaLoader, documentLoader) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !result.Valid() { | ||
errorDescriptions := []string{} | ||
for _, err := range result.Errors() { | ||
errorDescriptions = append(errorDescriptions, err.Description()) | ||
} | ||
failed[path] = errorDescriptions | ||
} | ||
return nil | ||
}) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return failed, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters