From a247dc26942626894c9921b4298c54fb5db5a95e Mon Sep 17 00:00:00 2001 From: aibaend1 <106729492+aibaend1@users.noreply.github.com> Date: Wed, 2 Aug 2023 13:47:06 +0600 Subject: [PATCH] adding verbose log of cyclonedx (#4492) * adding log of cyclonedx * fix test * fix integration test * fix assertion of test --------- Co-authored-by: asadu --- cmd/golangBuild.go | 3 ++- cmd/golangBuild_test.go | 5 +++-- integration/integration_golang_test.go | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cmd/golangBuild.go b/cmd/golangBuild.go index 3066eced81..9fae08a008 100644 --- a/cmd/golangBuild.go +++ b/cmd/golangBuild.go @@ -570,7 +570,8 @@ func lookupGolangPrivateModulesRepositories(goModFile *modfile.File, globPattern } func runBOMCreation(utils golangBuildUtils, outputFilename string) error { - if err := utils.RunExecutable("cyclonedx-gomod", "mod", "-licenses", "-test", "-output", outputFilename, "-output-version", "1.4"); err != nil { + + if err := utils.RunExecutable("cyclonedx-gomod", "mod", "-licenses", fmt.Sprintf("-verbose=%t", GeneralConfig.Verbose), "-test", "-output", outputFilename, "-output-version", "1.4"); err != nil { return fmt.Errorf("BOM creation failed: %w", err) } return nil diff --git a/cmd/golangBuild_test.go b/cmd/golangBuild_test.go index f65145f352..8709cb0e30 100644 --- a/cmd/golangBuild_test.go +++ b/cmd/golangBuild_test.go @@ -286,7 +286,7 @@ go 1.17` assert.Equal(t, "go", utils.ExecMockRunner.Calls[0].Exec) assert.Equal(t, []string{"install", "github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@v1.4.0"}, utils.ExecMockRunner.Calls[0].Params) assert.Equal(t, "cyclonedx-gomod", utils.ExecMockRunner.Calls[1].Exec) - assert.Equal(t, []string{"mod", "-licenses", "-test", "-output", "bom-golang.xml", "-output-version", "1.4"}, utils.ExecMockRunner.Calls[1].Params) + assert.Equal(t, []string{"mod", "-licenses", "-verbose=false", "-test", "-output", "bom-golang.xml", "-output-version", "1.4"}, utils.ExecMockRunner.Calls[1].Params) assert.Equal(t, "go", utils.ExecMockRunner.Calls[2].Exec) assert.Equal(t, []string{"build", "-trimpath"}, utils.ExecMockRunner.Calls[2].Params) }) @@ -479,8 +479,9 @@ go 1.17` CreateBOM: true, TargetArchitectures: []string{"linux,amd64"}, } + GeneralConfig.Verbose = false utils := newGolangBuildTestsUtils() - utils.ShouldFailOnCommand = map[string]error{"cyclonedx-gomod mod -licenses -test -output bom-golang.xml": fmt.Errorf("BOM creation failure")} + utils.ShouldFailOnCommand = map[string]error{"cyclonedx-gomod mod -licenses -verbose=false -test -output bom-golang.xml -output-version 1.4": fmt.Errorf("BOM creation failure")} telemetryData := telemetry.CustomData{} err := runGolangBuild(&config, &telemetryData, utils, &cpe) diff --git a/integration/integration_golang_test.go b/integration/integration_golang_test.go index 06b2318a37..e2b20a5559 100644 --- a/integration/integration_golang_test.go +++ b/integration/integration_golang_test.go @@ -34,7 +34,7 @@ func TestGolangIntegrationBuildProject1(t *testing.T) { "info golangBuild - DONE 8 tests", "info golangBuild - running command: go tool cover -html cover.out -o coverage.html", "info golangBuild - running command: gotestsum --junitfile TEST-integration.xml --jsonfile integration-report.out -- -tags=integration ./...", - "info golangBuild - running command: cyclonedx-gomod mod -licenses -test -output bom-golang.xml", + "info golangBuild - running command: cyclonedx-gomod mod -licenses -verbose=false -test -output bom-golang.xml", "info golangBuild - running command: go build -trimpath -o golang-app-linux.amd64 cmd/server/server.go", "info golangBuild - SUCCESS", ) @@ -69,7 +69,7 @@ func TestGolangIntegrationBuildProject1MultiPackage(t *testing.T) { "info golangBuild - DONE 8 tests", "info golangBuild - running command: go tool cover -html cover.out -o coverage.html", "info golangBuild - running command: gotestsum --junitfile TEST-integration.xml --jsonfile integration-report.out -- -tags=integration ./...", - "info golangBuild - running command: cyclonedx-gomod mod -licenses -test -output bom-golang.xml", + "info golangBuild - running command: cyclonedx-gomod mod -licenses -verbose=false -test -output bom-golang.xml", "info golangBuild - running command: go build -trimpath -o golang-app-linux-amd64/ github.com/example/golang-app/cmd/server github.com/example/golang-app/cmd/helper", "info golangBuild - SUCCESS", ) @@ -106,7 +106,7 @@ func TestGolangIntegrationBuildProject2(t *testing.T) { "info golangBuild - running command: gotestsum --junitfile TEST-go.xml --jsonfile unit-report.out -- -coverprofile=cover.out -tags=unit ./...", "info golangBuild - running command: go tool cover -html cover.out -o coverage.html", "info golangBuild - running command: gotestsum --junitfile TEST-integration.xml --jsonfile integration-report.out -- -tags=integration ./...", - "info golangBuild - running command: cyclonedx-gomod mod -licenses -test -output bom-golang.xml", + "info golangBuild - running command: cyclonedx-gomod mod -licenses -verbose=false -test -output bom-golang.xml", ) container.assertHasOutput(t,