Skip to content

Commit

Permalink
fix: print unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
meganwolf0 committed Nov 5, 2024
1 parent 419d93b commit ba27bd9
Showing 1 changed file with 2 additions and 30 deletions.
32 changes: 2 additions & 30 deletions src/cmd/dev/print_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ import (
)

const (
assessmentPath = "../../test/unit/common/oscal/valid-assessment-results-with-resources.yaml"
componentPath = "../../test/unit/common/oscal/valid-multi-component-validations.yaml"
nonComposedComponentPath = "../../test/e2e/scenarios/validation-composition/component-definition.yaml"
nonComposedAssessmentPath = "../../test/e2e/scenarios/validation-composition/assessment-results.yaml"
assessmentPath = "../../test/unit/common/oscal/valid-assessment-results-with-resources.yaml"
componentPath = "../../test/unit/common/oscal/valid-multi-component-validations.yaml"
)

func TestPrintResources(t *testing.T) {
Expand Down Expand Up @@ -93,32 +91,6 @@ func TestPrintValidation(t *testing.T) {
require.Equal(t, validationData, printedData)
})

t.Run("Test print validation non-composed component", func(t *testing.T) {
nonComposedAssessmentModel := testhelpers.OscalFromPath(t, nonComposedAssessmentPath)
nonComposedAssessment := nonComposedAssessmentModel.AssessmentResults
require.NotNil(t, nonComposedAssessment)

nonComposedComponentModel := testhelpers.OscalFromPath(t, nonComposedComponentPath)
nonComposedComponent := nonComposedComponentModel.ComponentDefinition
require.NotNil(t, nonComposedComponent)

tmpFile := testhelpers.CreateTempFile(t, ".json")
defer os.Remove(tmpFile.Name())

err := dev.PrintValidation(nonComposedComponent, nonComposedAssessment, "d328a0a1-630b-40a2-9c9d-4818420a4126", tmpFile.Name())
require.NoError(t, err)

// get printed data
printedData, err := os.ReadFile(tmpFile.Name())
require.NoError(t, err)

// get actual data
validationData, err := os.ReadFile("../../test/e2e/scenarios/validation-composition/validation.opa.yaml")
require.NoError(t, err)

require.Equal(t, validationData, printedData)
})

t.Run("Test print validation with no validation prop", func(t *testing.T) {
err := dev.PrintValidation(component, assessment, "e1ca2968-8652-41be-a19f-c32bc0b3086c", "")
require.ErrorContains(t, err, "no validation linked to observation")
Expand Down

0 comments on commit ba27bd9

Please sign in to comment.