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 
			
		
		
		
	Fix marshalling a boolean (#2521)
This commit is contained in:
		| @@ -87,7 +87,7 @@ func generateManifestYAML(config *abapEnvironmentCreateSystemOptions) ([]byte, e | |||||||
| 	params := abapSystemParameters{ | 	params := abapSystemParameters{ | ||||||
| 		AdminEmail:           config.AbapSystemAdminEmail, | 		AdminEmail:           config.AbapSystemAdminEmail, | ||||||
| 		Description:          config.AbapSystemDescription, | 		Description:          config.AbapSystemDescription, | ||||||
| 		IsDevelopmentAllowed: config.AbapSystemIsDevelopmentAllowed, | 		IsDevelopmentAllowed: &config.AbapSystemIsDevelopmentAllowed, | ||||||
| 		SapSystemName:        config.AbapSystemID, | 		SapSystemName:        config.AbapSystemID, | ||||||
| 		SizeOfPersistence:    config.AbapSystemSizeOfPersistence, | 		SizeOfPersistence:    config.AbapSystemSizeOfPersistence, | ||||||
| 		SizeOfRuntime:        config.AbapSystemSizeOfRuntime, | 		SizeOfRuntime:        config.AbapSystemSizeOfRuntime, | ||||||
| @@ -136,7 +136,7 @@ func generateManifestYAML(config *abapEnvironmentCreateSystemOptions) ([]byte, e | |||||||
| type abapSystemParameters struct { | type abapSystemParameters struct { | ||||||
| 	AdminEmail           string `json:"admin_email,omitempty"` | 	AdminEmail           string `json:"admin_email,omitempty"` | ||||||
| 	Description          string `json:"description,omitempty"` | 	Description          string `json:"description,omitempty"` | ||||||
| 	IsDevelopmentAllowed bool   `json:"is_development_allowed,omitempty"` | 	IsDevelopmentAllowed *bool  `json:"is_development_allowed,omitempty"` | ||||||
| 	SapSystemName        string `json:"sapsystemname,omitempty"` | 	SapSystemName        string `json:"sapsystemname,omitempty"` | ||||||
| 	SizeOfPersistence    int    `json:"size_of_persistence,omitempty"` | 	SizeOfPersistence    int    `json:"size_of_persistence,omitempty"` | ||||||
| 	SizeOfRuntime        int    `json:"size_of_runtime,omitempty"` | 	SizeOfRuntime        int    `json:"size_of_runtime,omitempty"` | ||||||
|   | |||||||
| @@ -200,6 +200,115 @@ repositories: | |||||||
| 			assert.Equal(t, expectedResult, result, "Result not as expected") | 			assert.Equal(t, expectedResult, result, "Result not as expected") | ||||||
| 		} | 		} | ||||||
| 	}) | 	}) | ||||||
|  |  | ||||||
|  | 	t.Run("Test IsDevelopmentAllowed", func(t *testing.T) { | ||||||
|  | 		config := abapEnvironmentCreateSystemOptions{ | ||||||
|  | 			CfAPIEndpoint:                  "https://api.endpoint.com", | ||||||
|  | 			CfOrg:                          "testOrg", | ||||||
|  | 			CfSpace:                        "testSpace", | ||||||
|  | 			Username:                       "testUser", | ||||||
|  | 			Password:                       "testPassword", | ||||||
|  | 			CfService:                      "testService", | ||||||
|  | 			CfServiceInstance:              "testName", | ||||||
|  | 			CfServicePlan:                  "testPlan", | ||||||
|  | 			AbapSystemAdminEmail:           "user@example.com", | ||||||
|  | 			AbapSystemID:                   "H02", | ||||||
|  | 			AbapSystemIsDevelopmentAllowed: true, | ||||||
|  | 			AbapSystemSizeOfPersistence:    4, | ||||||
|  | 			AbapSystemSizeOfRuntime:        4, | ||||||
|  | 			AddonDescriptorFileName:        "addon.yml", | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		dir, err := ioutil.TempDir("", "test variable substitution") | ||||||
|  | 		if err != nil { | ||||||
|  | 			t.Fatal("Failed to create temporary directory") | ||||||
|  | 		} | ||||||
|  | 		oldCWD, _ := os.Getwd() | ||||||
|  | 		_ = os.Chdir(dir) | ||||||
|  | 		// clean up tmp dir | ||||||
|  | 		defer func() { | ||||||
|  | 			_ = os.Chdir(oldCWD) | ||||||
|  | 			_ = os.RemoveAll(dir) | ||||||
|  | 		}() | ||||||
|  |  | ||||||
|  | 		addonYML := `addonProduct: myProduct | ||||||
|  | addonVersion: 1.2.3 | ||||||
|  | repositories: | ||||||
|  |   - name: '/DMO/REPO' | ||||||
|  | ` | ||||||
|  |  | ||||||
|  | 		addonYMLBytes := []byte(addonYML) | ||||||
|  | 		err = ioutil.WriteFile("addon.yml", addonYMLBytes, 0644) | ||||||
|  |  | ||||||
|  | 		expectedResult := `create-services: | ||||||
|  | - broker: testService | ||||||
|  |   name: testName | ||||||
|  |   parameters: '{"admin_email":"user@example.com","is_development_allowed":true,"sapsystemname":"H02","size_of_persistence":4,"size_of_runtime":4}' | ||||||
|  |   plan: testPlan | ||||||
|  | ` | ||||||
|  |  | ||||||
|  | 		resultBytes, err := generateManifestYAML(&config) | ||||||
|  |  | ||||||
|  | 		if assert.NoError(t, err) { | ||||||
|  | 			result := string(resultBytes) | ||||||
|  | 			assert.Equal(t, expectedResult, result, "Result not as expected") | ||||||
|  | 		} | ||||||
|  | 	}) | ||||||
|  |  | ||||||
|  | 	t.Run("Create service with generated manifest - with addon", func(t *testing.T) { | ||||||
|  | 		config := abapEnvironmentCreateSystemOptions{ | ||||||
|  | 			CfAPIEndpoint:                  "https://api.endpoint.com", | ||||||
|  | 			CfOrg:                          "testOrg", | ||||||
|  | 			CfSpace:                        "testSpace", | ||||||
|  | 			Username:                       "testUser", | ||||||
|  | 			Password:                       "testPassword", | ||||||
|  | 			CfService:                      "testService", | ||||||
|  | 			CfServiceInstance:              "testName", | ||||||
|  | 			CfServicePlan:                  "testPlan", | ||||||
|  | 			AbapSystemAdminEmail:           "user@example.com", | ||||||
|  | 			AbapSystemID:                   "H02", | ||||||
|  | 			AbapSystemIsDevelopmentAllowed: false, | ||||||
|  | 			AbapSystemSizeOfPersistence:    4, | ||||||
|  | 			AbapSystemSizeOfRuntime:        4, | ||||||
|  | 			AddonDescriptorFileName:        "addon.yml", | ||||||
|  | 			IncludeAddon:                   true, | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		dir, err := ioutil.TempDir("", "test variable substitution") | ||||||
|  | 		if err != nil { | ||||||
|  | 			t.Fatal("Failed to create temporary directory") | ||||||
|  | 		} | ||||||
|  | 		oldCWD, _ := os.Getwd() | ||||||
|  | 		_ = os.Chdir(dir) | ||||||
|  | 		// clean up tmp dir | ||||||
|  | 		defer func() { | ||||||
|  | 			_ = os.Chdir(oldCWD) | ||||||
|  | 			_ = os.RemoveAll(dir) | ||||||
|  | 		}() | ||||||
|  |  | ||||||
|  | 		addonYML := `addonProduct: myProduct | ||||||
|  | addonVersion: 1.2.3 | ||||||
|  | repositories: | ||||||
|  |   - name: '/DMO/REPO' | ||||||
|  | ` | ||||||
|  |  | ||||||
|  | 		addonYMLBytes := []byte(addonYML) | ||||||
|  | 		err = ioutil.WriteFile("addon.yml", addonYMLBytes, 0644) | ||||||
|  |  | ||||||
|  | 		expectedResult := `create-services: | ||||||
|  | - broker: testService | ||||||
|  |   name: testName | ||||||
|  |   parameters: '{"admin_email":"user@example.com","is_development_allowed":false,"sapsystemname":"H02","size_of_persistence":4,"size_of_runtime":4,"addon_product_name":"myProduct","addon_product_version":"1.2.3","parent_saas_appname":"addon_test"}' | ||||||
|  |   plan: testPlan | ||||||
|  | ` | ||||||
|  |  | ||||||
|  | 		resultBytes, err := generateManifestYAML(&config) | ||||||
|  |  | ||||||
|  | 		if assert.NoError(t, err) { | ||||||
|  | 			result := string(resultBytes) | ||||||
|  | 			assert.Equal(t, expectedResult, result, "Result not as expected") | ||||||
|  | 		} | ||||||
|  | 	}) | ||||||
| } | } | ||||||
|  |  | ||||||
| type uuidMock struct { | type uuidMock struct { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user