You've already forked sap-jenkins-library
							
							
				mirror of
				https://github.com/SAP/jenkins-library.git
				synced 2025-10-30 23:57:50 +02:00 
			
		
		
		
	* Add runHelmCommand * Add dryRun for debug * Add default case in helmExecute * Fix unit-tests * small fix * Fix RunHelmAdd and change RunHelmPublish methods * Fix RunHelmPublish * Fix unit-tests * Fix unit-test * small fix * small fix * small fix * Add LintFlag PackageFlag PublishFlag flags * Add tests for httpClient.go * test * test * smal fix * small fix * Add getting name and version from Chart.yaml * Add test * Fix * small fix * Fix according to comments * small fix Co-authored-by: “Vitalii <“vitalii.sidorov@sap.com”> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Vitalii Sidorov <vitalii_sidorov@sap.com>
		
			
				
	
	
		
			81 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			81 lines
		
	
	
		
			2.6 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package kubernetes
 | |
| 
 | |
| import (
 | |
| 	"errors"
 | |
| 	"testing"
 | |
| 
 | |
| 	"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 := newHelmMockUtilsBundle()
 | |
| 			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)
 | |
| 			}
 | |
| 
 | |
| 		}
 | |
| 	})
 | |
| }
 |