Skip to content

Commit 52fd57b

Browse files
committed
Add tests for merging TemplateSpecs with nil parent or plugin
These tests are expected to fail due to devfile#295 Signed-off-by: Angel Misevski <[email protected]>
1 parent e491cff commit 52fd57b

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

pkg/utils/overriding/overriding_test.go

+39
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,45 @@ func TestPluginOverrides(t *testing.T) {
323323
}
324324
}
325325

326+
func TestMergingOnlyPlugins(t *testing.T) {
327+
baseFile := "test-fixtures/merges/no-parent/main.yaml"
328+
pluginFile := "test-fixtures/merges/no-parent/plugin.yaml"
329+
resultFile := "test-fixtures/merges/no-parent/result.yaml"
330+
331+
baseDWT := workspaces.DevWorkspaceTemplateSpecContent{}
332+
pluginDWT := workspaces.DevWorkspaceTemplateSpecContent{}
333+
expectedDWT := workspaces.DevWorkspaceTemplateSpecContent{}
334+
335+
readFileToStruct(t, baseFile, &baseDWT)
336+
readFileToStruct(t, pluginFile, &pluginDWT)
337+
readFileToStruct(t, resultFile, &expectedDWT)
338+
339+
gotDWT, err := MergeDevWorkspaceTemplateSpec(&baseDWT, nil, &pluginDWT)
340+
if assert.NoError(t, err) {
341+
assert.Equal(t, &expectedDWT, gotDWT)
342+
}
343+
}
344+
345+
func TestMergingOnlyParent(t *testing.T) {
346+
// Reuse only plugin case since it's compatible
347+
baseFile := "test-fixtures/merges/no-parent/main.yaml"
348+
parentFile := "test-fixtures/merges/no-parent/plugin.yaml"
349+
resultFile := "test-fixtures/merges/no-parent/result.yaml"
350+
351+
baseDWT := workspaces.DevWorkspaceTemplateSpecContent{}
352+
parentDWT := workspaces.DevWorkspaceTemplateSpecContent{}
353+
expectedDWT := workspaces.DevWorkspaceTemplateSpecContent{}
354+
355+
readFileToStruct(t, baseFile, &baseDWT)
356+
readFileToStruct(t, parentFile, &parentDWT)
357+
readFileToStruct(t, resultFile, &expectedDWT)
358+
359+
gotDWT, err := MergeDevWorkspaceTemplateSpec(&baseDWT, &parentDWT)
360+
if assert.NoError(t, err) {
361+
assert.Equal(t, &expectedDWT, gotDWT)
362+
}
363+
}
364+
326365
func readFileToStruct(t *testing.T, path string, into interface{}) {
327366
bytes, err := ioutil.ReadFile(path)
328367
if err != nil {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
components:
2+
- name: test-component
3+
container:
4+
image: test-image
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
components:
2+
- name: test-plugin-component
3+
container:
4+
image: test-plugin-image
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
components:
2+
- name: test-plugin-component
3+
container:
4+
image: test-plugin-image
5+
- name: test-component
6+
container:
7+
image: test-image

0 commit comments

Comments
 (0)