diff --git a/e2e/commands/start/start_test.go b/e2e/commands/start/start_test.go index 06139e762..d1d1ead91 100644 --- a/e2e/commands/start/start_test.go +++ b/e2e/commands/start/start_test.go @@ -18,13 +18,14 @@ 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" @@ -32,22 +33,18 @@ import ( 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() { @@ -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, @@ -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()) + }) + }) }) diff --git a/internal/controllers/printresults/print_results_test.go b/internal/controllers/printresults/print_results_test.go index 20b9510aa..3d538a971 100644 --- a/internal/controllers/printresults/print_results_test.go +++ b/internal/controllers/printresults/print_results_test.go @@ -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" @@ -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"