Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
- Remove compat unit tests that are no longer needed
- Only add the compat layer path to the layers for an image if the
  compat.tar exists
- `make acceptance` should only require previous pack fixtures to be a
  valid directory if the env variable is set

Signed-off-by: Natalie Arellano <narellano@pivotal.io>
Signed-off-by: Andrew Meyer <ameyer@pivotal.io>
  • Loading branch information
ameyer-pivotal authored and natalieparellano committed Jan 17, 2020
1 parent cb76022 commit ee81248
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 312 deletions.
15 changes: 8 additions & 7 deletions acceptance/acceptance_test.go
Expand Up @@ -89,11 +89,19 @@ func TestAcceptance(t *testing.T) {
}

previousPackFixturesPath := os.Getenv(envPreviousPackFixturesPath)
var tmpPreviousPackFixturesPath string
if previousPackFixturesPath != "" {
previousPackFixturesPath, err = filepath.Abs(previousPackFixturesPath)
if err != nil {
t.Fatal(err)
}

tmpPreviousPackFixturesPath, err := ioutil.TempDir("", "previous-pack-fixtures")
h.AssertNil(t, err)
defer os.RemoveAll(tmpPreviousPackFixturesPath)

h.RecursiveCopy(t, previousPackFixturesPath, tmpPreviousPackFixturesPath)
h.RecursiveCopy(t, filepath.Join("testdata", "pack_previous_fixtures_overrides"), tmpPreviousPackFixturesPath)
}

lifecycleDescriptor := builder.LifecycleDescriptor{
Expand Down Expand Up @@ -142,13 +150,6 @@ func TestAcceptance(t *testing.T) {
h.AssertNil(t, err)
}

tmpPreviousPackFixturesPath, err := ioutil.TempDir("", "previous-pack-fixtures")
h.AssertNil(t, err)
defer os.RemoveAll(tmpPreviousPackFixturesPath)

h.RecursiveCopy(t, previousPackFixturesPath, tmpPreviousPackFixturesPath)
h.RecursiveCopy(t, filepath.Join("testdata", "pack_previous_fixtures_overrides"), tmpPreviousPackFixturesPath)

resolvedCombos, err := resolveRunCombinations(
combos,
packPath,
Expand Down
2 changes: 1 addition & 1 deletion internal/build/phase_test.go
Expand Up @@ -197,7 +197,7 @@ func testPhase(t *testing.T, when spec.G, it spec.S) {
phase, err := subject.NewPhase("phase", build.WithArgs("some", "args"))
h.AssertNil(t, err)
assertRunSucceeds(t, phase, &outBuf, &errBuf)
h.AssertContains(t, outBuf.String(), `received args [/lifecycle/phase some args]`)
h.AssertContains(t, outBuf.String(), `received args [/cnb/lifecycle/phase some args]`)
})
})

Expand Down
11 changes: 2 additions & 9 deletions internal/build/testdata/fake-lifecycle/Dockerfile
Expand Up @@ -3,17 +3,10 @@ FROM golang
RUN mkdir /lifecycle
WORKDIR /go/src/step
COPY . .
RUN GO111MODULE=on go build -mod=vendor -o /lifecycle/phase ./phase.go

RUN mkdir -p /buildpacks
RUN echo '[[groups]]\n\
[[groups.buildpacks]]\n\
id = orig.buildpack.id\n\
version = orig.buildpack.version\n'\
> /buildpacks/order.toml
RUN GO111MODULE=on go build -mod=vendor -o /cnb/lifecycle/phase ./phase.go

ENV CNB_USER_ID 111
ENV CNB_GROUP_ID 222

LABEL io.buildpacks.stack.id="test.stack"
LABEL io.buildpacks.builder.metadata="{\"buildpacks\":[{\"id\":\"just/buildpack.id\",\"version\":\"1.2.3\"}],\"groups\":[{\"buildpacks\":[{\"id\":\"orig.buildpack.id\",\"version\":\"orig.buildpack.version\"}]}],\"lifecycle\":{\"version\":\"0.5.0\",\"api\":{\"buildpack\":\"0.2\",\"platform\":\"0.1\"}}}"
LABEL io.buildpacks.builder.metadata="{\"buildpacks\":[{\"id\":\"just/buildpack.id\",\"version\":\"1.2.3\"}],\"lifecycle\":{\"version\":\"0.5.0\",\"api\":{\"buildpack\":\"0.2\",\"platform\":\"0.1\"}}}"
6 changes: 4 additions & 2 deletions internal/builder/builder.go
Expand Up @@ -327,8 +327,10 @@ func (b *Builder) Save(logger logging.Logger) error {
return err
}

if err := b.image.AddLayer(compatTar); err != nil {
return errors.Wrap(err, "adding compat.tar layer")
if compatTar != "" {
if err := b.image.AddLayer(compatTar); err != nil {
return errors.Wrap(err, "adding compat.tar layer")
}
}

envTar, err := b.envLayer(tmpDir, b.env)
Expand Down
10 changes: 6 additions & 4 deletions internal/builder/compat.go
Expand Up @@ -17,6 +17,10 @@ const (
)

func (b *Builder) compatLayer(order dist.Order, dest string) (string, error) {
if b.lifecycle == nil {
return "", nil
}

compatTar := path.Join(dest, "compat.tar")
fh, err := os.Create(compatTar)
if err != nil {
Expand All @@ -27,10 +31,8 @@ func (b *Builder) compatLayer(order dist.Order, dest string) (string, error) {
tw := tar.NewWriter(fh)
defer tw.Close()

if b.lifecycle != nil {
if err := compatLifecycle(tw); err != nil {
return "", err
}
if err := compatLifecycle(tw); err != nil {
return "", err
}

return compatTar, nil
Expand Down

0 comments on commit ee81248

Please sign in to comment.