diff --git a/src/test/e2e/report_test.go b/src/test/e2e/report_test.go index 66dc0ba2..1133e22e 100644 --- a/src/test/e2e/report_test.go +++ b/src/test/e2e/report_test.go @@ -2,48 +2,47 @@ package test import ( "bytes" - "os/exec" "testing" + "github.com/defenseunicorns/lula/src/cmd" "github.com/defenseunicorns/lula/src/pkg/message" "github.com/stretchr/testify/assert" ) -const ( - validMultiComponentPath = "../unit/common/oscal/valid-multi-component.yaml" - catalogPath = "../unit/common/oscal/catalog.yaml" -) - -// TestLulaReportValidComponent checks that the 'lula report' command works with a valid component definition. +// TestLulaReportValidComponent checks that the 'lula report' command works with a valid component definition with multiple components and framework prop. func TestLulaReportValidComponent(t *testing.T) { // Disable progress indicators and other extra formatting message.NoProgress = true - var outBuf, errBuf bytes.Buffer + // Setup the root command and buffers for capturing output + rootCmd := cmd.RootCommand() + rootCmd.SetArgs([]string{"report", "-f", "../unit/common/oscal/valid-multi-component.yaml", "--file-format", "table"}) - cmd := exec.Command("lula", "report", "-f", validMultiComponentPath, "--file-format", "table") - cmd.Stdout = &outBuf - cmd.Stderr = &errBuf + var outBuf, errBuf bytes.Buffer + rootCmd.SetOut(&outBuf) + rootCmd.SetErr(&errBuf) - err := cmd.Run() + // Execute the command + err := rootCmd.Execute() // Check for errors in command execution. - assert.NoError(t, err, "Expected no error from `lula report` with valid component definition") -} + assert.NoError(t, err, "Expected no error from `lula report` with valid component definition")} -// TestLulaReportCatalog checks that the 'lula report' command fails gracefully with a catalog file. -// OSCAL Catalogs are not currently supported by 'lula report' command yet. +// TestLulaReportCatalog checks that the 'lula report' command fails gracefully with a catalog file since it is not currently supported. +// TODO: This test will need to be changed as more models are supported for reporting. func TestLulaReportCatalog(t *testing.T) { // Disable progress indicators and other extra formatting message.NoProgress = true - var outBuf, errBuf bytes.Buffer + // Setup the root command and buffers for capturing output + rootCmd := cmd.RootCommand() + rootCmd.SetArgs([]string{"report", "-f", "../unit/common/oscal/catalog.yaml", "--file-format", "table"}) - cmd := exec.Command("lula", "report", "-f", catalogPath, "--file-format", "table") - cmd.Stdout = &outBuf - cmd.Stderr = &errBuf + var outBuf, errBuf bytes.Buffer + rootCmd.SetOut(&outBuf) + rootCmd.SetErr(&errBuf) - err := cmd.Run() + // Execute the command + err := rootCmd.Execute() - assert.Error(t, err, "error running report") -} + assert.Error(t, err, "Expected an error running report")}