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

Add test cases for stepmeta.go (#1801)

* Add tests

* Remove obsolete comment
This commit is contained in:
Daniel Mieg 2020-07-16 11:09:49 +02:00 committed by GitHub
parent 1c49326103
commit 90571754bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 5 deletions

View File

@ -534,9 +534,25 @@ func TestGetResourceParameters(t *testing.T) {
{
in: StepData{
Spec: StepSpec{Inputs: StepInputs{Parameters: []StepParameters{
{Name: "param3", ResourceRef: []ResourceReference{{Name: "commonPipelineEnvironment", Param: "envparam3"}}, Type: "[]string"},
{Name: "param2", ResourceRef: []ResourceReference{{Name: "commonPipelineEnvironment", Param: "envparam2"}}, Type: "string"},
{Name: "param3", ResourceRef: []ResourceReference{{Name: "commonPipelineEnvironment", Param: "jsonList"}}, Type: "[]string"},
}}}},
expected: map[string]interface{}{"param3": []interface{}{"value1", "value2"}},
expected: map[string]interface{}{"param2": "val2", "param3": []interface{}{"value1", "value2"}},
},
{
in: StepData{
Spec: StepSpec{Inputs: StepInputs{Parameters: []StepParameters{
{Name: "param4", ResourceRef: []ResourceReference{{Name: "commonPipelineEnvironment", Param: "jsonKeyValue"}}, Type: "map[string]interface{}"},
}}}},
expected: map[string]interface{}{"param4": map[string]interface{}{"key": "value"}},
},
{
in: StepData{
Spec: StepSpec{Inputs: StepInputs{Parameters: []StepParameters{
{Name: "param1", ResourceRef: []ResourceReference{{Name: "commonPipelineEnvironment", Param: "envparam1"}}, Type: "noString"},
{Name: "param4", ResourceRef: []ResourceReference{{Name: "commonPipelineEnvironment", Param: "jsonKeyValue"}}, Type: "string"},
}}}},
expected: map[string]interface{}{"param1": interface{}(nil), "param4": "{\"key\":\"value\"}"},
},
}
@ -555,7 +571,8 @@ func TestGetResourceParameters(t *testing.T) {
ioutil.WriteFile(filepath.Join(cpeDir, "envparam1"), []byte("val1"), 0700)
ioutil.WriteFile(filepath.Join(cpeDir, "envparam2"), []byte("val2"), 0700)
ioutil.WriteFile(filepath.Join(cpeDir, "envparam3"), []byte("[\"value1\",\"value2\"]"), 0700)
ioutil.WriteFile(filepath.Join(cpeDir, "jsonList"), []byte("[\"value1\",\"value2\"]"), 0700)
ioutil.WriteFile(filepath.Join(cpeDir, "jsonKeyValue"), []byte("{\"key\":\"value\"}"), 0700)
for run, test := range tt {
t.Run(fmt.Sprintf("Run %v", run), func(t *testing.T) {

View File

@ -218,8 +218,6 @@ class commonPipelineEnvironment implements Serializable {
void readFromDisk(script) {
// While a groovy list will be parsed into a JSON list in "writeToDisk", the function "readFromDisk" won't parse the received String
files.each({f ->
if (script.fileExists(f.filename)) {
this[f.property] = script.readFile(f.filename)