1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-16 05:16:08 +02:00

Ignore wrong type of alias (#1778)

This commit is contained in:
Daniel Kurzynski 2020-07-09 14:13:06 +02:00 committed by GitHub
parent bdd1e89497
commit fb3c6b5978
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import (
"io"
"io/ioutil"
"os"
"reflect"
"strings"
"github.com/SAP/jenkins-library/pkg/http"
@ -100,6 +101,12 @@ func getDeepAliasValue(configMap map[string]interface{}, key string) interface{}
if configMap[parts[0]] == nil {
return nil
}
paramValueType := reflect.ValueOf(configMap[parts[0]])
if paramValueType.Kind() != reflect.Map {
log.Entry().Debugf("Ignoring alias '%v' as '%v' is not pointing to a map.", key, parts[0])
return nil
}
return getDeepAliasValue(configMap[parts[0]].(map[string]interface{}), strings.Join(parts[1:], "/"))
}
return configMap[key]

View File

@ -258,6 +258,21 @@ steps:
assert.Equal(t, "p1_conf", stepConfig.Config["p1"])
})
t.Run("Ignore alias if wrong type", func(t *testing.T) {
var c Config
stepParams := []StepParameters{
StepParameters{Name: "p0", Scope: []string{"GENERAL"}, Type: "bool", Aliases: []Alias{}},
StepParameters{Name: "p1", Scope: []string{"GENERAL"}, Type: "string", Aliases: []Alias{{Name: "p0/subParam"}}}}
testConf := "general:\n p0: true"
stepConfig, err := c.GetStepConfig(nil, "", ioutil.NopCloser(strings.NewReader(testConf)), nil, false, StepFilters{General: []string{"p0", "p1"}}, stepParams, nil, nil, "stage1", "step1", []Alias{{}})
assert.NoError(t, err, "Error occurred but no error expected")
assert.Equal(t, true, stepConfig.Config["p0"])
assert.Equal(t, nil, stepConfig.Config["p1"])
})
t.Run("Failure case config", func(t *testing.T) {
var c Config
myConfig := ioutil.NopCloser(strings.NewReader("invalid config"))