mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
ffc931aad1
* 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>
91 lines
2.8 KiB
Go
91 lines
2.8 KiB
Go
//go:build unit
|
|
// +build unit
|
|
|
|
package kubernetes
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/mock"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestRunUtils(t *testing.T) {
|
|
t.Run("Get container info", func(t *testing.T) {
|
|
testTable := []struct {
|
|
chartYamlFile string
|
|
dataChartYaml string
|
|
expectedChartName string
|
|
expectedPackageVersion string
|
|
expectedError error
|
|
setFileReadError bool
|
|
}{
|
|
{
|
|
chartYamlFile: "path/to/Chart.yaml",
|
|
dataChartYaml: "name: nginx-testChart\nversion: 1.3.5",
|
|
expectedChartName: "nginx-testChart",
|
|
expectedPackageVersion: "1.3.5",
|
|
expectedError: nil,
|
|
setFileReadError: false,
|
|
},
|
|
{
|
|
chartYamlFile: "path/to/Chart.yaml",
|
|
dataChartYaml: "name: nginx-testChart\nversion: 1.3.5",
|
|
expectedChartName: "nginx-testChart",
|
|
expectedPackageVersion: "1.3.5",
|
|
expectedError: errors.New("file couldn't read"),
|
|
setFileReadError: true,
|
|
},
|
|
{
|
|
chartYamlFile: "path/to/Chart.yaml",
|
|
dataChartYaml: "version: 1.3.5",
|
|
expectedChartName: "nginx-testChart",
|
|
expectedPackageVersion: "1.3.5",
|
|
expectedError: errors.New("name not found in chart yaml file (or wrong type)"),
|
|
setFileReadError: false,
|
|
},
|
|
{
|
|
chartYamlFile: "path/to/Chart.yaml",
|
|
dataChartYaml: "name: nginx-testChart",
|
|
expectedChartName: "nginx-testChart",
|
|
expectedPackageVersion: "1.3.5",
|
|
expectedError: errors.New("version not found in chart yaml file (or wrong type)"),
|
|
setFileReadError: false,
|
|
},
|
|
{
|
|
chartYamlFile: "path/to/Chart.yaml",
|
|
dataChartYaml: "name=nginx-testChart",
|
|
expectedChartName: "nginx-testChart",
|
|
expectedPackageVersion: "1.3.5",
|
|
expectedError: errors.New("failed unmarshal"),
|
|
setFileReadError: false,
|
|
},
|
|
}
|
|
|
|
for _, testCase := range testTable {
|
|
utils := helmMockUtilsBundle{
|
|
ExecMockRunner: &mock.ExecMockRunner{},
|
|
FilesMock: &mock.FilesMock{},
|
|
HttpClientMock: &mock.HttpClientMock{
|
|
FileUploads: map[string]string{},
|
|
},
|
|
}
|
|
utils.AddFile(testCase.chartYamlFile, []byte(testCase.dataChartYaml))
|
|
if testCase.setFileReadError {
|
|
utils.FileReadErrors = map[string]error{testCase.chartYamlFile: testCase.expectedError}
|
|
}
|
|
nameChart, packageVersion, err := GetChartInfo(testCase.chartYamlFile, utils)
|
|
if testCase.expectedError != nil {
|
|
assert.Error(t, err)
|
|
assert.Contains(t, err.Error(), testCase.expectedError.Error())
|
|
} else {
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, testCase.expectedChartName, nameChart)
|
|
assert.Equal(t, testCase.expectedPackageVersion, packageVersion)
|
|
}
|
|
|
|
}
|
|
})
|
|
}
|