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
Jk1484 ffc931aad1
feat(golangBuild): use 'unit' build tag to include tests during test execution (#4345)
* Added unit tag as argument. Added description to runTests command. Changed code generator to have unit build tag in generated unit test files.

* Added unit build tag to all unit test files.

* added to new unit test unit build tag

* Update verify-go.yml

* small fix

---------

Co-authored-by: Muhammadali Nazarov <Muhammadali.Nazarov@acronis.com>
Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
2023-05-03 21:02:11 +05:00

57 lines
1.5 KiB
Go

//go:build unit
// +build unit
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.")
}
})
}