mirror of https://github.com/databricks/cli.git
fix comparison on Windows: ignore slash difference, ignore terraform path
This commit is contained in:
parent
004d0df9fe
commit
b972bcd50a
|
@ -102,6 +102,7 @@ func testDefaultPython(t *testing.T, pythonVersion string) {
|
||||||
})
|
})
|
||||||
|
|
||||||
ignoredFields := []string{
|
ignoredFields := []string{
|
||||||
|
"/bundle/terraform/exec_path",
|
||||||
"/resources/jobs/project_name_$UNIQUE_PRJ_job/email_notifications",
|
"/resources/jobs/project_name_$UNIQUE_PRJ_job/email_notifications",
|
||||||
"/resources/jobs/project_name_$UNIQUE_PRJ_job/job_clusters/0/new_cluster/node_type_id",
|
"/resources/jobs/project_name_$UNIQUE_PRJ_job/job_clusters/0/new_cluster/node_type_id",
|
||||||
"/resources/jobs/project_name_$UNIQUE_PRJ_job/url",
|
"/resources/jobs/project_name_$UNIQUE_PRJ_job/url",
|
||||||
|
|
|
@ -37,17 +37,17 @@ func AssertEqualJQ(t *testing.T, expectedName, outName, expected, out string, ig
|
||||||
} else {
|
} else {
|
||||||
diff := UnifiedDiff(expectedName, outName, expected, out)
|
diff := UnifiedDiff(expectedName, outName, expected, out)
|
||||||
t.Logf("Diff:\n%s", diff)
|
t.Logf("Diff:\n%s", diff)
|
||||||
ignoredDiffs := []string{}
|
allowedDiffs := []string{}
|
||||||
erroredDiffs := []string{}
|
erroredDiffs := []string{}
|
||||||
for _, op := range patch {
|
for _, op := range patch {
|
||||||
if matchesPrefixes(ignorePaths, op.Path) {
|
if allowDifference(ignorePaths, op) {
|
||||||
ignoredDiffs = append(ignoredDiffs, fmt.Sprintf("%7s %s %v", op.Type, op.Path, op.Value))
|
allowedDiffs = append(allowedDiffs, fmt.Sprintf("%7s %s %v old=%v", op.Type, op.Path, op.Value, op.OldValue))
|
||||||
} else {
|
} else {
|
||||||
erroredDiffs = append(erroredDiffs, fmt.Sprintf("%7s %s %v", op.Type, op.Path, op.Value))
|
erroredDiffs = append(erroredDiffs, fmt.Sprintf("%7s %s %v old=%v", op.Type, op.Path, op.Value, op.OldValue))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(ignoredDiffs) > 0 {
|
if len(allowedDiffs) > 0 {
|
||||||
t.Logf("Ignored differences between %s and %s:\n ==> %s", expectedName, outName, strings.Join(ignoredDiffs, "\n ==> "))
|
t.Logf("Allowed differences between %s and %s:\n ==> %s", expectedName, outName, strings.Join(allowedDiffs, "\n ==> "))
|
||||||
}
|
}
|
||||||
if len(erroredDiffs) > 0 {
|
if len(erroredDiffs) > 0 {
|
||||||
t.Errorf("Unexpected differences between %s and %s:\n ==> %s", expectedName, outName, strings.Join(erroredDiffs, "\n ==> "))
|
t.Errorf("Unexpected differences between %s and %s:\n ==> %s", expectedName, outName, strings.Join(erroredDiffs, "\n ==> "))
|
||||||
|
@ -55,6 +55,29 @@ func AssertEqualJQ(t *testing.T, expectedName, outName, expected, out string, ig
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func allowDifference(ignorePaths []string, op jsondiff.Operation) bool {
|
||||||
|
if matchesPrefixes(ignorePaths, op.Path) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if op.Type == "replace" && almostSameStrings(op.OldValue, op.Value) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// compare strings and ignore forward vs backward slashes
|
||||||
|
func almostSameStrings(v1, v2 any) bool {
|
||||||
|
s1, ok := v1.(string)
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
s2, ok := v2.(string)
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return strings.ReplaceAll(s1, "\\", "/") == strings.ReplaceAll(s2, "\\", "/")
|
||||||
|
}
|
||||||
|
|
||||||
func matchesPrefixes(prefixes []string, path string) bool {
|
func matchesPrefixes(prefixes []string, path string) bool {
|
||||||
for _, p := range prefixes {
|
for _, p := range prefixes {
|
||||||
if p == path {
|
if p == path {
|
||||||
|
|
Loading…
Reference in New Issue