Skip to content

Commit 489d6fa

Browse files
authored
Replace direct calls with bundle.Apply (#990)
## Changes Some test call sites called directly into the mutator's `Apply` function instead of `bundle.Apply`. Calling into `bundle.Apply` is preferred because that's where we can run pre/post logic common across all mutators. ## Tests Pass.
1 parent d80c35f commit 489d6fa

17 files changed

+65
-65
lines changed

bundle/config/mutator/default_target_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
func TestDefaultTarget(t *testing.T) {
1515
b := &bundle.Bundle{}
16-
err := mutator.DefineDefaultTarget().Apply(context.Background(), b)
16+
err := bundle.Apply(context.Background(), b, mutator.DefineDefaultTarget())
1717
require.NoError(t, err)
1818
env, ok := b.Config.Targets["default"]
1919
assert.True(t, ok)
@@ -28,7 +28,7 @@ func TestDefaultTargetAlreadySpecified(t *testing.T) {
2828
},
2929
},
3030
}
31-
err := mutator.DefineDefaultTarget().Apply(context.Background(), b)
31+
err := bundle.Apply(context.Background(), b, mutator.DefineDefaultTarget())
3232
require.NoError(t, err)
3333
_, ok := b.Config.Targets["default"]
3434
assert.False(t, ok)

bundle/config/mutator/default_workspace_paths_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestDefineDefaultWorkspacePaths(t *testing.T) {
1919
},
2020
},
2121
}
22-
err := mutator.DefineDefaultWorkspacePaths().Apply(context.Background(), b)
22+
err := bundle.Apply(context.Background(), b, mutator.DefineDefaultWorkspacePaths())
2323
require.NoError(t, err)
2424
assert.Equal(t, "/files", b.Config.Workspace.FilePath)
2525
assert.Equal(t, "/artifacts", b.Config.Workspace.ArtifactPath)
@@ -37,7 +37,7 @@ func TestDefineDefaultWorkspacePathsAlreadySet(t *testing.T) {
3737
},
3838
},
3939
}
40-
err := mutator.DefineDefaultWorkspacePaths().Apply(context.Background(), b)
40+
err := bundle.Apply(context.Background(), b, mutator.DefineDefaultWorkspacePaths())
4141
require.NoError(t, err)
4242
assert.Equal(t, "/foo/bar", b.Config.Workspace.FilePath)
4343
assert.Equal(t, "/foo/bar", b.Config.Workspace.ArtifactPath)

bundle/config/mutator/default_workspace_root_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestDefaultWorkspaceRoot(t *testing.T) {
2020
},
2121
},
2222
}
23-
err := mutator.DefineDefaultWorkspaceRoot().Apply(context.Background(), b)
23+
err := bundle.Apply(context.Background(), b, mutator.DefineDefaultWorkspaceRoot())
2424
require.NoError(t, err)
2525
assert.Equal(t, "~/.bundle/name/environment", b.Config.Workspace.RootPath)
2626
}

bundle/config/mutator/expand_workspace_root_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestExpandWorkspaceRoot(t *testing.T) {
2525
},
2626
},
2727
}
28-
err := mutator.ExpandWorkspaceRoot().Apply(context.Background(), b)
28+
err := bundle.Apply(context.Background(), b, mutator.ExpandWorkspaceRoot())
2929
require.NoError(t, err)
3030
assert.Equal(t, "/Users/jane@doe.com/foo", b.Config.Workspace.RootPath)
3131
}
@@ -43,7 +43,7 @@ func TestExpandWorkspaceRootDoesNothing(t *testing.T) {
4343
},
4444
},
4545
}
46-
err := mutator.ExpandWorkspaceRoot().Apply(context.Background(), b)
46+
err := bundle.Apply(context.Background(), b, mutator.ExpandWorkspaceRoot())
4747
require.NoError(t, err)
4848
assert.Equal(t, "/Users/charly@doe.com/foo", b.Config.Workspace.RootPath)
4949
}
@@ -60,7 +60,7 @@ func TestExpandWorkspaceRootWithoutRoot(t *testing.T) {
6060
},
6161
},
6262
}
63-
err := mutator.ExpandWorkspaceRoot().Apply(context.Background(), b)
63+
err := bundle.Apply(context.Background(), b, mutator.ExpandWorkspaceRoot())
6464
require.Error(t, err)
6565
}
6666

@@ -72,6 +72,6 @@ func TestExpandWorkspaceRootWithoutCurrentUser(t *testing.T) {
7272
},
7373
},
7474
}
75-
err := mutator.ExpandWorkspaceRoot().Apply(context.Background(), b)
75+
err := bundle.Apply(context.Background(), b, mutator.ExpandWorkspaceRoot())
7676
require.Error(t, err)
7777
}

bundle/config/mutator/override_compute_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestOverrideDevelopment(t *testing.T) {
4747
}
4848

4949
m := mutator.OverrideCompute()
50-
err := m.Apply(context.Background(), b)
50+
err := bundle.Apply(context.Background(), b, m)
5151
require.NoError(t, err)
5252
assert.Nil(t, b.Config.Resources.Jobs["job1"].Tasks[0].NewCluster)
5353
assert.Equal(t, "newClusterID", b.Config.Resources.Jobs["job1"].Tasks[0].ExistingClusterId)
@@ -83,7 +83,7 @@ func TestOverrideDevelopmentEnv(t *testing.T) {
8383
}
8484

8585
m := mutator.OverrideCompute()
86-
err := m.Apply(context.Background(), b)
86+
err := bundle.Apply(context.Background(), b, m)
8787
require.NoError(t, err)
8888
assert.Equal(t, "cluster2", b.Config.Resources.Jobs["job1"].Tasks[1].ExistingClusterId)
8989
}
@@ -108,7 +108,7 @@ func TestOverridePipelineTask(t *testing.T) {
108108
}
109109

110110
m := mutator.OverrideCompute()
111-
err := m.Apply(context.Background(), b)
111+
err := bundle.Apply(context.Background(), b, m)
112112
require.NoError(t, err)
113113
assert.Empty(t, b.Config.Resources.Jobs["job1"].Tasks[0].ExistingClusterId)
114114
}
@@ -138,7 +138,7 @@ func TestOverrideProduction(t *testing.T) {
138138
}
139139

140140
m := mutator.OverrideCompute()
141-
err := m.Apply(context.Background(), b)
141+
err := bundle.Apply(context.Background(), b, m)
142142
require.Error(t, err)
143143
}
144144

@@ -165,6 +165,6 @@ func TestOverrideProductionEnv(t *testing.T) {
165165
}
166166

167167
m := mutator.OverrideCompute()
168-
err := m.Apply(context.Background(), b)
168+
err := bundle.Apply(context.Background(), b, m)
169169
require.NoError(t, err)
170170
}

bundle/config/mutator/process_include_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestProcessInclude(t *testing.T) {
3232
f.Close()
3333

3434
assert.Equal(t, "foo", b.Config.Workspace.Host)
35-
err = mutator.ProcessInclude(fullPath, relPath).Apply(context.Background(), b)
35+
err = bundle.Apply(context.Background(), b, mutator.ProcessInclude(fullPath, relPath))
3636
require.NoError(t, err)
3737
assert.Equal(t, "bar", b.Config.Workspace.Host)
3838
}

bundle/config/mutator/process_root_includes_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestProcessRootIncludesEmpty(t *testing.T) {
2929
Path: ".",
3030
},
3131
}
32-
err := mutator.ProcessRootIncludes().Apply(context.Background(), b)
32+
err := bundle.Apply(context.Background(), b, mutator.ProcessRootIncludes())
3333
require.NoError(t, err)
3434
}
3535

@@ -49,7 +49,7 @@ func TestProcessRootIncludesAbs(t *testing.T) {
4949
},
5050
},
5151
}
52-
err := mutator.ProcessRootIncludes().Apply(context.Background(), b)
52+
err := bundle.Apply(context.Background(), b, mutator.ProcessRootIncludes())
5353
require.Error(t, err)
5454
assert.Contains(t, err.Error(), "must be relative paths")
5555
}
@@ -68,7 +68,7 @@ func TestProcessRootIncludesSingleGlob(t *testing.T) {
6868
touch(t, b.Config.Path, "a.yml")
6969
touch(t, b.Config.Path, "b.yml")
7070

71-
err := mutator.ProcessRootIncludes().Apply(context.Background(), b)
71+
err := bundle.Apply(context.Background(), b, mutator.ProcessRootIncludes())
7272
require.NoError(t, err)
7373

7474
assert.Equal(t, []string{"a.yml", "b.yml"}, b.Config.Include)
@@ -88,7 +88,7 @@ func TestProcessRootIncludesMultiGlob(t *testing.T) {
8888
touch(t, b.Config.Path, "a1.yml")
8989
touch(t, b.Config.Path, "b1.yml")
9090

91-
err := mutator.ProcessRootIncludes().Apply(context.Background(), b)
91+
err := bundle.Apply(context.Background(), b, mutator.ProcessRootIncludes())
9292
require.NoError(t, err)
9393

9494
assert.Equal(t, []string{"a1.yml", "b1.yml"}, b.Config.Include)
@@ -107,7 +107,7 @@ func TestProcessRootIncludesRemoveDups(t *testing.T) {
107107

108108
touch(t, b.Config.Path, "a.yml")
109109

110-
err := mutator.ProcessRootIncludes().Apply(context.Background(), b)
110+
err := bundle.Apply(context.Background(), b, mutator.ProcessRootIncludes())
111111
require.NoError(t, err)
112112
assert.Equal(t, []string{"a.yml"}, b.Config.Include)
113113
}
@@ -121,7 +121,7 @@ func TestProcessRootIncludesNotExists(t *testing.T) {
121121
},
122122
},
123123
}
124-
err := mutator.ProcessRootIncludes().Apply(context.Background(), b)
124+
err := bundle.Apply(context.Background(), b, mutator.ProcessRootIncludes())
125125
require.Error(t, err)
126126
assert.Contains(t, err.Error(), "notexist.yml defined in 'include' section does not match any files")
127127
}
@@ -138,7 +138,7 @@ func TestProcessRootIncludesExtrasFromEnvVar(t *testing.T) {
138138
},
139139
}
140140

141-
err := mutator.ProcessRootIncludes().Apply(context.Background(), b)
141+
err := bundle.Apply(context.Background(), b, mutator.ProcessRootIncludes())
142142
require.NoError(t, err)
143143
assert.Contains(t, b.Config.Include, testYamlName)
144144
}
@@ -161,7 +161,7 @@ func TestProcessRootIncludesDedupExtrasFromEnvVar(t *testing.T) {
161161
},
162162
}
163163

164-
err := mutator.ProcessRootIncludes().Apply(context.Background(), b)
164+
err := bundle.Apply(context.Background(), b, mutator.ProcessRootIncludes())
165165
require.NoError(t, err)
166166
assert.Equal(t, []string{testYamlName}, b.Config.Include)
167167
}

bundle/config/mutator/process_target_mode_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func TestProcessTargetModeDevelopment(t *testing.T) {
9292
b := mockBundle(config.Development)
9393

9494
m := ProcessTargetMode()
95-
err := m.Apply(context.Background(), b)
95+
err := bundle.Apply(context.Background(), b, m)
9696
require.NoError(t, err)
9797

9898
// Job 1
@@ -135,7 +135,7 @@ func TestProcessTargetModeDevelopmentTagNormalizationForAws(t *testing.T) {
135135
})
136136

137137
b.Config.Workspace.CurrentUser.ShortName = "Héllö wörld?!"
138-
err := ProcessTargetMode().Apply(context.Background(), b)
138+
err := bundle.Apply(context.Background(), b, ProcessTargetMode())
139139
require.NoError(t, err)
140140

141141
// Assert that tag normalization took place.
@@ -149,7 +149,7 @@ func TestProcessTargetModeDevelopmentTagNormalizationForAzure(t *testing.T) {
149149
})
150150

151151
b.Config.Workspace.CurrentUser.ShortName = "Héllö wörld?!"
152-
err := ProcessTargetMode().Apply(context.Background(), b)
152+
err := bundle.Apply(context.Background(), b, ProcessTargetMode())
153153
require.NoError(t, err)
154154

155155
// Assert that tag normalization took place (Azure allows more characters than AWS).
@@ -163,7 +163,7 @@ func TestProcessTargetModeDevelopmentTagNormalizationForGcp(t *testing.T) {
163163
})
164164

165165
b.Config.Workspace.CurrentUser.ShortName = "Héllö wörld?!"
166-
err := ProcessTargetMode().Apply(context.Background(), b)
166+
err := bundle.Apply(context.Background(), b, ProcessTargetMode())
167167
require.NoError(t, err)
168168

169169
// Assert that tag normalization took place.
@@ -174,7 +174,7 @@ func TestProcessTargetModeDefault(t *testing.T) {
174174
b := mockBundle("")
175175

176176
m := ProcessTargetMode()
177-
err := m.Apply(context.Background(), b)
177+
err := bundle.Apply(context.Background(), b, m)
178178
require.NoError(t, err)
179179
assert.Equal(t, "job1", b.Config.Resources.Jobs["job1"].Name)
180180
assert.Equal(t, "pipeline1", b.Config.Resources.Pipelines["pipeline1"].Name)
@@ -257,7 +257,7 @@ func TestAllResourcesRenamed(t *testing.T) {
257257
resources := reflect.ValueOf(b.Config.Resources)
258258

259259
m := ProcessTargetMode()
260-
err := m.Apply(context.Background(), b)
260+
err := bundle.Apply(context.Background(), b, m)
261261
require.NoError(t, err)
262262

263263
for i := 0; i < resources.NumField(); i++ {

bundle/config/mutator/select_default_target.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (m *selectDefaultTarget) Apply(ctx context.Context, b *bundle.Bundle) error
2828
// One target means there's only one default.
2929
names := maps.Keys(b.Config.Targets)
3030
if len(names) == 1 {
31-
return SelectTarget(names[0]).Apply(ctx, b)
31+
return bundle.Apply(ctx, b, SelectTarget(names[0]))
3232
}
3333

3434
// Multiple targets means we look for the `default` flag.
@@ -50,5 +50,5 @@ func (m *selectDefaultTarget) Apply(ctx context.Context, b *bundle.Bundle) error
5050
}
5151

5252
// One default remaining.
53-
return SelectTarget(defaults[0]).Apply(ctx, b)
53+
return bundle.Apply(ctx, b, SelectTarget(defaults[0]))
5454
}

bundle/config/mutator/select_default_target_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func TestSelectDefaultTargetNoTargets(t *testing.T) {
1616
Targets: map[string]*config.Target{},
1717
},
1818
}
19-
err := mutator.SelectDefaultTarget().Apply(context.Background(), b)
19+
err := bundle.Apply(context.Background(), b, mutator.SelectDefaultTarget())
2020
assert.ErrorContains(t, err, "no targets defined")
2121
}
2222

@@ -28,7 +28,7 @@ func TestSelectDefaultTargetSingleTargets(t *testing.T) {
2828
},
2929
},
3030
}
31-
err := mutator.SelectDefaultTarget().Apply(context.Background(), b)
31+
err := bundle.Apply(context.Background(), b, mutator.SelectDefaultTarget())
3232
assert.NoError(t, err)
3333
assert.Equal(t, "foo", b.Config.Bundle.Target)
3434
}
@@ -43,7 +43,7 @@ func TestSelectDefaultTargetNoDefaults(t *testing.T) {
4343
},
4444
},
4545
}
46-
err := mutator.SelectDefaultTarget().Apply(context.Background(), b)
46+
err := bundle.Apply(context.Background(), b, mutator.SelectDefaultTarget())
4747
assert.ErrorContains(t, err, "please specify target")
4848
}
4949

@@ -56,7 +56,7 @@ func TestSelectDefaultTargetNoDefaultsWithNil(t *testing.T) {
5656
},
5757
},
5858
}
59-
err := mutator.SelectDefaultTarget().Apply(context.Background(), b)
59+
err := bundle.Apply(context.Background(), b, mutator.SelectDefaultTarget())
6060
assert.ErrorContains(t, err, "please specify target")
6161
}
6262

@@ -70,7 +70,7 @@ func TestSelectDefaultTargetMultipleDefaults(t *testing.T) {
7070
},
7171
},
7272
}
73-
err := mutator.SelectDefaultTarget().Apply(context.Background(), b)
73+
err := bundle.Apply(context.Background(), b, mutator.SelectDefaultTarget())
7474
assert.ErrorContains(t, err, "multiple targets are marked as default")
7575
}
7676

@@ -84,7 +84,7 @@ func TestSelectDefaultTargetSingleDefault(t *testing.T) {
8484
},
8585
},
8686
}
87-
err := mutator.SelectDefaultTarget().Apply(context.Background(), b)
87+
err := bundle.Apply(context.Background(), b, mutator.SelectDefaultTarget())
8888
assert.NoError(t, err)
8989
assert.Equal(t, "bar", b.Config.Bundle.Target)
9090
}

0 commit comments

Comments
 (0)