From 055b785f62fb79e72f9fa06544a7104df4313d55 Mon Sep 17 00:00:00 2001 From: Kim Christensen <2461567+kichristensen@users.noreply.github.com> Date: Fri, 1 Nov 2024 19:25:25 +0100 Subject: [PATCH] Debug flag should apply to single invocation only (#3241) * test: Add integration test Signed-off-by: Kim Christensen * fix: Debug flag should apply to single invocation Signed-off-by: Kim Christensen --------- Signed-off-by: Kim Christensen --- pkg/porter/parameters.go | 8 +++++++ tests/integration/upgrade_test.go | 36 +++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/pkg/porter/parameters.go b/pkg/porter/parameters.go index 4d035a3ef..630372d84 100644 --- a/pkg/porter/parameters.go +++ b/pkg/porter/parameters.go @@ -843,6 +843,14 @@ func (p *Porter) applyActionOptionsToInstallation(ctx context.Context, ba Bundle // Default the porter-debug param to --debug if o.DebugMode { parsedOverrides["porter-debug"] = "true" + } else { + // Remove porter-debug parameter from the installation parameters + for i := len(inst.Parameters.Parameters) - 1; i >= 0; i-- { + if inst.Parameters.Parameters[i].Name == "porter-debug" { + inst.Parameters.Parameters = append(inst.Parameters.Parameters[:i], inst.Parameters.Parameters[i+1:]...) + break + } + } } // Apply overrides on to of any pre-existing parameters that were specified previously diff --git a/tests/integration/upgrade_test.go b/tests/integration/upgrade_test.go index e48fac9db..dd0e215a4 100644 --- a/tests/integration/upgrade_test.go +++ b/tests/integration/upgrade_test.go @@ -30,3 +30,39 @@ func TestUpgrade_failedInstallation(t *testing.T) { err = p.UpgradeBundle(ctx, upgradeOpts) require.Error(t, err, "Upgrade should fail, because the installation failed") } + +func TestUpgrade_DebugModeAppliesToSingleInvocation(t *testing.T) { + p := porter.NewTestPorter(t) + defer p.Close() + ctx := p.SetupIntegrationTest() + + p.AddTestBundleDir("testdata/bundles/bundle-with-custom-action", false) + + installOpts := porter.NewInstallOptions() + err := installOpts.Validate(ctx, []string{}, p.Porter) + require.NoError(t, err) + + err = p.InstallBundle(ctx, installOpts) + require.NoError(t, err) + + upgradeOpts := porter.NewUpgradeOptions() + upgradeOpts.DebugMode = true + err = upgradeOpts.Validate(ctx, []string{}, p.Porter) + require.NoError(t, err) + + err = p.UpgradeBundle(ctx, upgradeOpts) + require.NoError(t, err) + output := p.TestConfig.TestContext.GetOutput() + require.Contains(t, output, "== Step Template ===") + p.TestConfig.TestContext.ClearOutputs() + + upgradeOpts = porter.NewUpgradeOptions() + upgradeOpts.DebugMode = false + err = upgradeOpts.Validate(ctx, []string{}, p.Porter) + require.NoError(t, err) + + err = p.UpgradeBundle(ctx, upgradeOpts) + require.NoError(t, err) + output = p.TestConfig.TestContext.GetOutput() + require.NotContains(t, output, "== Step Template ===") +}