Skip to content

Commit

Permalink
Debug flag should apply to single invocation only (#3241)
Browse files Browse the repository at this point in the history
* test: Add integration test

Signed-off-by: Kim Christensen <kimworking@gmail.com>

* fix: Debug flag should apply to single invocation

Signed-off-by: Kim Christensen <kimworking@gmail.com>

---------

Signed-off-by: Kim Christensen <kimworking@gmail.com>
  • Loading branch information
kichristensen authored Nov 1, 2024
1 parent 3dbecb1 commit 055b785
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/porter/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions tests/integration/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ===")
}

0 comments on commit 055b785

Please sign in to comment.