From 6cfe452f877f2a8a810906b4c8b4e80898ff6489 Mon Sep 17 00:00:00 2001 From: Anatolii Bazko Date: Wed, 26 Jun 2024 09:05:00 +0200 Subject: [PATCH] fix: Properly convert devfile version to a string (#1863) Signed-off-by: Anatolii Bazko --- .../editors_definitions.go | 2 +- .../editors_definitions_test.go | 24 +++++++++++++------ .../{devfile.yaml => devfile-1.yaml} | 0 .../test-editors-definitions/devfile-2.yaml | 23 ++++++++++++++++++ 4 files changed, 41 insertions(+), 8 deletions(-) rename pkg/deploy/editors-definitions/test-editors-definitions/{devfile.yaml => devfile-1.yaml} (100%) create mode 100644 pkg/deploy/editors-definitions/test-editors-definitions/devfile-2.yaml diff --git a/pkg/deploy/editors-definitions/editors_definitions.go b/pkg/deploy/editors-definitions/editors_definitions.go index 4d7f5dcf5..b31838d2b 100644 --- a/pkg/deploy/editors-definitions/editors_definitions.go +++ b/pkg/deploy/editors-definitions/editors_definitions.go @@ -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 { diff --git a/pkg/deploy/editors-definitions/editors_definitions_test.go b/pkg/deploy/editors-definitions/editors_definitions_test.go index aa9f54125..a4888ff88 100644 --- a/pkg/deploy/editors-definitions/editors_definitions_test.go +++ b/pkg/deploy/editors-definitions/editors_definitions_test.go @@ -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{}) @@ -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) { @@ -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) diff --git a/pkg/deploy/editors-definitions/test-editors-definitions/devfile.yaml b/pkg/deploy/editors-definitions/test-editors-definitions/devfile-1.yaml similarity index 100% rename from pkg/deploy/editors-definitions/test-editors-definitions/devfile.yaml rename to pkg/deploy/editors-definitions/test-editors-definitions/devfile-1.yaml diff --git a/pkg/deploy/editors-definitions/test-editors-definitions/devfile-2.yaml b/pkg/deploy/editors-definitions/test-editors-definitions/devfile-2.yaml new file mode 100644 index 000000000..ad965db17 --- /dev/null +++ b/pkg/deploy/editors-definitions/test-editors-definitions/devfile-2.yaml @@ -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 +