From 821239e45d969dccb14e64891e7abc70a44f937b Mon Sep 17 00:00:00 2001 From: Lennart Kats Date: Mon, 2 Sep 2024 14:00:28 +0200 Subject: [PATCH] Add nil check --- bundle/config/mutator/process_target_mode.go | 3 +++ bundle/config/mutator/process_target_mode_test.go | 13 +++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/bundle/config/mutator/process_target_mode.go b/bundle/config/mutator/process_target_mode.go index 8bcff0ca..4602fc5d 100644 --- a/bundle/config/mutator/process_target_mode.go +++ b/bundle/config/mutator/process_target_mode.go @@ -158,6 +158,9 @@ func isRunAsSet(r config.Resources) bool { } func isExplicitRootSet(b *bundle.Bundle) bool { + if b.Config.Targets == nil { + return false + } targetConfig := b.Config.Targets[b.Config.Bundle.Target] if targetConfig.Workspace == nil { return false diff --git a/bundle/config/mutator/process_target_mode_test.go b/bundle/config/mutator/process_target_mode_test.go index 804371c0..a4730b10 100644 --- a/bundle/config/mutator/process_target_mode_test.go +++ b/bundle/config/mutator/process_target_mode_test.go @@ -32,10 +32,7 @@ func mockBundle(mode config.Mode) *bundle.Bundle { Branch: "main", }, }, - Targets: map[string]*config.Target{ - "": {}, - }, - Workspace: config.Workspace{ + Workspace: config.Workspace{ CurrentUser: &config.User{ ShortName: "lennart", User: &iam.User{ @@ -337,8 +334,12 @@ func TestProcessTargetModeProductionOkWithRootPath(t *testing.T) { require.Error(t, diags.Error()) // ... but we're okay if we specify a root path - b.Config.Targets[""].Workspace = &config.Workspace{ - RootPath: "some-root-path", + b.Config.Targets = map[string]*config.Target{ + "": { + Workspace: &config.Workspace{ + RootPath: "some-root-path", + }, + }, } diags = validateProductionMode(context.Background(), b, false) require.NoError(t, diags.Error())