Add nil check

This commit is contained in:
Lennart Kats 2024-09-02 14:00:28 +02:00
parent 2dad625b84
commit 821239e45d
No known key found for this signature in database
GPG Key ID: 1EB8B57673197023
2 changed files with 10 additions and 6 deletions

View File

@ -158,6 +158,9 @@ func isRunAsSet(r config.Resources) bool {
} }
func isExplicitRootSet(b *bundle.Bundle) bool { func isExplicitRootSet(b *bundle.Bundle) bool {
if b.Config.Targets == nil {
return false
}
targetConfig := b.Config.Targets[b.Config.Bundle.Target] targetConfig := b.Config.Targets[b.Config.Bundle.Target]
if targetConfig.Workspace == nil { if targetConfig.Workspace == nil {
return false return false

View File

@ -32,10 +32,7 @@ func mockBundle(mode config.Mode) *bundle.Bundle {
Branch: "main", Branch: "main",
}, },
}, },
Targets: map[string]*config.Target{ Workspace: config.Workspace{
"": {},
},
Workspace: config.Workspace{
CurrentUser: &config.User{ CurrentUser: &config.User{
ShortName: "lennart", ShortName: "lennart",
User: &iam.User{ User: &iam.User{
@ -337,8 +334,12 @@ func TestProcessTargetModeProductionOkWithRootPath(t *testing.T) {
require.Error(t, diags.Error()) require.Error(t, diags.Error())
// ... but we're okay if we specify a root path // ... but we're okay if we specify a root path
b.Config.Targets[""].Workspace = &config.Workspace{ b.Config.Targets = map[string]*config.Target{
RootPath: "some-root-path", "": {
Workspace: &config.Workspace{
RootPath: "some-root-path",
},
},
} }
diags = validateProductionMode(context.Background(), b, false) diags = validateProductionMode(context.Background(), b, false)
require.NoError(t, diags.Error()) require.NoError(t, diags.Error())