Skip to content

Commit

Permalink
refactor!(evaluate): #388 EvaluateResults now uses pointers
Browse files Browse the repository at this point in the history
refactor!(component): change NewOscalComponentDefinitionFromBytes to return a pointer
  • Loading branch information
mike-winberry committed May 10, 2024
1 parent 1d74a87 commit a09dffd
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/cmd/evaluate/evaluate.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func EvaluateAssessmentResults(files []string) error {
}
// We write results to the assessment-results report in newest -> oldest
// Older being our threshold here
status, findings, err = EvaluateResults(assessment.Results[1], assessment.Results[0])
status, findings, err = EvaluateResults(&assessment.Results[1], &assessment.Results[0])
if err != nil {
return err
}
Expand All @@ -94,7 +94,7 @@ func EvaluateAssessmentResults(files []string) error {
// Consider parsing the timestamps for comparison
// Older timestamp being the threshold

status, findings, err = EvaluateResults(assessmentOne.Results[0], assessmentTwo.Results[0])
status, findings, err = EvaluateResults(&assessmentOne.Results[0], &assessmentTwo.Results[0])
if err != nil {
return err
}
Expand All @@ -120,7 +120,7 @@ func EvaluateAssessmentResults(files []string) error {
}
}

func EvaluateResults(thresholdResult oscalTypes_1_1_2.Result, newResult oscalTypes_1_1_2.Result) (bool, map[string][]oscalTypes_1_1_2.Finding, error) {
func EvaluateResults(thresholdResult *oscalTypes_1_1_2.Result, newResult *oscalTypes_1_1_2.Result) (bool, map[string][]oscalTypes_1_1_2.Finding, error) {
spinner := message.NewProgressSpinner("Evaluating Assessment Results %s against %s", newResult.UUID, thresholdResult.UUID)
defer spinner.Stop()

Expand Down
10 changes: 5 additions & 5 deletions src/cmd/evaluate/evaluate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestEvaluateResultsPassing(t *testing.T) {
},
}

status, _, err := EvaluateResults(mockThresholdResult, mockEvaluationResult)
status, _, err := EvaluateResults(&mockThresholdResult, &mockEvaluationResult)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestEvaluateResultsFailed(t *testing.T) {
},
}

status, findings, err := EvaluateResults(mockThresholdResult, mockEvaluationResult)
status, findings, err := EvaluateResults(&mockThresholdResult, &mockEvaluationResult)
if err != nil {
t.Fatal(err)
}
Expand All @@ -103,7 +103,7 @@ func TestEvaluateResultsNoFindings(t *testing.T) {
Findings: &[]oscalTypes_1_1_2.Finding{},
}

status, _, err := EvaluateResults(mockThresholdResult, mockEvaluationResult)
status, _, err := EvaluateResults(&mockThresholdResult, &mockEvaluationResult)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestEvaluateResultsNoThreshold(t *testing.T) {
},
}

_, _, err := EvaluateResults(mockThresholdResult, mockEvaluationResult)
_, _, err := EvaluateResults(&mockThresholdResult, &mockEvaluationResult)
if err == nil {
t.Fatal("error - expected error, got nil")
}
Expand Down Expand Up @@ -182,7 +182,7 @@ func TestEvaluateResultsNewFindings(t *testing.T) {
},
}

status, findings, err := EvaluateResults(mockThresholdResult, mockEvaluationResult)
status, findings, err := EvaluateResults(&mockThresholdResult, &mockEvaluationResult)
if err != nil {
t.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions src/pkg/common/composition/composition.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ func ComposeComponentDefinitions(compDef *oscalTypes_1_1_2.ComponentDefinition)
}

// Recurse and compose the component definition
err = ComposeComponentDefinitions(&importDef)
err = ComposeComponentDefinitions(importDef)
if err != nil {
return err
}

// Merge the component definitions
compDef, err = oscal.MergeComponentDefinitions(compDef, &importDef)
compDef, err = oscal.MergeComponentDefinitions(compDef, importDef)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions src/pkg/common/oscal/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ func NewOscalComponentDefinition(source string, data []byte) (componentDefinitio
}

// NewOscalComponentDefinitionFromBytes consumes a byte array and returns a new single OscalComponentDefinitionModel object
func NewOscalComponentDefinitionFromBytes(data []byte) (componentDefinition oscalTypes_1_1_2.ComponentDefinition, err error) {
func NewOscalComponentDefinitionFromBytes(data []byte) (componentDefinition *oscalTypes_1_1_2.ComponentDefinition, err error) {
var oscalModels oscalTypes_1_1_2.OscalModels
err = yaml.Unmarshal(data, &oscalModels)
if err != nil {
return componentDefinition, err
}
return *oscalModels.ComponentDefinition, nil
return oscalModels.ComponentDefinition, nil
}

// This function should perform a merge of two component-definitions where maintaining the original component-definition is the primary concern.
Expand Down

0 comments on commit a09dffd

Please sign in to comment.