Skip to content

Commit f088413

Browse files
committed
ignore fields that current mismatch
1 parent ecf1137 commit f088413

File tree

4 files changed

+53
-19
lines changed

4 files changed

+53
-19
lines changed

integration/bundle/init_default_python_test.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,16 @@ func testDefaultPython(t *testing.T, pythonVersion string) {
122122
testcli.RequireSuccessfulRun(t, ctx, "bundle", "destroy", "--auto-approve")
123123
})
124124

125-
testcli.RequireOutputJQ(t, ctx, []string{"bundle", "summary", "--output", "json"}, "testdata/default_python/bundle_summary.txt", []string{"/hello"})
125+
ignoredFields := []string{
126+
"/resources/jobs/project_name_$UNIQUE_PRJ_job/email_notifications",
127+
"/resources/jobs/project_name_$UNIQUE_PRJ_job/job_clusters/0/new_cluster/node_type_id",
128+
"/resources/jobs/project_name_$UNIQUE_PRJ_job/url",
129+
"/resources/pipelines/project_name_$UNIQUE_PRJ_pipeline/catalog",
130+
"/resources/pipelines/project_name_$UNIQUE_PRJ_pipeline/url",
131+
"/workspace/current_user/externalId",
132+
"/workspace/current_user/groups",
133+
"/workspace/current_user/name/familyName",
134+
}
135+
136+
testcli.RequireOutputJQ(t, ctx, []string{"bundle", "summary", "--output", "json"}, "testdata/default_python/bundle_summary.txt", ignoredFields)
126137
}

internal/testcli/golden.go

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ func assertEqualTexts(t testutil.TestingT, filename1, filename2, expected, out s
5555
}
5656
}
5757

58+
func logDiff(t testutil.TestingT, filename1, filename2, expected, out string) {
59+
diff := testutil.Diff(filename1, filename2, expected, out)
60+
t.Logf("Diff:\n" + diff)
61+
}
62+
5863
func RequireOutput(t testutil.TestingT, ctx context.Context, args []string, expectedFilename string) {
5964
_, filename, _, _ := runtime.Caller(1)
6065
dir := filepath.Dir(filename)
@@ -83,13 +88,26 @@ func RequireOutputJQ(t testutil.TestingT, ctx context.Context, args []string, ex
8388

8489
if out != expected {
8590
patch, err := jsondiff.CompareJSON([]byte(expected), []byte(out))
91+
actual := fmt.Sprintf("Output from %v", args)
8692
if err != nil {
8793
t.Logf("CompareJSON error for %s vs %s: %s (fallback to textual comparison)", args, expectedFilename, err)
88-
actual := fmt.Sprintf("Output from %v", args)
8994
assertEqualTexts(t, expectedFilename, actual, expected, out)
9095
} else {
96+
logDiff(t, expectedFilename, actual, expected, out)
97+
ignoredDiffs := []string{}
98+
erroredDiffs := []string{}
9199
for _, op := range patch {
92-
t.Errorf("PATCH %s %s: %s", args, expectedFilename, op)
100+
if matchesPrefixes(ignorePaths, op.Path) {
101+
ignoredDiffs = append(ignoredDiffs, fmt.Sprintf("%7s %s %v", op.Type, op.Path, op.Value))
102+
} else {
103+
erroredDiffs = append(erroredDiffs, fmt.Sprintf("%7s %s %v", op.Type, op.Path, op.Value))
104+
}
105+
}
106+
if len(ignoredDiffs) > 0 {
107+
t.Logf("Ignored differences between %s and %s:\n ==> %s", expectedFilename, args, strings.Join(ignoredDiffs, "\n ==> "))
108+
}
109+
if len(erroredDiffs) > 0 {
110+
t.Errorf("Unexpected differences between %s and %s:\n ==> %s", expectedFilename, args, strings.Join(erroredDiffs, "\n ==> "))
93111
}
94112
}
95113

@@ -99,6 +117,18 @@ func RequireOutputJQ(t testutil.TestingT, ctx context.Context, args []string, ex
99117
}
100118
}
101119

120+
func matchesPrefixes(prefixes []string, path string) bool {
121+
for _, p := range prefixes {
122+
if p == path {
123+
return true
124+
}
125+
if strings.HasPrefix(path, p+"/") {
126+
return true
127+
}
128+
}
129+
return false
130+
}
131+
102132
var (
103133
uuidRegex = regexp.MustCompile(`[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}`)
104134
numIdRegex = regexp.MustCompile(`[0-9]{3,}`)
@@ -158,18 +188,6 @@ func setKV(replacements *orderedmap.OrderedMap[string, string], key, value strin
158188
replacements.Set(key, value)
159189
}
160190

161-
/*
162-
func setMissing(replacements *orderedmap.OrderedMap[string, string], key, value string) {
163-
if key == "" || value == "" {
164-
return
165-
}
166-
_, exists := replacements.Get(key)
167-
if !exists {
168-
replacements.Set(key, value)
169-
}
170-
}
171-
*/
172-
173191
func PrepareReplacements(t testutil.TestingT, replacements *orderedmap.OrderedMap[string, string], w *databricks.WorkspaceClient) {
174192
// in some clouds (gcp) w.Config.Host includes "https://" prefix in others it's really just a host (azure)
175193
host := strings.TrimPrefix(strings.TrimPrefix(w.Config.Host, "http://"), "https://")
@@ -233,10 +251,6 @@ func PrepareReplacementsUser(t testutil.TestingT, replacements *orderedmap.Order
233251
setKV(replacements, val.Value, fmt.Sprintf("$USER.Roles[%d]", ind))
234252
}
235253

236-
for key, val := range replacements.AllFromFront() {
237-
fmt.Printf("REPL %v=%v\n", key, val)
238-
}
239-
240254
// Schemas []UserSchema `json:"schemas,omitempty"`
241255
}
242256

internal/testcli/golden_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,10 @@ func TestSort(t *testing.T) {
1111
stableSortReverseLength(input)
1212
assert.Equal(t, []string{"bc", "cd", "a"}, input)
1313
}
14+
15+
func TestMatchesPrefixes(t *testing.T) {
16+
assert.False(t, matchesPrefixes([]string{}, ""))
17+
assert.False(t, matchesPrefixes([]string{"/hello", "/hello/world"}, ""))
18+
assert.True(t, matchesPrefixes([]string{"/hello", "/a/b"}, "/hello"))
19+
assert.True(t, matchesPrefixes([]string{"/hello", "/a/b"}, "/a/b/c"))
20+
}

libs/python/detect.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ func DetectExecutable(ctx context.Context) (string, error) {
3737
if err != nil && !errors.Is(err, exec.ErrNotFound) {
3838
return "", err
3939
}
40+
4041
if out != "" {
4142
return out, nil
4243
}
44+
4345
// otherwise, detect all interpreters and pick the least that satisfies
4446
// minimal version requirements
4547
all, err := DetectInterpreters(ctx)

0 commit comments

Comments
 (0)