1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/pkg/cloudfoundry/Vars_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

58 lines
1.5 KiB
Go

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