Skip to content

Commit 3f19375

Browse files
committed
Add test to cover plugins overriding
Signed-off-by: Angel Misevski <[email protected]>
1 parent 45d962c commit 3f19375

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

pkg/utils/overriding/overriding_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,36 @@ func TestMerging(t *testing.T) {
304304
})
305305
}
306306

307+
func TestPluginOverrides(t *testing.T) {
308+
originalFile := "test-fixtures/patches/override-just-plugin/original.yaml"
309+
patchFile := "test-fixtures/patches/override-just-plugin/patch.yaml"
310+
resultFile := "test-fixtures/patches/override-just-plugin/result.yaml"
311+
312+
originalDWT := workspaces.DevWorkspaceTemplateSpecContent{}
313+
patch := workspaces.PluginOverrides{}
314+
expectedDWT := workspaces.DevWorkspaceTemplateSpecContent{}
315+
316+
readFileToStruct(t, originalFile, &originalDWT)
317+
readFileToStruct(t, patchFile, &patch)
318+
readFileToStruct(t, resultFile, &expectedDWT)
319+
320+
gotDWT, err := OverrideDevWorkspaceTemplateSpec(&originalDWT, patch)
321+
if assert.NoError(t, err) {
322+
assert.Equal(t, &expectedDWT, gotDWT)
323+
}
324+
}
325+
326+
func readFileToStruct(t *testing.T, path string, into interface{}) {
327+
bytes, err := ioutil.ReadFile(path)
328+
if err != nil {
329+
t.Fatalf("Failed to read test file from %s: %s", path, err.Error())
330+
}
331+
err = yaml.Unmarshal(bytes, into)
332+
if err != nil {
333+
t.Fatalf("Failed to unmarshal file into struct: %s", err.Error())
334+
}
335+
}
336+
307337
// Since order of error message lines is not deterministic, it's necessary to compare
308338
// in a weaker way than asserting string equality.
309339
func compareErrorMessages(t *testing.T, expected, actual string, failReason string) {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
projects:
2+
- name: test-project
3+
git:
4+
remotes:
5+
origin: "https://test-data.io"
6+
7+
components:
8+
- name: my-component
9+
container:
10+
image: testimg
11+
12+
commands:
13+
- id: test-command
14+
exec:
15+
component: my-component
16+
commandLine: "echo 'just a test'"
17+
18+
events:
19+
preStart:
20+
- test-command
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
components:
2+
- name: my-component
3+
container:
4+
image: overridden-image
5+
6+
commands:
7+
- id: test-command
8+
exec:
9+
component: my-component
10+
commandLine: "echo 'this bit is updated'"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
projects:
2+
- name: test-project
3+
git:
4+
remotes:
5+
origin: "https://test-data.io"
6+
7+
components:
8+
- name: my-component
9+
container:
10+
image: overridden-image
11+
12+
commands:
13+
- id: test-command
14+
exec:
15+
component: my-component
16+
commandLine: "echo 'this bit is updated'"
17+
18+
events:
19+
preStart:
20+
- test-command

0 commit comments

Comments
 (0)