mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-16 11:09:33 +02:00
55bba0ebbb
Vars file handling centralized We have the same coding for handling varsf-files and vars. With that change we shift to having one common coding for that
55 lines
1.5 KiB
Go
55 lines
1.5 KiB
Go
package cloudfoundry
|
|
|
|
import (
|
|
"github.com/SAP/jenkins-library/pkg/mock"
|
|
"github.com/SAP/jenkins-library/pkg/piperutils"
|
|
"github.com/stretchr/testify/assert"
|
|
"testing"
|
|
)
|
|
|
|
func TestVarsFiles(t *testing.T) {
|
|
|
|
defer func() {
|
|
_fileUtils = piperutils.Files{}
|
|
}()
|
|
|
|
filesMock := mock.FilesMock{}
|
|
filesMock.AddDir("/home/me")
|
|
filesMock.Chdir("/home/me")
|
|
filesMock.AddFile("varsA.yml", []byte("file content does not matter"))
|
|
filesMock.AddFile("varsB.yml", []byte("file content does not matter"))
|
|
_fileUtils = &filesMock
|
|
|
|
t.Run("All vars files found", func(t *testing.T) {
|
|
opts, err := GetVarsFileOptions([]string{"varsA.yml", "varsB.yml"})
|
|
if assert.NoError(t, err) {
|
|
assert.Equal(t, []string{"--vars-file", "varsA.yml", "--vars-file", "varsB.yml"}, opts)
|
|
}
|
|
})
|
|
|
|
t.Run("Some vars files missing", func(t *testing.T) {
|
|
opts, err := GetVarsFileOptions([]string{"varsA.yml", "varsC.yml", "varsD.yml"})
|
|
if assert.EqualError(t, err, "Some vars files could not be found: [varsC.yml varsD.yml]") {
|
|
assert.IsType(t, &VarsFilesNotFoundError{}, err)
|
|
assert.Equal(t, []string{"--vars-file", "varsA.yml"}, opts)
|
|
}
|
|
})
|
|
}
|
|
|
|
func TestVars(t *testing.T) {
|
|
|
|
t.Run("Empty vars", func(t *testing.T) {
|
|
opts, err := GetVarsOptions([]string{})
|
|
if assert.NoError(t, err) {
|
|
assert.Equal(t, []string{}, opts)
|
|
}
|
|
})
|
|
|
|
t.Run("Some vars", func(t *testing.T) {
|
|
opts, err := GetVarsOptions([]string{"a=b", "x=y"})
|
|
if assert.NoError(t, err) {
|
|
assert.Equal(t, []string{"--var", "a=b", "--var", "x=y"}, opts)
|
|
}
|
|
})
|
|
}
|