1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/pkg/config/defaults_test.go
Oliver Nocon c1eb9f5c70
Provide first parts for golang implementation ()
* Provide first parts for golang implementation
2019-10-22 15:41:27 +02:00

54 lines
1.4 KiB
Go

package config
import (
"io"
"io/ioutil"
"strings"
"testing"
)
func TestReadPipelineDefaults(t *testing.T) {
var d PipelineDefaults
t.Run("Success case", func(t *testing.T) {
d0 := strings.NewReader("general:\n testStepKey1: testStepValue1")
d1 := strings.NewReader("general:\n testStepKey2: testStepValue2")
err := d.ReadPipelineDefaults([]io.ReadCloser{ioutil.NopCloser(d0), ioutil.NopCloser(d1)})
if err != nil {
t.Errorf("Got error although no error expected: %v", err)
}
t.Run("Defaults 0", func(t *testing.T) {
expected := "testStepValue1"
if d.Defaults[0].General["testStepKey1"] != expected {
t.Errorf("got: %v, expected: %v", d.Defaults[0].General["testStepKey1"], expected)
}
})
t.Run("Defaults 1", func(t *testing.T) {
expected := "testStepValue2"
if d.Defaults[1].General["testStepKey2"] != expected {
t.Errorf("got: %v, expected: %v", d.Defaults[1].General["testStepKey2"], expected)
}
})
})
t.Run("Read failure", func(t *testing.T) {
var rc errReadCloser
err := d.ReadPipelineDefaults([]io.ReadCloser{rc})
if err == nil {
t.Errorf("Got no error although error expected.")
}
})
t.Run("Unmarshalling failure", func(t *testing.T) {
myConfig := strings.NewReader("general:\n\ttestStepKey: testStepValue")
err := d.ReadPipelineDefaults([]io.ReadCloser{ioutil.NopCloser(myConfig)})
if err == nil {
t.Errorf("Got no error although error expected.")
}
})
}