Skip to content

Commit

Permalink
Merge pull request #52 from elisasre/kapifixes
Browse files Browse the repository at this point in the history
Kapi fixes
  • Loading branch information
zetaab authored Nov 27, 2023
2 parents 886fb7e + c9fe8e5 commit f3822ed
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
10 changes: 10 additions & 0 deletions docker/target/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,13 @@ func (Docker) Push(ctx context.Context) error {
func (Docker) Build(ctx context.Context) error {
return docker.BuildDefault(ctx, ImageName, ProjectUrl)
}

// Up start containers in daemon mode
func (Docker) Up(ctx context.Context) error {
return docker.Docker(ctx, "compose", "up", "-d")
}

// Down stops containers in daemon mode
func (Docker) Down(ctx context.Context) error {
return docker.Docker(ctx, "compose", "down", "-v", "--remove-orphans")
}
16 changes: 11 additions & 5 deletions golang/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,24 @@ func WithSHA(info BuildInfo, err error) (BuildInfo, error) {
}

// BuildForTesting builds binary that is instrumented for coverage collection and race detection.
func BuildForTesting(ctx context.Context, target string) (BuildInfo, error) {
env := map[string]string{
"CGO_ENABLED": "1",
func BuildForTesting(ctx context.Context, target string, raceDetection bool, binDir string) (BuildInfo, error) {
var env map[string]string
if !raceDetection {
env = map[string]string{
"CGO_ENABLED": "1",
}
}

pkgs, err := ListPackages(ctx, "./...")
if err != nil {
return BuildInfo{}, err
}

args := []string{"-race", "-cover", "-covermode", "atomic", "-coverpkg=" + strings.Join(pkgs, ",")}
return build(ctx, env, TestBinDir, target, args...)
args := []string{"-cover", "-covermode", "atomic", "-coverpkg=" + strings.Join(pkgs, ",")}
if !raceDetection {
args = append([]string{"-race"}, args...)
}
return build(ctx, env, binDir, target, args...)
}

// BuildFromMatrixWithSHA is a higher level build utility function doing cross compilation with sha calculation.
Expand Down
14 changes: 10 additions & 4 deletions golang/target/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var (
BuildMatrix = golang.DefaultBuildMatrix
RunArgs = []string{}
IntegrationTestRunArgs = []string{}
RunEnvs = map[string]string{}
)

type Go mg.Namespace
Expand All @@ -34,9 +35,15 @@ func (Go) CrossBuild(ctx context.Context) error {
return err
}

// Build build binary with race detection and coverage collections
// TestBuild build binary with race detection and coverage collections
func (Go) TestBuild(ctx context.Context) error {
_, err := golang.WithSHA(golang.BuildForTesting(ctx, BuildTarget))
_, err := golang.WithSHA(golang.BuildForTesting(ctx, BuildTarget, false, golang.TestBinDir))
return err
}

// E2eBuild build binary with coverage collections
func (Go) E2eBuild(ctx context.Context) error {
_, err := golang.WithSHA(golang.BuildForTesting(ctx, BuildTarget, true, golang.BinDir))
return err
}

Expand All @@ -46,8 +53,7 @@ func (Go) Run(ctx context.Context) error {
if err != nil {
return err
}

return sh.RunV(info.BinPath, RunArgs...)
return sh.RunWithV(RunEnvs, info.BinPath, RunArgs...)
}

// Test run unit and integration tests
Expand Down
2 changes: 1 addition & 1 deletion golang/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
//
// For example usage see golang.IntegrationTest function.
func IntegrationTestRunner(ctx context.Context, name, coverDir string, testFn func(ctx context.Context) error, runArgs ...string) error {
buildInfo, err := BuildForTesting(ctx, name)
buildInfo, err := BuildForTesting(ctx, name, false, TestBinDir)
if err != nil {
return fmt.Errorf("builing application failed: %w", err)
}
Expand Down

0 comments on commit f3822ed

Please sign in to comment.