From 90571754bfba799321671749473e7836b98d1bee Mon Sep 17 00:00:00 2001 From: Daniel Mieg <56156797+DanielMieg@users.noreply.github.com> Date: Thu, 16 Jul 2020 11:09:49 +0200 Subject: [PATCH] Add test cases for stepmeta.go (#1801) * Add tests * Remove obsolete comment --- pkg/config/stepmeta_test.go | 23 ++++++++++++++++++++--- vars/commonPipelineEnvironment.groovy | 2 -- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/pkg/config/stepmeta_test.go b/pkg/config/stepmeta_test.go index ab41ecad2..2ce43961c 100644 --- a/pkg/config/stepmeta_test.go +++ b/pkg/config/stepmeta_test.go @@ -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) { diff --git a/vars/commonPipelineEnvironment.groovy b/vars/commonPipelineEnvironment.groovy index 22ca7ee70..4059b051e 100644 --- a/vars/commonPipelineEnvironment.groovy +++ b/vars/commonPipelineEnvironment.groovy @@ -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)