diff --git a/bundle/config/mutator/resourcemutator/validate_target_mode.go b/bundle/config/mutator/resourcemutator/validate_target_mode.go index 190c60c9b98..3b9fbb57107 100644 --- a/bundle/config/mutator/resourcemutator/validate_target_mode.go +++ b/bundle/config/mutator/resourcemutator/validate_target_mode.go @@ -110,15 +110,17 @@ func findNonUserPath(b *bundle.Bundle) string { if b.Config.Workspace.RootPath != "" && !containsName(b.Config.Workspace.RootPath) { return "root_path" } - if b.Config.Workspace.FilePath != "" && !containsName(b.Config.Workspace.FilePath) { - return "file_path" + if !b.IsImmutableFolder() { + if b.Config.Workspace.FilePath != "" && !containsName(b.Config.Workspace.FilePath) { + return "file_path" + } + if b.Config.Workspace.ArtifactPath != "" && !containsName(b.Config.Workspace.ArtifactPath) { + return "artifact_path" + } } if b.Config.Workspace.ResourcePath != "" && !containsName(b.Config.Workspace.ResourcePath) { return "resource_path" } - if b.Config.Workspace.ArtifactPath != "" && !containsName(b.Config.Workspace.ArtifactPath) { - return "artifact_path" - } if b.Config.Workspace.StatePath != "" && !containsName(b.Config.Workspace.StatePath) { return "state_path" } diff --git a/bundle/config/mutator/resourcemutator/validate_target_mode_test.go b/bundle/config/mutator/resourcemutator/validate_target_mode_test.go index bf82773d9e5..47e435f407c 100644 --- a/bundle/config/mutator/resourcemutator/validate_target_mode_test.go +++ b/bundle/config/mutator/resourcemutator/validate_target_mode_test.go @@ -139,6 +139,58 @@ func TestProcessTargetModeProductionOkWithRootPath(t *testing.T) { require.NoError(t, diags.Error()) } +func TestFindNonUserPath(t *testing.T) { + // No paths set at all. + b := mockBundle(config.Development) + b.Config.Workspace.StatePath = "" + b.Config.Workspace.ArtifactPath = "" + b.Config.Workspace.FilePath = "" + assert.Empty(t, findNonUserPath(b)) + + // All paths contain the username or short name: no non-user path found. + b = mockBundle(config.Development) + b.Config.Workspace.RootPath = "/Users/lennart@company.com/.bundle/x/y/state" + b.Config.Workspace.ResourcePath = "/Users/lennart/.bundle/x/y/resources" + assert.Empty(t, findNonUserPath(b)) + + // root_path is checked first. + b = mockBundle(config.Development) + b.Config.Workspace.RootPath = "/Shared/.bundle/x/y" + assert.Equal(t, "root_path", findNonUserPath(b)) + + // file_path is checked next. + b = mockBundle(config.Development) + b.Config.Workspace.FilePath = "/Shared/.bundle/x/y/files" + assert.Equal(t, "file_path", findNonUserPath(b)) + + // file_path is skipped when the workspace uses an immutable folder. + b = mockBundle(config.Development) + b.Config.Workspace.FilePath = "/Shared/.bundle/x/y/files" + b.Config.Experimental = &config.Experimental{ImmutableFolder: true} + assert.Empty(t, findNonUserPath(b)) + + // resource_path is checked next. + b = mockBundle(config.Development) + b.Config.Workspace.ResourcePath = "/Shared/.bundle/x/y/resources" + assert.Equal(t, "resource_path", findNonUserPath(b)) + + // artifact_path is checked next. + b = mockBundle(config.Development) + b.Config.Workspace.ArtifactPath = "/Shared/.bundle/x/y/artifacts" + assert.Equal(t, "artifact_path", findNonUserPath(b)) + + // artifact_path is skipped when the workspace uses an immutable folder. + b = mockBundle(config.Development) + b.Config.Workspace.ArtifactPath = "/Shared/.bundle/x/y/artifacts" + b.Config.Experimental = &config.Experimental{ImmutableFolder: true} + assert.Empty(t, findNonUserPath(b)) + + // state_path is checked last. + b = mockBundle(config.Development) + b.Config.Workspace.StatePath = "/Shared/.bundle/x/y/state" + assert.Equal(t, "state_path", findNonUserPath(b)) +} + func TestTriggerPauseStatusWhenUnpaused(t *testing.T) { b := mockBundle(config.Development) b.Config.Presets.TriggerPauseStatus = config.Unpaused