diff --git a/src/pkg/common/oscal/assessment-results.go b/src/pkg/common/oscal/assessment-results.go index 31a2c331..0d13c401 100644 --- a/src/pkg/common/oscal/assessment-results.go +++ b/src/pkg/common/oscal/assessment-results.go @@ -89,9 +89,9 @@ func GenerateAssessmentResults(findingMap map[string]oscalTypes_1_1_2.Finding, o func MergeAssessmentResults(original *oscalTypes_1_1_2.AssessmentResults, latest *oscalTypes_1_1_2.AssessmentResults) (*oscalTypes_1_1_2.AssessmentResults, error) { results := make([]oscalTypes_1_1_2.Result, 0) - // append new results first - unfurl so as to allow multiple results in the future - results = append(results, original.Results...) + // append newest to oldest results results = append(results, latest.Results...) + results = append(results, original.Results...) original.Results = results original.Metadata.LastModified = time.Now() diff --git a/src/test/e2e/pod_validation_test.go b/src/test/e2e/pod_validation_test.go index 1694a75d..e96d5258 100644 --- a/src/test/e2e/pod_validation_test.go +++ b/src/test/e2e/pod_validation_test.go @@ -180,7 +180,7 @@ func validatePodLabelPass(ctx context.Context, t *testing.T, config *envconf.Con AssessmentResults: report, } - // Write the component definition to file + // Write the assessment results to file err = oscal.WriteOscalModel("sar-test.yaml", &model) if err != nil { message.Fatalf(err, "error writing component to file") @@ -193,11 +193,15 @@ func validatePodLabelPass(ctx context.Context, t *testing.T, config *envconf.Con if err != nil { t.Fatal("Failed generation of Assessment Results object with: ", err) } + + // Get the UUID of the report results - there should only be one + resultId := report.Results[0].UUID + model = oscalTypes_1_1_2.OscalModels{ AssessmentResults: report, } - // Write the component definition to file + // Write the assessment results to file err = oscal.WriteOscalModel("sar-test.yaml", &model) if err != nil { message.Fatalf(err, "error writing component to file") @@ -218,6 +222,10 @@ func validatePodLabelPass(ctx context.Context, t *testing.T, config *envconf.Con t.Fatal("Failed to append results to existing report") } + if resultId != tempAssessment.Results[0].UUID { + t.Fatal("Failed to prepend results to existing report") + } + validatorResponse, err := validation.ValidationCommand("sar-test.yaml") if err != nil { t.Fatal("File failed linting")