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:
parent
bdd1e89497
commit
fb3c6b5978
@ -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]
|
||||
|
@ -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"))
|
||||
|
Loading…
Reference in New Issue
Block a user