Skip to content

Commit

Permalink
e2e: test for the output format and json outuput file flags
Browse files Browse the repository at this point in the history
Signed-off-by: lucas.bruno <lucas.bruno@zup.com.br>
  • Loading branch information
lucasbrunozup committed Nov 11, 2021
1 parent 92e1d0d commit 99375ba
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
42 changes: 29 additions & 13 deletions e2e/commands/start/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,33 @@ import (
"fmt"
"os"

"github.com/ZupIT/horusec-devkit/pkg/utils/logger/enums"
"github.com/ZupIT/horusec/internal/enums/outputtype"

"github.com/google/uuid"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"

"github.com/ZupIT/horusec-devkit/pkg/utils/logger/enums"

"path/filepath"

"github.com/ZupIT/horusec/internal/utils/testutil"
)

var _ = Describe("running binary Horusec with start parameter", func() {
var (
session *gexec.Session
err error
flags map[string]string
repoAuthorization string
configFilePath = testutil.GoExample1
session *gexec.Session
flags map[string]string
configFilePath = testutil.GoExample1
)

JustBeforeEach(func() {
var err error
cmd := testutil.GinkgoGetHorusecCmdWithFlags(testutil.CmdStart, flags)
session, err = gexec.Start(cmd, GinkgoWriter, GinkgoWriter)
Expect(err).NotTo(HaveOccurred())
session.Wait(testutil.AverageTimeoutAnalyzeForExamplesFolder)

By("runs the command without errors", func() {
Expect(err).NotTo(HaveOccurred())
Expect(session).Should(gexec.Exit(0))
})
Expect(session).Should(gexec.Exit(0))
})

When("global flag --log-level is passed", func() {
Expand Down Expand Up @@ -120,8 +117,9 @@ var _ = Describe("running binary Horusec with start parameter", func() {
})

When("--authorization is passed", func() {
repoAuthorization := uuid.New().String()

BeforeEach(func() {
repoAuthorization = uuid.New().String()
flags = map[string]string{
testutil.StartFlagProjectPath: configFilePath,
testutil.StartFlagAuthorization: repoAuthorization,
Expand All @@ -132,4 +130,22 @@ var _ = Describe("running binary Horusec with start parameter", func() {
Expect(session.Out.Contents()).To(ContainSubstring(fmt.Sprintf(`\"repository_authorization\": \"%s\"`, testutil.NormalizePathToAssertInJSON(repoAuthorization))))
})
})

When("--output-format and --json-output-file is passed", func() {
jsonOutputPath := filepath.Join(os.TempDir(), fmt.Sprintf("%s-e2e-output.json", uuid.New()))

BeforeEach(func() {
flags = map[string]string{
testutil.StartFlagProjectPath: configFilePath,
testutil.StartFlagOutputFormat: outputtype.JSON,
testutil.StartFlagJSONOutputFilePath: jsonOutputPath,
}
})

It("Checks if the repository authorization property was set", func() {
Expect(session.Out.Contents()).To(ContainSubstring(fmt.Sprintf(`\"print_output_type\": \"%s\"`, outputtype.JSON)))
Expect(session.Out.Contents()).To(ContainSubstring(fmt.Sprintf(`\"json_output_file_path\": \"%s\"`, testutil.NormalizePathToAssertInJSON(jsonOutputPath))))
Expect(jsonOutputPath).Should(BeAnExistingFile())
})
})
})
3 changes: 2 additions & 1 deletion internal/controllers/printresults/print_results_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"strings"
"testing"

"github.com/google/uuid"

"github.com/ZupIT/horusec-devkit/pkg/entities/analysis"
entitiesAnalysis "github.com/ZupIT/horusec-devkit/pkg/entities/analysis"
"github.com/ZupIT/horusec-devkit/pkg/entities/vulnerability"
Expand All @@ -33,7 +35,6 @@ import (
"github.com/ZupIT/horusec/internal/enums/outputtype"
"github.com/ZupIT/horusec/internal/helpers/messages"
"github.com/ZupIT/horusec/internal/utils/mock"
"github.com/google/uuid"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down

0 comments on commit 99375ba

Please sign in to comment.