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

feat: support extra args for unit-tests #232

Merged
merged 1 commit into from
Mar 10, 2023
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
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
#
# Generated on 2023-03-06T12:13:29Z by kres 3df0fa6-dirty.
# Generated on 2023-03-10T10:39:05Z by kres 60707f3-dirty.

# common variables

Expand All @@ -16,7 +16,7 @@ REGISTRY_AND_USERNAME ?= $(REGISTRY)/$(USERNAME)
GOLANGCILINT_VERSION ?= v1.51.2
GOFUMPT_VERSION ?= v0.4.0
GO_VERSION ?= 1.20
GOIMPORTS_VERSION ?= v0.6.0
GOIMPORTS_VERSION ?= v0.7.0
PROTOBUF_GO_VERSION ?= 1.28.1
GRPC_GO_VERSION ?= 1.3.0
GRPC_GATEWAY_VERSION ?= 2.15.2
Expand Down
2 changes: 1 addition & 1 deletion internal/config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
GoFmtVersion = "v0.4.0"
// GoImportsVersion is the version of goimports.
// renovate: datasource=go depName=golang.org/x/tools
GoImportsVersion = "v0.6.0"
GoImportsVersion = "v0.7.0"
// GolangCIlintVersion is the version of golangci-lint.
// renovate: datasource=go depName=github.com/golangci/golangci-lint
GolangCIlintVersion = "v1.51.2"
Expand Down
36 changes: 27 additions & 9 deletions internal/project/golang/unit_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type UnitTests struct { //nolint:govet
dag.BaseNode

RequiresInsecure bool `yaml:"requiresInsecure"`
// ExtraArgs are extra arguments for `go test`.
ExtraArgs string `yaml:"extraArgs"`

meta *meta.Options
}
Expand All @@ -45,14 +47,24 @@ func (tests *UnitTests) CompileDockerfile(output *dockerfile.Output) error {
return s
}

extraArgs := tests.ExtraArgs
if extraArgs != "" {
extraArgs += " "
}

output.Stage("unit-tests-run").
Description("runs unit-tests").
From("base").
Step(step.Arg("TESTPKGS")).
Step(wrapAsInsecure(step.Script(`go test -v -covermode=atomic -coverprofile=coverage.txt -coverpkg=${TESTPKGS} -count 1 ${TESTPKGS}`).
MountCache(filepath.Join(tests.meta.CachePath, "go-build")).
MountCache(filepath.Join(tests.meta.GoPath, "pkg")).
MountCache("/tmp")))
Step(wrapAsInsecure(
step.Script(
fmt.Sprintf(
`go test -v -covermode=atomic -coverprofile=coverage.txt -coverpkg=${TESTPKGS} -count 1 %s${TESTPKGS}`,
extraArgs),
).
MountCache(filepath.Join(tests.meta.CachePath, "go-build")).
MountCache(filepath.Join(tests.meta.GoPath, "pkg")).
MountCache("/tmp")))

output.Stage("unit-tests").
From("scratch").
Expand All @@ -62,11 +74,17 @@ func (tests *UnitTests) CompileDockerfile(output *dockerfile.Output) error {
Description("runs unit-tests with race detector").
From("base").
Step(step.Arg("TESTPKGS")).
Step(wrapAsInsecure(step.Script(`go test -v -race -count 1 ${TESTPKGS}`).
MountCache(filepath.Join(tests.meta.CachePath, "go-build")).
MountCache(filepath.Join(tests.meta.GoPath, "pkg")).
MountCache("/tmp").
Env("CGO_ENABLED", "1")))
Step(wrapAsInsecure(
step.Script(
fmt.Sprintf(
`go test -v -race -count 1 %s${TESTPKGS}`,
extraArgs,
),
).
MountCache(filepath.Join(tests.meta.CachePath, "go-build")).
MountCache(filepath.Join(tests.meta.GoPath, "pkg")).
MountCache("/tmp").
Env("CGO_ENABLED", "1")))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why tests run with CGO_ENABLED, just a query?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

golang/go#27089

Basically race detector requires cgo


return nil
}
Expand Down