Skip to content

Commit

Permalink
fix e2e test
Browse files Browse the repository at this point in the history
  • Loading branch information
CloudBeard committed Sep 27, 2024
1 parent 6296154 commit d707143
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions src/test/e2e/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")}

0 comments on commit d707143

Please sign in to comment.