Skip to content

Commit

Permalink
Calculate lifecycle digest and output version as part of acceptance t…
Browse files Browse the repository at this point in the history
…esting

This can help us diagnose weird failures in CI

Signed-off-by: Natalie Arellano <[email protected]>
  • Loading branch information
natalieparellano committed Nov 3, 2023
1 parent 55f4521 commit 3781972
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
8 changes: 8 additions & 0 deletions acceptance/phase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ func (p *PhaseTest) Start(t *testing.T, phaseOp ...func(*testing.T, *PhaseTest))
p.testImageDockerContext,
h.WithArgs("-f", filepath.Join(p.testImageDockerContext, dockerfileName)),
)
t.Logf("Using image %s with lifecycle version %s",
p.testImageRef,
h.DockerRun(
t,
p.testImageRef,
h.WithFlags("--env", "CNB_PLATFORM_API="+latestPlatformAPI, "--entrypoint", "/cnb/lifecycle/lifecycle"),
h.WithArgs("-version"),
))
}

func (p *PhaseTest) Stop(t *testing.T) {
Expand Down
17 changes: 14 additions & 3 deletions testhelpers/binaries.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package testhelpers

import (
"crypto/sha256"
"encoding/hex"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"testing"
)

func MakeAndCopyLifecycle(t *testing.T, goos, goarch, destDir string, envs ...string) {
buildDir, err := filepath.Abs(filepath.Join("..", "out"))
outParentDir, err := filepath.Abs(filepath.Join("..", "out"))
AssertNil(t, err)

cmd := exec.Command("make", fmt.Sprintf("build-%s-%s", goos, goarch)) // #nosec G204
Expand All @@ -21,15 +24,23 @@ func MakeAndCopyLifecycle(t *testing.T, goos, goarch, destDir string, envs ...st
envs = append(
envs,
"PWD="+cmd.Dir,
"BUILD_DIR="+buildDir,
"BUILD_DIR="+outParentDir,
)
cmd.Env = append(os.Environ(), envs...)

t.Log("Building binaries:", cmd.Args)
output := Run(t, cmd)
t.Log(output)

copyLifecycle(t, filepath.Join(buildDir, fmt.Sprintf("%s-%s", goos, goarch), "lifecycle"), destDir)
outDir := filepath.Join(outParentDir, fmt.Sprintf("%s-%s", goos, goarch), "lifecycle")
hasher := sha256.New()
f, err := os.Open(filepath.Join(outDir, "lifecycle")) //#nosec G304
AssertNil(t, err)
_, err = io.Copy(hasher, f)
AssertNil(t, err)
t.Logf("Built lifecycle binary with digest: %s", hex.EncodeToString(hasher.Sum(nil)))

copyLifecycle(t, outDir, destDir)
}

func copyLifecycle(t *testing.T, src, dst string) {
Expand Down

0 comments on commit 3781972

Please sign in to comment.