Skip to content

Commit

Permalink
Add lifecycle execution tests for phase order
Browse files Browse the repository at this point in the history
Signed-off-by: Sambhav Kothari <skothari44@bloomberg.net>
  • Loading branch information
sambhav committed Nov 22, 2021
1 parent 4187d7b commit 1f855b9
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions internal/build/lifecycle_execution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,69 @@ func testLifecycleExecution(t *testing.T, when spec.G, it spec.S) {
})
})
when("Run without using creator", func() {
when("platform < 0.7", func() {
it("calls the phases with the right order", func() {
opts := build.LifecycleOptions{
Publish: false,
ClearCache: false,
RunImage: "test",
Image: imageName,
Builder: fakeBuilder,
TrustBuilder: false,
UseCreator: false,
}

lifecycle, err := build.NewLifecycleExecution(logger, docker, opts)
h.AssertNil(t, err)

err = lifecycle.Run(context.Background(), func(execution *build.LifecycleExecution) build.PhaseFactory {
return fakePhaseFactory
})
h.AssertNil(t, err)

h.AssertEq(t, len(fakePhaseFactory.NewCalledWithProvider), 5)
expectedPhases := []string{
"detector", "analyzer", "restorer", "builder", "exporter",
}
for i, entry := range fakePhaseFactory.NewCalledWithProvider {
h.AssertEq(t, entry.Name(), expectedPhases[i])
}
})
})

when("platform >= 0.7", func() {
it("calls the phases with the right order", func() {
fakeBuilder, err := fakes.NewFakeBuilder(fakes.WithSupportedPlatformAPIs([]*api.Version{api.MustParse("0.7")}))
h.AssertNil(t, err)

opts := build.LifecycleOptions{
Publish: false,
ClearCache: false,
RunImage: "test",
Image: imageName,
Builder: fakeBuilder,
TrustBuilder: false,
UseCreator: false,
}

lifecycle, err := build.NewLifecycleExecution(logger, docker, opts)
h.AssertNil(t, err)

err = lifecycle.Run(context.Background(), func(execution *build.LifecycleExecution) build.PhaseFactory {
return fakePhaseFactory
})
h.AssertNil(t, err)

h.AssertEq(t, len(fakePhaseFactory.NewCalledWithProvider), 5)
expectedPhases := []string{
"analyzer", "detector", "restorer", "builder", "exporter",
}
for i, entry := range fakePhaseFactory.NewCalledWithProvider {
h.AssertEq(t, entry.Name(), expectedPhases[i])
}
})
})

it("succeeds", func() {
opts := build.LifecycleOptions{
Publish: false,
Expand Down

0 comments on commit 1f855b9

Please sign in to comment.