From db8f9566fcd73e7d315801ac0e6fa75c31b75e2e Mon Sep 17 00:00:00 2001 From: Cyrill Troxler Date: Tue, 31 Oct 2023 08:14:17 +0100 Subject: [PATCH] fix: panic during env removal The env removal only worked when both parameters were specified. Since we also did it like this in the test, it still passed. --- update/application.go | 2 +- update/application_test.go | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/update/application.go b/update/application.go index a94f743..e8bf169 100644 --- a/update/application.go +++ b/update/application.go @@ -161,7 +161,7 @@ func (cmd *applicationCmd) applyUpdates(app *apps.Application) { } var buildDelEnv []string - if cmd.DeleteEnv != nil { + if cmd.DeleteBuildEnv != nil { buildDelEnv = *cmd.DeleteBuildEnv } app.Spec.ForProvider.BuildEnv = util.UpdateEnvVars(app.Spec.ForProvider.BuildEnv, buildEnv, buildDelEnv) diff --git a/update/application_test.go b/update/application_test.go index 4170a9b..57f3d06 100644 --- a/update/application_test.go +++ b/update/application_test.go @@ -130,16 +130,26 @@ func TestApplication(t *testing.T) { assert.Nil(t, util.EnvVarByName(updated.Spec.ForProvider.BuildEnv, BuildTrigger)) }, }, - "reset env variables": { + "reset env variable": { + orig: existingApp, + cmd: applicationCmd{ + Name: pointer.String(existingApp.Name), + DeleteEnv: &[]string{"foo"}, + }, + checkApp: func(t *testing.T, cmd applicationCmd, orig, updated *apps.Application) { + assert.Empty(t, updated.Spec.ForProvider.Config.Env) + assert.NotEmpty(t, updated.Spec.ForProvider.BuildEnv) + }, + }, + "reset build env variable": { orig: existingApp, cmd: applicationCmd{ Name: pointer.String(existingApp.Name), - DeleteEnv: &[]string{"foo"}, DeleteBuildEnv: &[]string{"BP_ENVIRONMENT_VARIABLE"}, }, checkApp: func(t *testing.T, cmd applicationCmd, orig, updated *apps.Application) { - assert.Equal(t, apps.EnvVars{}, updated.Spec.ForProvider.Config.Env) - assert.Equal(t, apps.EnvVars{}, updated.Spec.ForProvider.BuildEnv) + assert.Empty(t, updated.Spec.ForProvider.BuildEnv) + assert.NotEmpty(t, updated.Spec.ForProvider.Config.Env) }, }, "git auth update user/pass": {