Skip to content

Commit

Permalink
fix: Properly convert devfile version to a string
Browse files Browse the repository at this point in the history
Signed-off-by: Anatolii Bazko <abazko@redhat.com>
  • Loading branch information
tolusha committed Jun 25, 2024
1 parent 66c83ce commit a3a2896
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/deploy/editors-definitions/editors_definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func updateEditorDefinitionImages(devfile map[string]interface{}) {
metadata := devfile["metadata"].(map[string]interface{})
devfileName := metadata["name"].(string)
attributes := metadata["attributes"].(map[string]interface{})
devfileVersion := attributes["version"].(string)
devfileVersion := fmt.Sprintf("%v", attributes["version"])

components := devfile["components"].([]interface{})
for _, component := range components {
Expand Down
24 changes: 17 additions & 7 deletions pkg/deploy/editors-definitions/editors_definitions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,30 @@ import (
)

func TestReadEditorDefinitions(t *testing.T) {
err := os.Setenv("RELATED_IMAGE_editor_definition_che_code_1_2_3_component_a", "image-new-a")
err := os.Setenv("RELATED_IMAGE_editor_definition_che_code_1_2_3_component_a", "image-new-1_2_3-a")
err = os.Setenv("RELATED_IMAGE_editor_definition_che_code_2022_1_component_a", "image-new-2022_1-a")
assert.NoError(t, err)

defer func() {
_ = os.Setenv("RELATED_IMAGE_editor_definition_che_code_1_2_3_component_a", "")
_ = os.Setenv("RELATED_IMAGE_editor_definition_che_code_2022_1_component_a", "")
}()

editorDefinitions, err := readEditorDefinitions()
assert.NoError(t, err)
assert.NotEmpty(t, editorDefinitions)
assert.Equal(t, 1, len(editorDefinitions))
assert.Contains(t, editorDefinitions, "devfile.yaml")
assert.Equal(t, 2, len(editorDefinitions))
assert.Contains(t, editorDefinitions, "devfile-1.yaml")
assert.Contains(t, editorDefinitions, "devfile-2.yaml")

var devfile map[string]interface{}
err = yaml.Unmarshal(editorDefinitions["devfile.yaml"], &devfile)
err = yaml.Unmarshal(editorDefinitions["devfile-1.yaml"], &devfile)
assert.NoError(t, err)

components := devfile["components"].([]interface{})

component := components[0].(map[string]interface{})
container := component["container"].(map[string]interface{})
assert.Equal(t, "image-new-a", container["image"])
assert.Equal(t, "image-new-1_2_3-a", container["image"])

component = components[1].(map[string]interface{})
container = component["container"].(map[string]interface{})
Expand All @@ -53,6 +55,14 @@ func TestReadEditorDefinitions(t *testing.T) {
component = components[2].(map[string]interface{})
container, ok := component["container"].(map[string]interface{})
assert.False(t, ok)

err = yaml.Unmarshal(editorDefinitions["devfile-2.yaml"], &devfile)
assert.NoError(t, err)

components = devfile["components"].([]interface{})
component = components[0].(map[string]interface{})
container = component["container"].(map[string]interface{})
assert.Equal(t, "image-new-2022_1-a", container["image"])
}

func TestSyncEditorDefinitions(t *testing.T) {
Expand All @@ -61,7 +71,7 @@ func TestSyncEditorDefinitions(t *testing.T) {
editorDefinitions, err := readEditorDefinitions()
assert.NoError(t, err)
assert.NotEmpty(t, editorDefinitions)
assert.Len(t, editorDefinitions, 1)
assert.Len(t, editorDefinitions, 2)

done, err := syncEditorDefinitions(ctx, editorDefinitions)
assert.NoError(t, err)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# Copyright (c) 2019-2024 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation
#

schemaVersion: 2.2.2
metadata:
name: che-code
attributes:
version: 2022.1
publisher: test
components:
- name: component-a
container:
image: image-a

0 comments on commit a3a2896

Please sign in to comment.