Skip to content

Commit

Permalink
[TOOL-2041] Access Environment item values with GetKeyValuePair inste…
Browse files Browse the repository at this point in the history
…ad of [] operator (#719)

* check cast, return default representation if unable to cast but value not nil

* fix env value access

* added tests
  • Loading branch information
Szabados Áron authored Apr 28, 2020
1 parent dcef36f commit e7bdce2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
5 changes: 2 additions & 3 deletions cli/run_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
}
}

Expand Down
40 changes: 40 additions & 0 deletions cli/run_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit e7bdce2

Please sign in to comment.