2023-07-30 12:44:33 +00:00
|
|
|
package mutator
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/databricks/cli/bundle"
|
|
|
|
"github.com/databricks/cli/bundle/config"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestValidateGitDetailsMatchingBranches(t *testing.T) {
|
2023-11-15 14:03:36 +00:00
|
|
|
b := &bundle.Bundle{
|
2023-07-30 12:44:33 +00:00
|
|
|
Config: config.Root{
|
|
|
|
Bundle: config.Bundle{
|
|
|
|
Git: config.Git{
|
|
|
|
Branch: "main",
|
|
|
|
ActualBranch: "main",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
m := ValidateGitDetails()
|
2024-03-25 14:18:47 +00:00
|
|
|
diags := bundle.Apply(context.Background(), b, m)
|
|
|
|
assert.NoError(t, diags.Error())
|
2023-07-30 12:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestValidateGitDetailsNonMatchingBranches(t *testing.T) {
|
2023-11-15 14:03:36 +00:00
|
|
|
b := &bundle.Bundle{
|
2023-07-30 12:44:33 +00:00
|
|
|
Config: config.Root{
|
|
|
|
Bundle: config.Bundle{
|
|
|
|
Git: config.Git{
|
|
|
|
Branch: "main",
|
|
|
|
ActualBranch: "feature",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
m := ValidateGitDetails()
|
2024-03-25 14:18:47 +00:00
|
|
|
diags := bundle.Apply(context.Background(), b, m)
|
2023-07-30 12:44:33 +00:00
|
|
|
|
|
|
|
expectedError := "not on the right Git branch:\n expected according to configuration: main\n actual: feature\nuse --force to override"
|
2024-03-25 14:18:47 +00:00
|
|
|
assert.EqualError(t, diags.Error(), expectedError)
|
2023-07-30 12:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestValidateGitDetailsNotUsingGit(t *testing.T) {
|
2023-11-15 14:03:36 +00:00
|
|
|
b := &bundle.Bundle{
|
2023-07-30 12:44:33 +00:00
|
|
|
Config: config.Root{
|
|
|
|
Bundle: config.Bundle{
|
|
|
|
Git: config.Git{
|
|
|
|
Branch: "main",
|
|
|
|
ActualBranch: "",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
m := ValidateGitDetails()
|
2024-03-25 14:18:47 +00:00
|
|
|
diags := bundle.Apply(context.Background(), b, m)
|
|
|
|
assert.NoError(t, diags.Error())
|
2023-07-30 12:44:33 +00:00
|
|
|
}
|