Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e2e:chore - tests for the output format and json outuput file flags #763

Merged
merged 1 commit into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 65 additions & 13 deletions e2e/commands/start/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,35 @@ package start_test

import (
"fmt"
"github.com/ZupIT/horusec-devkit/pkg/utils/logger/enums"
"os"

"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
iancardosozup marked this conversation as resolved.
Show resolved Hide resolved
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,58 @@ 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 as JSON", 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 format was set as JSON and the file is created", 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())
})
})

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

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

It("Checks if format was set as text and the file is created", func() {
Expect(session.Out.Contents()).To(ContainSubstring(fmt.Sprintf(`\"print_output_type\": \"%s\"`, outputtype.Text)))
Expect(session.Out.Contents()).To(ContainSubstring(fmt.Sprintf(`\"json_output_file_path\": \"%s\"`, testutil.NormalizePathToAssertInJSON(textOutputPath))))
Expect(textOutputPath).Should(BeAnExistingFile())
})
})

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

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

It("Checks if format was set as sonarqube and the JSON file is created", func() {
Expect(session.Out.Contents()).To(ContainSubstring(fmt.Sprintf(`\"print_output_type\": \"%s\"`, outputtype.SonarQube)))
Expect(session.Out.Contents()).To(ContainSubstring(fmt.Sprintf(`\"json_output_file_path\": \"%s\"`, testutil.NormalizePathToAssertInJSON(sonarqubeOutputPath))))
Expect(sonarqubeOutputPath).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