mirror of https://github.com/databricks/cli.git
Move loadGitDetails mutator to Initialize phase
This will require API call and we want to keep Load phase fast.
This commit is contained in:
parent
7b9726dd64
commit
84d535a412
|
@ -26,7 +26,6 @@ func DefaultMutators() []bundle.Mutator {
|
||||||
ComputeIdToClusterId(),
|
ComputeIdToClusterId(),
|
||||||
InitializeVariables(),
|
InitializeVariables(),
|
||||||
DefineDefaultTarget(),
|
DefineDefaultTarget(),
|
||||||
LoadGitDetails(),
|
|
||||||
pythonmutator.PythonMutator(pythonmutator.PythonMutatorPhaseLoad),
|
pythonmutator.PythonMutator(pythonmutator.PythonMutatorPhaseLoad),
|
||||||
|
|
||||||
// Note: This mutator must run before the target overrides are merged.
|
// Note: This mutator must run before the target overrides are merged.
|
||||||
|
|
|
@ -39,6 +39,7 @@ func Initialize() bundle.Mutator {
|
||||||
mutator.MergePipelineClusters(),
|
mutator.MergePipelineClusters(),
|
||||||
mutator.InitializeWorkspaceClient(),
|
mutator.InitializeWorkspaceClient(),
|
||||||
mutator.PopulateCurrentUser(),
|
mutator.PopulateCurrentUser(),
|
||||||
|
mutator.LoadGitDetails(),
|
||||||
|
|
||||||
mutator.DefineDefaultWorkspaceRoot(),
|
mutator.DefineDefaultWorkspaceRoot(),
|
||||||
mutator.ExpandWorkspaceRoot(),
|
mutator.ExpandWorkspaceRoot(),
|
||||||
|
|
|
@ -1,15 +1,19 @@
|
||||||
package config_tests
|
package config_tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/databricks/cli/bundle"
|
||||||
|
"github.com/databricks/cli/bundle/config/mutator"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGitAutoLoadWithEnvironment(t *testing.T) {
|
func TestGitAutoLoadWithEnvironment(t *testing.T) {
|
||||||
b := load(t, "./environments_autoload_git")
|
b := load(t, "./environments_autoload_git")
|
||||||
|
bundle.Apply(context.Background(), b, mutator.LoadGitDetails())
|
||||||
assert.True(t, b.Config.Bundle.Git.Inferred)
|
assert.True(t, b.Config.Bundle.Git.Inferred)
|
||||||
validUrl := strings.Contains(b.Config.Bundle.Git.OriginURL, "/cli") || strings.Contains(b.Config.Bundle.Git.OriginURL, "/bricks")
|
validUrl := strings.Contains(b.Config.Bundle.Git.OriginURL, "/cli") || strings.Contains(b.Config.Bundle.Git.OriginURL, "/bricks")
|
||||||
assert.True(t, validUrl, fmt.Sprintf("Expected URL to contain '/cli' or '/bricks', got %s", b.Config.Bundle.Git.OriginURL))
|
assert.True(t, validUrl, fmt.Sprintf("Expected URL to contain '/cli' or '/bricks', got %s", b.Config.Bundle.Git.OriginURL))
|
||||||
|
@ -17,6 +21,7 @@ func TestGitAutoLoadWithEnvironment(t *testing.T) {
|
||||||
|
|
||||||
func TestGitManuallySetBranchWithEnvironment(t *testing.T) {
|
func TestGitManuallySetBranchWithEnvironment(t *testing.T) {
|
||||||
b := loadTarget(t, "./environments_autoload_git", "production")
|
b := loadTarget(t, "./environments_autoload_git", "production")
|
||||||
|
bundle.Apply(context.Background(), b, mutator.LoadGitDetails())
|
||||||
assert.False(t, b.Config.Bundle.Git.Inferred)
|
assert.False(t, b.Config.Bundle.Git.Inferred)
|
||||||
assert.Equal(t, "main", b.Config.Bundle.Git.Branch)
|
assert.Equal(t, "main", b.Config.Bundle.Git.Branch)
|
||||||
validUrl := strings.Contains(b.Config.Bundle.Git.OriginURL, "/cli") || strings.Contains(b.Config.Bundle.Git.OriginURL, "/bricks")
|
validUrl := strings.Contains(b.Config.Bundle.Git.OriginURL, "/cli") || strings.Contains(b.Config.Bundle.Git.OriginURL, "/bricks")
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
|
|
||||||
func TestGitAutoLoad(t *testing.T) {
|
func TestGitAutoLoad(t *testing.T) {
|
||||||
b := load(t, "./autoload_git")
|
b := load(t, "./autoload_git")
|
||||||
|
bundle.Apply(context.Background(), b, mutator.LoadGitDetails())
|
||||||
assert.True(t, b.Config.Bundle.Git.Inferred)
|
assert.True(t, b.Config.Bundle.Git.Inferred)
|
||||||
validUrl := strings.Contains(b.Config.Bundle.Git.OriginURL, "/cli") || strings.Contains(b.Config.Bundle.Git.OriginURL, "/bricks")
|
validUrl := strings.Contains(b.Config.Bundle.Git.OriginURL, "/cli") || strings.Contains(b.Config.Bundle.Git.OriginURL, "/bricks")
|
||||||
assert.True(t, validUrl, fmt.Sprintf("Expected URL to contain '/cli' or '/bricks', got %s", b.Config.Bundle.Git.OriginURL))
|
assert.True(t, validUrl, fmt.Sprintf("Expected URL to contain '/cli' or '/bricks', got %s", b.Config.Bundle.Git.OriginURL))
|
||||||
|
@ -21,6 +22,7 @@ func TestGitAutoLoad(t *testing.T) {
|
||||||
|
|
||||||
func TestGitManuallySetBranch(t *testing.T) {
|
func TestGitManuallySetBranch(t *testing.T) {
|
||||||
b := loadTarget(t, "./autoload_git", "production")
|
b := loadTarget(t, "./autoload_git", "production")
|
||||||
|
bundle.Apply(context.Background(), b, mutator.LoadGitDetails())
|
||||||
assert.False(t, b.Config.Bundle.Git.Inferred)
|
assert.False(t, b.Config.Bundle.Git.Inferred)
|
||||||
assert.Equal(t, "main", b.Config.Bundle.Git.Branch)
|
assert.Equal(t, "main", b.Config.Bundle.Git.Branch)
|
||||||
validUrl := strings.Contains(b.Config.Bundle.Git.OriginURL, "/cli") || strings.Contains(b.Config.Bundle.Git.OriginURL, "/bricks")
|
validUrl := strings.Contains(b.Config.Bundle.Git.OriginURL, "/cli") || strings.Contains(b.Config.Bundle.Git.OriginURL, "/bricks")
|
||||||
|
@ -34,6 +36,7 @@ func TestGitBundleBranchValidation(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
b := load(t, "./git_branch_validation")
|
b := load(t, "./git_branch_validation")
|
||||||
|
bundle.Apply(context.Background(), b, mutator.LoadGitDetails())
|
||||||
assert.False(t, b.Config.Bundle.Git.Inferred)
|
assert.False(t, b.Config.Bundle.Git.Inferred)
|
||||||
assert.Equal(t, "feature-a", b.Config.Bundle.Git.Branch)
|
assert.Equal(t, "feature-a", b.Config.Bundle.Git.Branch)
|
||||||
assert.Equal(t, "feature-b", b.Config.Bundle.Git.ActualBranch)
|
assert.Equal(t, "feature-b", b.Config.Bundle.Git.ActualBranch)
|
||||||
|
|
Loading…
Reference in New Issue