From e7bdce2d714f37ad71812347b9df2a38138aa09f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szabados=20=C3=81ron?= Date: Tue, 28 Apr 2020 11:42:09 +0200 Subject: [PATCH] [TOOL-2041] Access Environment item values with GetKeyValuePair instead of [] operator (#719) * check cast, return default representation if unable to cast but value not nil * fix env value access * added tests --- cli/run_util.go | 5 ++--- cli/run_util_test.go | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/cli/run_util.go b/cli/run_util.go index 3e54d45fc..abb8e2228 100644 --- a/cli/run_util.go +++ b/cli/run_util.go @@ -596,9 +596,8 @@ func expandStepInputs( } for index, environmentItem := range environments { - envValue := environmentItem[key] - if envValue != nil { - return os.Expand(envValue.(string), mappingFuncFactory(environments[:index])) + if envKey, envValue, err := environmentItem.GetKeyValuePair(); err == nil && envKey == key { + return os.Expand(envValue, mappingFuncFactory(environments[:index])) } } diff --git a/cli/run_util_test.go b/cli/run_util_test.go index eeb861848..eda761e11 100644 --- a/cli/run_util_test.go +++ b/cli/run_util_test.go @@ -797,6 +797,46 @@ func TestExpandStepInputsNeedExpansion(t *testing.T) { require.Equal(t, "13.3", expandedInputs["simulator_os_version"]) } +func TestExpandStepInputsNeedsFloatExpansion(t *testing.T) { + // Arrange + testInputs := []envmanModels.EnvironmentItemModel{ + envmanModels.EnvironmentItemModel{"simulator_os_version": "$SIMULATOR_OS_VERSION", "opts": map[string]interface{}{"is_sensitive": false}}, + envmanModels.EnvironmentItemModel{"simulator_device": "iPhone 8 Plus", "opts": map[string]interface{}{"is_sensitive": false}}, + } + + testEnvironment := []envmanModels.EnvironmentItemModel{ + envmanModels.EnvironmentItemModel{"SIMULATOR_OS_VERSION": 13.3, "opts": map[string]interface{}{"is_sensitive": false}}, + envmanModels.EnvironmentItemModel{"SIMULATOR_DEVICE_BOOL": true, "opts": map[string]interface{}{"is_sensitive": false}}, + } + + // Act + expandedInputs := expandStepInputs(testInputs, testEnvironment) + + // Assert + require.NotNil(t, expandedInputs) + require.Equal(t, "iPhone 8 Plus", expandedInputs["simulator_device"]) + require.Equal(t, "13.3", expandedInputs["simulator_os_version"]) +} + +func TestExpandStepInputsNeedsBoolExpansion(t *testing.T) { + // Arrange + testInputs := []envmanModels.EnvironmentItemModel{ + envmanModels.EnvironmentItemModel{"random_bool": "BOOL: $RANDOM_BOOL", "opts": map[string]interface{}{"is_sensitive": false}}, + envmanModels.EnvironmentItemModel{"simulator_device": "iPhone 8 $SIMULATOR_DEVICE_BOOL", "opts": map[string]interface{}{"is_sensitive": false}}, + } + + testEnvironment := []envmanModels.EnvironmentItemModel{ + envmanModels.EnvironmentItemModel{"RANDOM_BOOL": true, "opts": map[string]interface{}{"is_sensitive": false}}, + } + + // Act + expandedInputs := expandStepInputs(testInputs, testEnvironment) + + // Assert + require.NotNil(t, expandedInputs) + require.Equal(t, "BOOL: true", expandedInputs["random_bool"]) +} + func TestExpandStepInputsNeedExpansionWithinExpansion(t *testing.T) { // Arrange testInputs := []envmanModels.EnvironmentItemModel{