-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bundle git branch validation (#645)
## Changes This PR: 1. Fixes the computation logic for `ActualBranch`. An error in the earlier logic caused the validation mutator to be a no-op. 2. Makes the `.git` string a global var. This is useful to configure in tests. 3. Adds e2e test for the validation mutator. ## Tests Unit test
- Loading branch information
1 parent
81ee031
commit d6f6269
Showing
6 changed files
with
61 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ref: refs/heads/feature-b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
bundle: | ||
name: "Dancing Feet" | ||
git: | ||
branch: "feature-a" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package config_tests | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/databricks/cli/bundle" | ||
"github.com/databricks/cli/bundle/config/mutator" | ||
"github.com/databricks/cli/libs/git" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGitAutoLoad(t *testing.T) { | ||
b := load(t, "./autoload_git") | ||
assert.True(t, b.Config.Bundle.Git.Inferred) | ||
assert.Contains(t, b.Config.Bundle.Git.OriginURL, "/cli") | ||
} | ||
|
||
func TestGitManuallySetBranch(t *testing.T) { | ||
b := loadEnvironment(t, "./autoload_git", "production") | ||
assert.False(t, b.Config.Bundle.Git.Inferred) | ||
assert.Equal(t, "main", b.Config.Bundle.Git.Branch) | ||
assert.Contains(t, b.Config.Bundle.Git.OriginURL, "/cli") | ||
} | ||
|
||
func TestGitBundleBranchValidation(t *testing.T) { | ||
git.GitDirectoryName = ".mock-git" | ||
t.Cleanup(func() { | ||
git.GitDirectoryName = ".git" | ||
}) | ||
|
||
b := load(t, "./git_branch_validation") | ||
assert.False(t, b.Config.Bundle.Git.Inferred) | ||
assert.Equal(t, "feature-a", b.Config.Bundle.Git.Branch) | ||
assert.Equal(t, "feature-b", b.Config.Bundle.Git.ActualBranch) | ||
|
||
err := bundle.Apply(context.Background(), b, mutator.ValidateGitDetails()) | ||
assert.ErrorContains(t, err, "not on the right Git branch:") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters