mirror of https://github.com/databricks/cli.git
fix tests
This commit is contained in:
parent
23169cdd87
commit
fa3f4cde77
|
@ -1,4 +1,4 @@
|
||||||
package mutator_test
|
package mutator
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -8,54 +8,67 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCheckMatch(t *testing.T, force bool) {
|
func TestCheckMatch(t *testing.T) {
|
||||||
type test struct {
|
type test struct {
|
||||||
Fetched string
|
Fetched string
|
||||||
Configured string
|
ConfiguredBefore string
|
||||||
|
ConfiguredAfter string
|
||||||
}
|
}
|
||||||
|
|
||||||
tests := []test{
|
tests := []test{
|
||||||
{
|
{
|
||||||
Fetched: "main",
|
Fetched: "main",
|
||||||
Configured: "main",
|
ConfiguredBefore: "main",
|
||||||
|
ConfiguredAfter: "main",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Fetched: "main",
|
Fetched: "main",
|
||||||
Configured: "",
|
ConfiguredBefore: "",
|
||||||
|
ConfiguredAfter: "main",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Fetched: "",
|
Fetched: "",
|
||||||
Configured: "main",
|
ConfiguredBefore: "main",
|
||||||
|
ConfiguredAfter: "main",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Fetched: "",
|
Fetched: "",
|
||||||
Configured: "main",
|
ConfiguredBefore: "main",
|
||||||
|
ConfiguredAfter: "main",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for test := range tests {
|
for _, test := range tests {
|
||||||
name := "CheckMatch " + test.Fetched + " " + test.Configured
|
name := "CheckMatch " + test.Fetched + " " + test.ConfiguredBefore + " " + test.ConfiguredAfter
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
diags := checkMatch("", test.Fetched, testConfigured, false)
|
configValue := test.ConfiguredBefore
|
||||||
|
diags := checkMatch("", test.Fetched, &configValue, false)
|
||||||
assert.Nil(t, diags)
|
assert.Nil(t, diags)
|
||||||
|
assert.Equal(t, test.ConfiguredAfter, configValue)
|
||||||
})
|
})
|
||||||
t.Run(name+" force", func(t *testing.T) {
|
t.Run(name+" force", func(t *testing.T) {
|
||||||
diags := checkMatch("", test.Fetched, testConfigured, true)
|
configValue := test.ConfiguredBefore
|
||||||
|
diags := checkMatch("", test.Fetched, &configValue, true)
|
||||||
assert.Nil(t, diags)
|
assert.Nil(t, diags)
|
||||||
|
assert.Equal(t, test.ConfiguredAfter, configValue)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCheckWarning(t *testing.T, force bool) {
|
func TestCheckWarning(t *testing.T) {
|
||||||
diags := checkMatch("Git branch", "feature", "main", true)
|
configValue := "main"
|
||||||
|
diags := checkMatch("Git branch", "feature", &configValue, true)
|
||||||
require.Len(t, diags, 1)
|
require.Len(t, diags, 1)
|
||||||
assert.Equal(t, diags[0].Severity, diag.Warning)
|
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")
|
assert.Equal(t, diags[0].Summary, "not on the right Git branch:\n expected according to configuration: main\n actual: feature")
|
||||||
|
assert.Equal(t, "main", configValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCheckError(t *testing.T, force bool) {
|
func TestCheckError(t *testing.T) {
|
||||||
diags := checkMatch("Git branch", "feature", "main", false)
|
configValue := "main"
|
||||||
|
diags := checkMatch("Git branch", "feature", &configValue, false)
|
||||||
require.Len(t, diags, 1)
|
require.Len(t, diags, 1)
|
||||||
assert.Equal(t, diags[0].Severity, diag.Error)
|
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")
|
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")
|
||||||
|
assert.Equal(t, "main", configValue)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue