File tree Expand file tree Collapse file tree 4 files changed +58
-3
lines changed Expand file tree Collapse file tree 4 files changed +58
-3
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import (
1111// validatePreflight validates the preflight spec and returns a warning if there is any
1212func validatePreflight (specs PreflightSpecs ) * types.ExitCodeWarning {
1313
14- if specs .PreflightSpec == nil && specs .HostPreflightSpec == nil {
14+ if specs .PreflightSpec == nil && specs .HostPreflightSpec == nil && specs . UploadResultSpecs == nil {
1515 return types .NewExitCodeWarning ("no preflight or host preflight spec was found" )
1616 }
1717
@@ -29,6 +29,15 @@ func validatePreflight(specs PreflightSpecs) *types.ExitCodeWarning {
2929 }
3030 }
3131
32+ if specs .UploadResultSpecs != nil {
33+ for _ , preflight := range specs .UploadResultSpecs {
34+ warning := validatePreflightSpecItems (preflight .Spec .Collectors , preflight .Spec .Analyzers )
35+ if warning != nil {
36+ return warning
37+ }
38+ }
39+ }
40+
3241 return nil
3342}
3443
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ func TestValidatePreflight(t *testing.T) {
2121 "noAnalyzersHostPreflightFile" : "troubleshoot_v1beta2_host_preflight_validate_empty_analyzers_gotest.yaml" ,
2222 "excludedHostCollectorsPreflightFile" : "troubleshoot_v1beta2_host_preflight_validate_excluded_collectors_gotest.yaml" ,
2323 "excludedHostAnalyzersPreflightFile" : "troubleshoot_v1beta2_host_preflight_validate_excluded_analyzers_gotest.yaml" ,
24+ "uploadResultsPreflightFile" : "troubleshoot_v1beta2_preflight_validate_spec_with_upload_results_gotest.yaml" ,
2425 }
2526
2627 tests := []struct {
@@ -83,6 +84,11 @@ func TestValidatePreflight(t *testing.T) {
8384 preflightSpec : testingFiles ["excludedHostAnalyzersPreflightFile" ],
8485 wantWarning : types .NewExitCodeWarning ("All analyzers were excluded by the applied values" ),
8586 },
87+ {
88+ name : "upload-results-preflight" ,
89+ preflightSpec : testingFiles ["uploadResultsPreflightFile" ],
90+ wantWarning : nil ,
91+ },
8692 }
8793
8894 for _ , tt := range tests {
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ set -euo pipefail
44
55tmpdir=" $( mktemp -d) "
66
7+ echo -e " \n========= Running preflights from e2e spec and checking results ========="
78./bin/preflight --debug --interactive=false --format=json examples/preflight/e2e.yaml > " $tmpdir /result.json"
89if [ $? -ne 0 ]; then
910 echo " preflight command failed"
@@ -33,9 +34,10 @@ echo "Failed preflights found"
3334EXIT_STATUS=1
3435fi
3536
36- # test stdin
37+ echo -e " \n========= Running preflights from stdin using e2e spec ========= "
3738cat examples/preflight/e2e.yaml | ./bin/preflight --debug --interactive=false --format=json - > " $tmpdir /result.json"
38- if [ $? -ne 0 ]; then
39+ EXIT_STATUS=$?
40+ if [ $EXIT_STATUS -ne 0 ]; then
3941 echo " preflight command failed"
4042 exit $EXIT_STATUS
4143fi
Original file line number Diff line number Diff line change 1+ apiVersion : troubleshoot.sh/v1beta2
2+ kind : Preflight
3+ metadata :
4+ name : go-test-preflight
5+ spec :
6+ uploadResultsTo : http://someurl
7+ collectors :
8+ - data :
9+ name : example.json
10+ data : |
11+ {
12+ "foo": "bar",
13+ "stuff": {
14+ "foo": "bar",
15+ "bar": true
16+ },
17+ "morestuff": [
18+ {
19+ "foo": {
20+ "bar": 123
21+ }
22+ }
23+ ]
24+ }
25+ analyzers :
26+ - jsonCompare :
27+ checkName : Compare JSON Example
28+ fileName : example.json
29+ path : " morestuff.[0].foo.bar"
30+ value : |
31+ 123
32+ outcomes :
33+ - fail :
34+ when : " false"
35+ message : The collected data does not match the value.
36+ - pass :
37+ when : " true"
38+ message : The collected data matches the value.
You can’t perform that action at this time.
0 commit comments