2022-03-07 18:15:36 +02:00
|
|
|
//go:build integration
|
2022-02-24 17:57:56 +02:00
|
|
|
// +build integration
|
2022-03-07 18:15:36 +02:00
|
|
|
|
2022-09-19 12:47:13 +02:00
|
|
|
// can be executed with
|
|
|
|
// go test -v -tags integration -run TestGolangIntegration ./integration/...
|
2022-02-24 17:57:56 +02:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
// In this test the piper command golangBuild performs testing, BOM file creation and building a project with entry point in the cmd/server/server.go
|
|
|
|
// The configuration for golangBuild can be found in testdata/TestGolangIntegration/golang-project1/.pipeline/config.yml
|
2022-09-19 12:47:13 +02:00
|
|
|
func TestGolangIntegrationBuildProject1(t *testing.T) {
|
2022-03-29 07:38:11 +02:00
|
|
|
t.Parallel()
|
2022-02-24 17:57:56 +02:00
|
|
|
|
2022-04-14 14:10:32 +02:00
|
|
|
container := givenThisContainer(t, IntegrationTestDockerExecRunnerBundle{
|
|
|
|
Image: "golang:1",
|
|
|
|
TestDir: []string{"testdata", "TestGolangIntegration", "golang-project1"},
|
|
|
|
ExecNoLogin: true,
|
2022-02-24 17:57:56 +02:00
|
|
|
})
|
2022-09-19 12:47:13 +02:00
|
|
|
defer container.terminate(t)
|
|
|
|
|
2022-04-14 14:10:32 +02:00
|
|
|
err := container.whenRunningPiperCommand("golangBuild")
|
2022-02-24 17:57:56 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-09-19 12:47:13 +02:00
|
|
|
container.assertHasOutput(t,
|
|
|
|
"info golangBuild - running command: go install gotest.tools/gotestsum@latest",
|
2023-07-12 17:49:11 +02:00
|
|
|
"info golangBuild - running command: go install github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@v1.4.0",
|
2023-05-03 18:02:11 +02:00
|
|
|
"info golangBuild - running command: gotestsum --junitfile TEST-go.xml --jsonfile unit-report.out -- -coverprofile=cover.out -tags=unit ./...",
|
2022-09-19 12:47:13 +02:00
|
|
|
"info golangBuild - DONE 8 tests",
|
|
|
|
"info golangBuild - running command: go tool cover -html cover.out -o coverage.html",
|
2023-04-05 15:07:54 +02:00
|
|
|
"info golangBuild - running command: gotestsum --junitfile TEST-integration.xml --jsonfile integration-report.out -- -tags=integration ./...",
|
2022-09-19 12:47:13 +02:00
|
|
|
"info golangBuild - running command: cyclonedx-gomod mod -licenses -test -output bom-golang.xml",
|
|
|
|
"info golangBuild - running command: go build -trimpath -o golang-app-linux.amd64 cmd/server/server.go",
|
|
|
|
"info golangBuild - SUCCESS",
|
|
|
|
)
|
|
|
|
|
|
|
|
container.assertHasFiles(t,
|
|
|
|
"/project/TEST-go.xml",
|
|
|
|
"/project/TEST-integration.xml",
|
|
|
|
"/project/bom-golang.xml",
|
|
|
|
"/project/cover.out",
|
|
|
|
"/project/coverage.html",
|
|
|
|
"/project/golang-app-linux.amd64",
|
|
|
|
)
|
2022-04-14 14:10:32 +02:00
|
|
|
}
|
2022-02-24 17:57:56 +02:00
|
|
|
|
2022-09-19 12:47:13 +02:00
|
|
|
// This test extends TestGolangIntegrationBuildProject1 with multi-package build
|
|
|
|
func TestGolangIntegrationBuildProject1MultiPackage(t *testing.T) {
|
2022-04-14 14:10:32 +02:00
|
|
|
t.Parallel()
|
2022-02-24 17:57:56 +02:00
|
|
|
|
2022-04-14 14:10:32 +02:00
|
|
|
container := givenThisContainer(t, IntegrationTestDockerExecRunnerBundle{
|
|
|
|
Image: "golang:1",
|
|
|
|
TestDir: []string{"testdata", "TestGolangIntegration", "golang-project1"},
|
|
|
|
ExecNoLogin: true,
|
|
|
|
})
|
2022-09-19 12:47:13 +02:00
|
|
|
defer container.terminate(t)
|
|
|
|
|
2022-04-14 14:10:32 +02:00
|
|
|
err := container.whenRunningPiperCommand("golangBuild", "--packages", "github.com/example/golang-app/cmd/server,github.com/example/golang-app/cmd/helper")
|
2022-02-24 17:57:56 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-09-19 12:47:13 +02:00
|
|
|
container.assertHasOutput(t, "info golangBuild - running command: go install gotest.tools/gotestsum@latest",
|
2023-07-12 17:49:11 +02:00
|
|
|
"info golangBuild - running command: go install github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@v1.4.0",
|
2023-05-03 18:02:11 +02:00
|
|
|
"info golangBuild - running command: gotestsum --junitfile TEST-go.xml --jsonfile unit-report.out -- -coverprofile=cover.out -tags=unit ./...",
|
2022-09-19 12:47:13 +02:00
|
|
|
"info golangBuild - DONE 8 tests",
|
|
|
|
"info golangBuild - running command: go tool cover -html cover.out -o coverage.html",
|
2023-04-05 15:07:54 +02:00
|
|
|
"info golangBuild - running command: gotestsum --junitfile TEST-integration.xml --jsonfile integration-report.out -- -tags=integration ./...",
|
2022-09-19 12:47:13 +02:00
|
|
|
"info golangBuild - running command: cyclonedx-gomod mod -licenses -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",
|
|
|
|
)
|
|
|
|
|
|
|
|
container.assertHasFiles(t,
|
|
|
|
"/project/TEST-go.xml",
|
|
|
|
"/project/TEST-integration.xml",
|
|
|
|
"/project/bom-golang.xml",
|
|
|
|
"/project/cover.out",
|
|
|
|
"/project/coverage.html",
|
|
|
|
"/project/golang-app-linux-amd64/server",
|
|
|
|
"/project/golang-app-linux-amd64/helper",
|
|
|
|
)
|
2022-02-24 17:57:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// In this test, the piper golangBuild command only builds the project with the entry point at the project root.
|
|
|
|
// The configuration for golangBuild can be found in testdata/TestGolangIntegration/golang-project2/.pipeline/config.yml
|
2022-09-19 12:47:13 +02:00
|
|
|
func TestGolangIntegrationBuildProject2(t *testing.T) {
|
2022-03-29 07:38:11 +02:00
|
|
|
t.Parallel()
|
2022-02-24 17:57:56 +02:00
|
|
|
|
2022-04-14 14:10:32 +02:00
|
|
|
container := givenThisContainer(t, IntegrationTestDockerExecRunnerBundle{
|
|
|
|
Image: "golang:1",
|
|
|
|
TestDir: []string{"testdata", "TestGolangIntegration", "golang-project2"},
|
|
|
|
ExecNoLogin: true,
|
2022-02-24 17:57:56 +02:00
|
|
|
})
|
2022-09-19 12:47:13 +02:00
|
|
|
defer container.terminate(t)
|
|
|
|
|
2022-04-14 14:10:32 +02:00
|
|
|
err := container.whenRunningPiperCommand("golangBuild")
|
2022-02-24 17:57:56 +02:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2022-09-19 12:47:13 +02:00
|
|
|
container.assertHasNoOutput(t,
|
|
|
|
"info golangBuild - running command: go install gotest.tools/gotestsum@latest",
|
2023-07-12 17:49:11 +02:00
|
|
|
"info golangBuild - running command: go install github.com/CycloneDX/cyclonedx-gomod/cmd/cyclonedx-gomod@v1.4.0",
|
2023-05-03 18:02:11 +02:00
|
|
|
"info golangBuild - running command: gotestsum --junitfile TEST-go.xml --jsonfile unit-report.out -- -coverprofile=cover.out -tags=unit ./...",
|
2022-09-19 12:47:13 +02:00
|
|
|
"info golangBuild - running command: go tool cover -html cover.out -o coverage.html",
|
2023-04-05 15:07:54 +02:00
|
|
|
"info golangBuild - running command: gotestsum --junitfile TEST-integration.xml --jsonfile integration-report.out -- -tags=integration ./...",
|
2022-09-19 12:47:13 +02:00
|
|
|
"info golangBuild - running command: cyclonedx-gomod mod -licenses -test -output bom-golang.xml",
|
|
|
|
)
|
|
|
|
|
|
|
|
container.assertHasOutput(t,
|
|
|
|
"info golangBuild - running command: go build -trimpath -o golang-app-linux.amd64",
|
|
|
|
"info golangBuild - SUCCESS",
|
|
|
|
)
|
2022-02-24 17:57:56 +02:00
|
|
|
}
|