Skip to content

Commit 1300073

Browse files
authored
Simplify tests for path mutators (#2610)
## Changes Simplify tests for path mutators
1 parent bf06d55 commit 1300073

File tree

6 files changed

+29
-72
lines changed

6 files changed

+29
-72
lines changed

bundle/config/mutator/paths/app_paths_visitor_test.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"github.com/databricks/cli/bundle/config/resources"
88
"github.com/databricks/cli/libs/dyn"
99
assert "github.com/databricks/cli/libs/dyn/dynassert"
10-
"github.com/stretchr/testify/require"
1110
)
1211

1312
func TestAppPathsVisitor(t *testing.T) {
@@ -21,22 +20,10 @@ func TestAppPathsVisitor(t *testing.T) {
2120
},
2221
}
2322

24-
actual := visitAppPaths(t, root)
23+
actual := collectVisitedPaths(t, root, VisitAppPaths)
2524
expected := []dyn.Path{
2625
dyn.MustPathFromString("resources.apps.app0.source_code_path"),
2726
}
2827

2928
assert.ElementsMatch(t, expected, actual)
3029
}
31-
32-
func visitAppPaths(t *testing.T, root config.Root) []dyn.Path {
33-
var actual []dyn.Path
34-
err := root.Mutate(func(value dyn.Value) (dyn.Value, error) {
35-
return VisitAppPaths(value, func(p dyn.Path, mode TranslateMode, v dyn.Value) (dyn.Value, error) {
36-
actual = append(actual, p)
37-
return v, nil
38-
})
39-
})
40-
require.NoError(t, err)
41-
return actual
42-
}

bundle/config/mutator/paths/artifact_paths_visitor_test.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/databricks/cli/bundle/config"
77
"github.com/databricks/cli/libs/dyn"
88
"github.com/stretchr/testify/assert"
9-
"github.com/stretchr/testify/require"
109
)
1110

1211
func TestArtifactPathsVisitor(t *testing.T) {
@@ -18,22 +17,10 @@ func TestArtifactPathsVisitor(t *testing.T) {
1817
},
1918
}
2019

21-
actual := visitArtifactPaths(t, root)
20+
actual := collectVisitedPaths(t, root, VisitArtifactPaths)
2221
expected := []dyn.Path{
2322
dyn.MustPathFromString("artifacts.artifact0.path"),
2423
}
2524

2625
assert.ElementsMatch(t, expected, actual)
2726
}
28-
29-
func visitArtifactPaths(t *testing.T, root config.Root) []dyn.Path {
30-
var actual []dyn.Path
31-
err := root.Mutate(func(value dyn.Value) (dyn.Value, error) {
32-
return VisitArtifactPaths(value, func(p dyn.Path, mode TranslateMode, v dyn.Value) (dyn.Value, error) {
33-
actual = append(actual, p)
34-
return v, nil
35-
})
36-
})
37-
require.NoError(t, err)
38-
return actual
39-
}

bundle/config/mutator/paths/dashboard_paths_visitor_test.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"github.com/databricks/cli/bundle/config/resources"
88
"github.com/databricks/cli/libs/dyn"
99
assert "github.com/databricks/cli/libs/dyn/dynassert"
10-
"github.com/stretchr/testify/require"
1110
)
1211

1312
func TestVisitDashboardPaths(t *testing.T) {
@@ -21,22 +20,10 @@ func TestVisitDashboardPaths(t *testing.T) {
2120
},
2221
}
2322

24-
actual := visitDashboardPaths(t, root)
23+
actual := collectVisitedPaths(t, root, VisitDashboardPaths)
2524
expected := []dyn.Path{
2625
dyn.MustPathFromString("resources.dashboards.dashboard0.file_path"),
2726
}
2827

2928
assert.ElementsMatch(t, expected, actual)
3029
}
31-
32-
func visitDashboardPaths(t *testing.T, root config.Root) []dyn.Path {
33-
var actual []dyn.Path
34-
err := root.Mutate(func(value dyn.Value) (dyn.Value, error) {
35-
return VisitDashboardPaths(value, func(p dyn.Path, mode TranslateMode, v dyn.Value) (dyn.Value, error) {
36-
actual = append(actual, p)
37-
return v, nil
38-
})
39-
})
40-
require.NoError(t, err)
41-
return actual
42-
}

bundle/config/mutator/paths/job_paths_visitor_test.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
assert "github.com/databricks/cli/libs/dyn/dynassert"
1010
"github.com/databricks/databricks-sdk-go/service/compute"
1111
"github.com/databricks/databricks-sdk-go/service/jobs"
12-
"github.com/stretchr/testify/require"
1312
)
1413

1514
func TestVisitJobPaths(t *testing.T) {
@@ -73,7 +72,7 @@ func TestVisitJobPaths(t *testing.T) {
7372
},
7473
}
7574

76-
actual := visitJobPaths(t, root)
75+
actual := collectVisitedPaths(t, root, VisitJobPaths)
7776
expected := []dyn.Path{
7877
dyn.MustPathFromString("resources.jobs.job0.tasks[0].notebook_task.notebook_path"),
7978
dyn.MustPathFromString("resources.jobs.job0.tasks[1].spark_python_task.python_file"),
@@ -112,7 +111,7 @@ func TestVisitJobPaths_environments(t *testing.T) {
112111
},
113112
}
114113

115-
actual := visitJobPaths(t, root)
114+
actual := collectVisitedPaths(t, root, VisitJobPaths)
116115
expected := []dyn.Path{
117116
dyn.MustPathFromString("resources.jobs.job0.environments[0].spec.dependencies[0]"),
118117
dyn.MustPathFromString("resources.jobs.job0.environments[0].spec.dependencies[1]"),
@@ -147,22 +146,10 @@ func TestVisitJobPaths_foreach(t *testing.T) {
147146
},
148147
}
149148

150-
actual := visitJobPaths(t, root)
149+
actual := collectVisitedPaths(t, root, VisitJobPaths)
151150
expected := []dyn.Path{
152151
dyn.MustPathFromString("resources.jobs.job0.tasks[0].for_each_task.task.notebook_task.notebook_path"),
153152
}
154153

155154
assert.ElementsMatch(t, expected, actual)
156155
}
157-
158-
func visitJobPaths(t *testing.T, root config.Root) []dyn.Path {
159-
var actual []dyn.Path
160-
err := root.Mutate(func(value dyn.Value) (dyn.Value, error) {
161-
return VisitJobPaths(value, func(p dyn.Path, mode TranslateMode, v dyn.Value) (dyn.Value, error) {
162-
actual = append(actual, p)
163-
return v, nil
164-
})
165-
})
166-
require.NoError(t, err)
167-
return actual
168-
}

bundle/config/mutator/paths/pipeline_paths_visitor_test.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/databricks/cli/libs/dyn"
99
assert "github.com/databricks/cli/libs/dyn/dynassert"
1010
"github.com/databricks/databricks-sdk-go/service/pipelines"
11-
"github.com/stretchr/testify/require"
1211
)
1312

1413
func TestVisitPipelinePaths(t *testing.T) {
@@ -35,23 +34,11 @@ func TestVisitPipelinePaths(t *testing.T) {
3534
},
3635
}
3736

38-
actual := visitPipelinePaths(t, root)
37+
actual := collectVisitedPaths(t, root, VisitPipelinePaths)
3938
expected := []dyn.Path{
4039
dyn.MustPathFromString("resources.pipelines.pipeline0.libraries[0].file.path"),
4140
dyn.MustPathFromString("resources.pipelines.pipeline0.libraries[1].notebook.path"),
4241
}
4342

4443
assert.ElementsMatch(t, expected, actual)
4544
}
46-
47-
func visitPipelinePaths(t *testing.T, root config.Root) []dyn.Path {
48-
var actual []dyn.Path
49-
err := root.Mutate(func(value dyn.Value) (dyn.Value, error) {
50-
return VisitPipelinePaths(value, func(p dyn.Path, mode TranslateMode, v dyn.Value) (dyn.Value, error) {
51-
actual = append(actual, p)
52-
return v, nil
53-
})
54-
})
55-
require.NoError(t, err)
56-
return actual
57-
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package paths
2+
3+
import (
4+
"testing"
5+
6+
"github.com/databricks/cli/bundle/config"
7+
"github.com/databricks/cli/libs/dyn"
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
// collectVisitedPaths is a helper function that collects all visited paths for testing
12+
func collectVisitedPaths(t *testing.T, root config.Root, visitFn func(value dyn.Value, fn VisitFunc) (dyn.Value, error)) []dyn.Path {
13+
var actual []dyn.Path
14+
err := root.Mutate(func(value dyn.Value) (dyn.Value, error) {
15+
return visitFn(value, func(p dyn.Path, mode TranslateMode, v dyn.Value) (dyn.Value, error) {
16+
actual = append(actual, p)
17+
return v, nil
18+
})
19+
})
20+
require.NoError(t, err)
21+
return actual
22+
}

0 commit comments

Comments
 (0)