Skip to content

Commit

Permalink
Add tests for merging TemplateSpecs with nil parent or plugin
Browse files Browse the repository at this point in the history
These tests are expected to fail due to devfile#295

Signed-off-by: Angel Misevski <amisevsk@redhat.com>
  • Loading branch information
amisevsk committed Jan 15, 2021
1 parent 56ca5a7 commit 17fdd5d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
39 changes: 39 additions & 0 deletions pkg/utils/overriding/overriding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,45 @@ func TestPluginOverrides(t *testing.T) {
}
}

func TestMergingOnlyPlugins(t *testing.T) {
baseFile := "test-fixtures/merges/no-parent/main.yaml"
pluginFile := "test-fixtures/merges/no-parent/plugin.yaml"
resultFile := "test-fixtures/merges/no-parent/result.yaml"

baseDWT := workspaces.DevWorkspaceTemplateSpecContent{}
pluginDWT := workspaces.DevWorkspaceTemplateSpecContent{}
expectedDWT := workspaces.DevWorkspaceTemplateSpecContent{}

readFileToStruct(t, baseFile, &baseDWT)
readFileToStruct(t, pluginFile, &pluginDWT)
readFileToStruct(t, resultFile, &expectedDWT)

gotDWT, err := MergeDevWorkspaceTemplateSpec(&baseDWT, nil, &pluginDWT)
if assert.NoError(t, err) {
assert.Equal(t, &expectedDWT, gotDWT)
}
}

func TestMergingOnlyParent(t *testing.T) {
// Reuse only plugin case since it's compatible
baseFile := "test-fixtures/merges/no-parent/main.yaml"
parentFile := "test-fixtures/merges/no-parent/plugin.yaml"
resultFile := "test-fixtures/merges/no-parent/result.yaml"

baseDWT := workspaces.DevWorkspaceTemplateSpecContent{}
parentDWT := workspaces.DevWorkspaceTemplateSpecContent{}
expectedDWT := workspaces.DevWorkspaceTemplateSpecContent{}

readFileToStruct(t, baseFile, &baseDWT)
readFileToStruct(t, parentFile, &parentDWT)
readFileToStruct(t, resultFile, &expectedDWT)

gotDWT, err := MergeDevWorkspaceTemplateSpec(&baseDWT, &parentDWT, nil)
if assert.NoError(t, err) {
assert.Equal(t, &expectedDWT, gotDWT)
}
}

func readFileToStruct(t *testing.T, path string, into interface{}) {
bytes, err := ioutil.ReadFile(path)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/utils/overriding/test-fixtures/merges/no-parent/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
components:
- name: test-component
container:
image: test-image
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
components:
- name: test-plugin-component
container:
image: test-plugin-image
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
components:
- name: test-plugin-component
container:
image: test-plugin-image
- name: test-component
container:
image: test-image

0 comments on commit 17fdd5d

Please sign in to comment.