databricks-cli/bundle/config/mutator/load_git_details_test.go

70 lines
1.9 KiB
Go
Raw Normal View History

2024-12-09 15:21:12 +00:00
package mutator
import (
"testing"
"github.com/databricks/cli/libs/diag"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
2024-12-09 15:21:12 +00:00
func TestCheckMatch(t *testing.T) {
type test struct {
2024-12-09 15:21:12 +00:00
Fetched string
ConfiguredBefore string
ConfiguredAfter string
}
tests := []test{
{
2024-12-09 15:21:12 +00:00
Fetched: "main",
ConfiguredBefore: "main",
ConfiguredAfter: "main",
},
{
2024-12-09 15:21:12 +00:00
Fetched: "main",
ConfiguredBefore: "",
ConfiguredAfter: "main",
},
{
2024-12-09 15:21:12 +00:00
Fetched: "",
ConfiguredBefore: "main",
ConfiguredAfter: "main",
},
}
2024-12-09 15:21:12 +00:00
for _, test := range tests {
name := "CheckMatch " + test.Fetched + " " + test.ConfiguredBefore + " " + test.ConfiguredAfter
t.Run(name, func(t *testing.T) {
2024-12-09 15:21:12 +00:00
configValue := test.ConfiguredBefore
diags := checkMatch("", test.Fetched, &configValue, false)
assert.Nil(t, diags)
2024-12-09 15:21:12 +00:00
assert.Equal(t, test.ConfiguredAfter, configValue)
})
t.Run(name+" force", func(t *testing.T) {
2024-12-09 15:21:12 +00:00
configValue := test.ConfiguredBefore
diags := checkMatch("", test.Fetched, &configValue, true)
assert.Nil(t, diags)
2024-12-09 15:21:12 +00:00
assert.Equal(t, test.ConfiguredAfter, configValue)
})
}
}
2024-12-09 15:21:12 +00:00
func TestCheckWarning(t *testing.T) {
configValue := "main"
diags := checkMatch("Git branch", "feature", &configValue, true)
require.Len(t, diags, 1)
assert.Equal(t, diags[0].Severity, diag.Warning)
assert.Equal(t, diags[0].Summary, "not on the right Git branch:\n expected according to configuration: main\n actual: feature")
2024-12-09 15:21:12 +00:00
assert.Equal(t, "main", configValue)
}
2024-12-09 15:21:12 +00:00
func TestCheckError(t *testing.T) {
configValue := "main"
diags := checkMatch("Git branch", "feature", &configValue, false)
require.Len(t, diags, 1)
assert.Equal(t, diags[0].Severity, diag.Error)
assert.Equal(t, diags[0].Summary, "not on the right Git branch:\n expected according to configuration: main\n actual: feature\nuse --force to override")
2024-12-09 15:21:12 +00:00
assert.Equal(t, "main", configValue)
}