Skip to content

Commit

Permalink
Only add log level debug to Build when after platform api 0.2
Browse files Browse the repository at this point in the history
Signed-off-by: David Freilich <dfreilich@vmware.com>
  • Loading branch information
dfreilich committed May 26, 2020
1 parent d3da2ce commit 69ff48d
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 21 deletions.
17 changes: 10 additions & 7 deletions internal/build/phases.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,16 +211,19 @@ func prependArg(arg string, args []string) []string {
}

func (l *Lifecycle) Build(ctx context.Context, networkMode string, volumes []string, phaseFactory PhaseFactory) error {
args := []string{"-layers", layersDir,
"-app", appDir,
"-platform", platformDir,
}

if l.platformAPIVersion > "0.2" { // lifecycle did not support log level for build until platform api 0.3
args = l.withLogLevel(args...)
}

configProvider := NewPhaseConfigProvider(
"builder",
l,
WithArgs(
l.withLogLevel(
"-layers", layersDir,
"-app", appDir,
"-platform", platformDir,
)...,
),
WithArgs(args...),
WithNetwork(networkMode),
WithBinds(volumes...),
)
Expand Down
59 changes: 45 additions & 14 deletions internal/build/phases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,22 +558,53 @@ func testPhases(t *testing.T, when spec.G, it spec.S) {
h.AssertEq(t, fakePhase.RunCallCount, 1)
})

it("configures the phase with the expected arguments", func() {
verboseLifecycle := newTestLifecycle(t, true)
fakePhaseFactory := fakes.NewFakePhaseFactory()
when("platform api <= 0.2", func() {
it("configures the phase with the expected arguments", func() {
platformAPIVersion, err := api.NewVersion("0.2")
h.AssertNil(t, err)
fakeBuilder, err := fakes.NewFakeBuilder(fakes.WithPlatformVersion(platformAPIVersion))
h.AssertNil(t, err)
verboseLifecycle := newTestLifecycle(t, true, fakes.WithBuilder(fakeBuilder))
fakePhaseFactory := fakes.NewFakePhaseFactory()

err := verboseLifecycle.Build(context.Background(), "test", []string{}, fakePhaseFactory)
h.AssertNil(t, err)
err = verboseLifecycle.Build(context.Background(), "test", []string{}, fakePhaseFactory)
h.AssertNil(t, err)

configProvider := fakePhaseFactory.NewCalledWithProvider
h.AssertEq(t, configProvider.Name(), "builder")
h.AssertIncludeAllExpectedPatterns(t,
configProvider.ContainerConfig().Cmd,
[]string{"-log-level", "debug"},
[]string{"-layers", "/layers"},
[]string{"-app", "/workspace"},
[]string{"-platform", "/platform"},
)
configProvider := fakePhaseFactory.NewCalledWithProvider
h.AssertEq(t, configProvider.Name(), "builder")

h.AssertSliceNotContains(t, configProvider.ContainerConfig().Cmd, "-log-level", "debug")
h.AssertIncludeAllExpectedPatterns(t,
configProvider.ContainerConfig().Cmd,
[]string{"-layers", "/layers"},
[]string{"-app", "/workspace"},
[]string{"-platform", "/platform"},
)
})
})

when("platform api > 0.2", func() {
it("configures the phase with the expected arguments", func() {
platformAPIVersion, err := api.NewVersion("0.3")
h.AssertNil(t, err)
fakeBuilder, err := fakes.NewFakeBuilder(fakes.WithPlatformVersion(platformAPIVersion))
h.AssertNil(t, err)
verboseLifecycle := newTestLifecycle(t, true, fakes.WithBuilder(fakeBuilder))
fakePhaseFactory := fakes.NewFakePhaseFactory()

err = verboseLifecycle.Build(context.Background(), "test", []string{}, fakePhaseFactory)
h.AssertNil(t, err)

configProvider := fakePhaseFactory.NewCalledWithProvider
h.AssertEq(t, configProvider.Name(), "builder")
h.AssertIncludeAllExpectedPatterns(t,
configProvider.ContainerConfig().Cmd,
[]string{"-log-level", "debug"},
[]string{"-layers", "/layers"},
[]string{"-app", "/workspace"},
[]string{"-platform", "/platform"},
)
})
})

it("configures the phase with the expected network mode", func() {
Expand Down
8 changes: 8 additions & 0 deletions testhelpers/testhelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ func AssertSliceContains(t *testing.T, slice []string, expected ...string) {
}
}

func AssertSliceNotContains(t *testing.T, slice []string, expected ...string) {
t.Helper()
_, missing, _ := stringset.Compare(slice, expected)
if len(missing) != len(expected) {
t.Fatalf("Expected %s not to contain elements %s", slice, expected)
}
}

func AssertSliceContainsMatch(t *testing.T, slice []string, expected ...string) {
t.Helper()

Expand Down

0 comments on commit 69ff48d

Please sign in to comment.