Skip to content

Commit

Permalink
adding verbose log of cyclonedx (#4492)
Browse files Browse the repository at this point in the history
* adding log of cyclonedx

* fix test

* fix integration test

* fix assertion of test

---------

Co-authored-by: asadu <[email protected]>
  • Loading branch information
aibaend1 and asadu authored Aug 2, 2023
1 parent cc080c8 commit a247dc2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion cmd/golangBuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions cmd/golangBuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]"}, 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)
})
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions integration/integration_golang_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand Down Expand Up @@ -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",
)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a247dc2

Please sign in to comment.