github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/api/cloudcontroller/ccv2/space_test.go (about)

     1  package ccv2_test
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
     7  	. "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2"
     8  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/constant"
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  	. "github.com/onsi/gomega/ghttp"
    12  )
    13  
    14  var _ = Describe("Space", func() {
    15  	var client *Client
    16  
    17  	BeforeEach(func() {
    18  		client = NewTestClient()
    19  	})
    20  
    21  	Describe("CreateSpace", func() {
    22  		var (
    23  			space      Space
    24  			warnings   Warnings
    25  			executeErr error
    26  		)
    27  
    28  		When("The response returns a valid space", func() {
    29  			JustBeforeEach(func() {
    30  				space, warnings, executeErr = client.CreateSpace("some-space", "some-org-guid")
    31  			})
    32  
    33  			BeforeEach(func() {
    34  				response := `{
    35  			  "metadata": {
    36  		      "guid": "some-space-guid",
    37                "url": "/v2/spaces/some-space-guid"
    38  			},
    39  			  "entity": {
    40     				 "name": "some-space",
    41                   "organization_guid": "some-org-guid",
    42                   "space_quota_definition_guid": "some-quota-guid",
    43                   "allow_ssh": true
    44  			  }
    45  			}`
    46  
    47  				requestBody := map[string]interface{}{
    48  					"name":              "some-space",
    49  					"organization_guid": "some-org-guid",
    50  				}
    51  
    52  				server.AppendHandlers(
    53  					CombineHandlers(
    54  						VerifyRequest(http.MethodPost, "/v2/spaces"),
    55  						VerifyJSONRepresenting(requestBody),
    56  						RespondWith(http.StatusCreated, response, http.Header{"X-Cf-Warnings": {"warning-1"}}),
    57  					))
    58  			})
    59  
    60  			It("return space and all warnings", func() {
    61  				Expect(executeErr).NotTo(HaveOccurred())
    62  				Expect(space).To(Equal(
    63  					Space{
    64  						GUID:                     "some-space-guid",
    65  						OrganizationGUID:         "some-org-guid",
    66  						Name:                     "some-space",
    67  						SpaceQuotaDefinitionGUID: "some-quota-guid",
    68  						AllowSSH:                 true,
    69  					},
    70  				))
    71  				Expect(warnings).To(ConsistOf("warning-1"))
    72  			})
    73  		})
    74  
    75  		When("The user is not authorized to create a space", func() {
    76  			JustBeforeEach(func() {
    77  				space, warnings, executeErr = client.CreateSpace("some-space", "some-org-guid")
    78  			})
    79  
    80  			BeforeEach(func() {
    81  				response := `{
    82  								"code": 10003,
    83  								"description": "You are not authorized to perform the requested action"
    84  							}`
    85  
    86  				requestBody := map[string]interface{}{
    87  					"name":              "some-space",
    88  					"organization_guid": "some-org-guid",
    89  				}
    90  
    91  				server.AppendHandlers(
    92  					CombineHandlers(
    93  						VerifyRequest(http.MethodPost, "/v2/spaces"),
    94  						VerifyJSONRepresenting(requestBody),
    95  						RespondWith(http.StatusForbidden, response, http.Header{"X-Cf-Warnings": {"warning-1"}}),
    96  					))
    97  			})
    98  
    99  			It("return empty space with the errors and warnings", func() {
   100  				Expect(space).To(Equal(
   101  					Space{},
   102  				))
   103  				Expect(warnings).To(ConsistOf("warning-1"))
   104  				Expect(executeErr).To(MatchError(ccerror.ForbiddenError{
   105  					Message: "You are not authorized to perform the requested action",
   106  				}))
   107  			})
   108  		})
   109  	})
   110  
   111  	Describe("DeleteSpace", func() {
   112  		When("no errors are encountered", func() {
   113  			BeforeEach(func() {
   114  				jsonResponse := `{
   115  				"metadata": {
   116  					"guid": "job-guid",
   117  					"created_at": "2016-06-08T16:41:27Z",
   118  					"url": "/v2/jobs/job-guid"
   119  				},
   120  				"entity": {
   121  					"guid": "job-guid",
   122  					"status": "queued"
   123  				}
   124  			}`
   125  
   126  				server.AppendHandlers(
   127  					CombineHandlers(
   128  						VerifyRequest(http.MethodDelete, "/v2/spaces/some-space-guid", "recursive=true&async=true"),
   129  						RespondWith(http.StatusAccepted, jsonResponse, http.Header{"X-Cf-Warnings": {"warning-1, warning-2"}}),
   130  					))
   131  			})
   132  
   133  			It("deletes the Space and returns all warnings", func() {
   134  				job, warnings, err := client.DeleteSpace("some-space-guid")
   135  
   136  				Expect(err).NotTo(HaveOccurred())
   137  				Expect(warnings).To(ConsistOf(Warnings{"warning-1", "warning-2"}))
   138  				Expect(job.GUID).To(Equal("job-guid"))
   139  				Expect(job.Status).To(Equal(constant.JobStatusQueued))
   140  			})
   141  		})
   142  
   143  		When("an error is encountered", func() {
   144  			BeforeEach(func() {
   145  				response := `{
   146  "code": 30003,
   147  "description": "The Space could not be found: some-space-guid",
   148  "error_code": "CF-SpaceNotFound"
   149  }`
   150  				server.AppendHandlers(
   151  					CombineHandlers(
   152  						VerifyRequest(http.MethodDelete, "/v2/spaces/some-space-guid", "recursive=true&async=true"),
   153  						RespondWith(http.StatusNotFound, response, http.Header{"X-Cf-Warnings": {"warning-1, warning-2"}}),
   154  					))
   155  			})
   156  
   157  			It("returns an error and all warnings", func() {
   158  				_, warnings, err := client.DeleteSpace("some-space-guid")
   159  
   160  				Expect(err).To(MatchError(ccerror.ResourceNotFoundError{
   161  					Message: "The Space could not be found: some-space-guid",
   162  				}))
   163  				Expect(warnings).To(ConsistOf(Warnings{"warning-1", "warning-2"}))
   164  			})
   165  		})
   166  	})
   167  
   168  	Describe("GetSpaces", func() {
   169  		When("no errors are encountered", func() {
   170  			When("results are paginated", func() {
   171  				BeforeEach(func() {
   172  					response1 := `{
   173  						"next_url": "/v2/spaces?q=some-query:some-value&page=2&order-by=name",
   174  						"resources": [
   175  							{
   176  								"metadata": {
   177  									"guid": "space-guid-1"
   178  								},
   179  								"entity": {
   180  									"name": "space-1",
   181  									"allow_ssh": false,
   182  									"space_quota_definition_guid": "some-space-quota-guid-1",
   183  									"organization_guid": "org-guid-1"
   184  								}
   185  							},
   186  							{
   187  								"metadata": {
   188  									"guid": "space-guid-2"
   189  								},
   190  								"entity": {
   191  									"name": "space-2",
   192  									"allow_ssh": true,
   193  									"space_quota_definition_guid": "some-space-quota-guid-2",
   194  									"organization_guid": "org-guid-2"
   195  								}
   196  							}
   197  						]
   198  					}`
   199  					response2 := `{
   200  						"next_url": null,
   201  						"resources": [
   202  							{
   203  								"metadata": {
   204  									"guid": "space-guid-3"
   205  								},
   206  								"entity": {
   207  									"name": "space-3",
   208  									"allow_ssh": false,
   209  									"space_quota_definition_guid": "some-space-quota-guid-3",
   210  									"organization_guid": "org-guid-3"
   211  								}
   212  							},
   213  							{
   214  								"metadata": {
   215  									"guid": "space-guid-4"
   216  								},
   217  								"entity": {
   218  									"name": "space-4",
   219  									"allow_ssh": true,
   220  									"space_quota_definition_guid": "some-space-quota-guid-4",
   221  									"organization_guid": "org-guid-4"
   222  								}
   223  							}
   224  						]
   225  					}`
   226  					server.AppendHandlers(
   227  						CombineHandlers(
   228  							VerifyRequest(http.MethodGet, "/v2/spaces", "q=some-query:some-value&order-by=name"),
   229  							RespondWith(http.StatusOK, response1, http.Header{"X-Cf-Warnings": {"warning-1"}}),
   230  						))
   231  					server.AppendHandlers(
   232  						CombineHandlers(
   233  							VerifyRequest(http.MethodGet, "/v2/spaces", "q=some-query:some-value&page=2&order-by=name"),
   234  							RespondWith(http.StatusOK, response2, http.Header{"X-Cf-Warnings": {"warning-2"}}),
   235  						))
   236  				})
   237  
   238  				It("returns paginated results and all warnings", func() {
   239  					spaces, warnings, err := client.GetSpaces(Filter{
   240  						Type:     "some-query",
   241  						Operator: constant.EqualOperator,
   242  						Values:   []string{"some-value"},
   243  					})
   244  
   245  					Expect(err).NotTo(HaveOccurred())
   246  					Expect(spaces).To(Equal([]Space{
   247  						{
   248  							GUID:                     "space-guid-1",
   249  							OrganizationGUID:         "org-guid-1",
   250  							Name:                     "space-1",
   251  							AllowSSH:                 false,
   252  							SpaceQuotaDefinitionGUID: "some-space-quota-guid-1",
   253  						},
   254  						{
   255  							GUID:                     "space-guid-2",
   256  							OrganizationGUID:         "org-guid-2",
   257  							Name:                     "space-2",
   258  							AllowSSH:                 true,
   259  							SpaceQuotaDefinitionGUID: "some-space-quota-guid-2",
   260  						},
   261  						{
   262  							GUID:                     "space-guid-3",
   263  							OrganizationGUID:         "org-guid-3",
   264  							Name:                     "space-3",
   265  							AllowSSH:                 false,
   266  							SpaceQuotaDefinitionGUID: "some-space-quota-guid-3",
   267  						},
   268  						{
   269  							GUID:                     "space-guid-4",
   270  							OrganizationGUID:         "org-guid-4",
   271  							Name:                     "space-4",
   272  							AllowSSH:                 true,
   273  							SpaceQuotaDefinitionGUID: "some-space-quota-guid-4",
   274  						},
   275  					}))
   276  					Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
   277  				})
   278  			})
   279  		})
   280  
   281  		When("an error is encountered", func() {
   282  			BeforeEach(func() {
   283  				response := `{
   284    "code": 10001,
   285    "description": "Some Error",
   286    "error_code": "CF-SomeError"
   287  }`
   288  				server.AppendHandlers(
   289  					CombineHandlers(
   290  						VerifyRequest(http.MethodGet, "/v2/spaces", "order-by=name"),
   291  						RespondWith(http.StatusTeapot, response, http.Header{"X-Cf-Warnings": {"warning-1, warning-2"}}),
   292  					))
   293  			})
   294  
   295  			It("returns an error and all warnings", func() {
   296  				_, warnings, err := client.GetSpaces()
   297  
   298  				Expect(err).To(MatchError(ccerror.V2UnexpectedResponseError{
   299  					ResponseCode: http.StatusTeapot,
   300  					V2ErrorResponse: ccerror.V2ErrorResponse{
   301  						Code:        10001,
   302  						Description: "Some Error",
   303  						ErrorCode:   "CF-SomeError",
   304  					},
   305  				}))
   306  				Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
   307  			})
   308  		})
   309  	})
   310  
   311  	Describe("GetSecurityGroupSpaces", func() {
   312  		When("no errors are encountered", func() {
   313  			When("results are paginated", func() {
   314  				BeforeEach(func() {
   315  					response1 := `{
   316  						"next_url": "/v2/security_groups/security-group-guid/spaces?page=2",
   317  						"resources": [
   318  							{
   319  								"metadata": {
   320  									"guid": "space-guid-1"
   321  								},
   322  								"entity": {
   323  									"name": "space-1",
   324  									"allow_ssh": false,
   325  									"space_quota_definition_guid": "some-space-quota-guid-1",
   326  									"organization_guid": "org-guid-1"
   327  								}
   328  							},
   329  							{
   330  								"metadata": {
   331  									"guid": "space-guid-2"
   332  								},
   333  								"entity": {
   334  									"name": "space-2",
   335  									"allow_ssh": true,
   336  									"space_quota_definition_guid": "some-space-quota-guid-2",
   337  									"organization_guid": "org-guid-2"
   338  								}
   339  							}
   340  						]
   341  					}`
   342  					response2 := `{
   343  						"next_url": null,
   344  						"resources": [
   345  							{
   346  								"metadata": {
   347  									"guid": "space-guid-3"
   348  								},
   349  								"entity": {
   350  									"name": "space-3",
   351  									"allow_ssh": false,
   352  									"space_quota_definition_guid": "some-space-quota-guid-3",
   353  									"organization_guid": "org-guid-3"
   354  								}
   355  							},
   356  							{
   357  								"metadata": {
   358  									"guid": "space-guid-4"
   359  								},
   360  								"entity": {
   361  									"name": "space-4",
   362  									"allow_ssh": true,
   363  									"space_quota_definition_guid": "some-space-quota-guid-4",
   364  									"organization_guid": "org-guid-4"
   365  								}
   366  							}
   367  						]
   368  					}`
   369  					server.AppendHandlers(
   370  						CombineHandlers(
   371  							VerifyRequest(http.MethodGet, "/v2/security_groups/security-group-guid/spaces", ""),
   372  							RespondWith(http.StatusOK, response1, http.Header{"X-Cf-Warnings": {"warning-1"}}),
   373  						))
   374  					server.AppendHandlers(
   375  						CombineHandlers(
   376  							VerifyRequest(http.MethodGet, "/v2/security_groups/security-group-guid/spaces", "page=2"),
   377  							RespondWith(http.StatusOK, response2, http.Header{"X-Cf-Warnings": {"warning-2"}}),
   378  						))
   379  				})
   380  
   381  				It("returns paginated results and all warnings", func() {
   382  					spaces, warnings, err := client.GetSecurityGroupSpaces("security-group-guid")
   383  
   384  					Expect(err).NotTo(HaveOccurred())
   385  					Expect(spaces).To(Equal([]Space{
   386  						{
   387  							GUID:                     "space-guid-1",
   388  							OrganizationGUID:         "org-guid-1",
   389  							Name:                     "space-1",
   390  							AllowSSH:                 false,
   391  							SpaceQuotaDefinitionGUID: "some-space-quota-guid-1",
   392  						},
   393  						{
   394  							GUID:                     "space-guid-2",
   395  							OrganizationGUID:         "org-guid-2",
   396  							Name:                     "space-2",
   397  							AllowSSH:                 true,
   398  							SpaceQuotaDefinitionGUID: "some-space-quota-guid-2",
   399  						},
   400  						{
   401  							GUID:                     "space-guid-3",
   402  							OrganizationGUID:         "org-guid-3",
   403  							Name:                     "space-3",
   404  							AllowSSH:                 false,
   405  							SpaceQuotaDefinitionGUID: "some-space-quota-guid-3",
   406  						},
   407  						{
   408  							GUID:                     "space-guid-4",
   409  							OrganizationGUID:         "org-guid-4",
   410  							Name:                     "space-4",
   411  							AllowSSH:                 true,
   412  							SpaceQuotaDefinitionGUID: "some-space-quota-guid-4",
   413  						},
   414  					}))
   415  					Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
   416  				})
   417  			})
   418  		})
   419  
   420  		When("an error is encountered", func() {
   421  			BeforeEach(func() {
   422  				response := `{
   423    "code": 10001,
   424    "description": "Some Error",
   425    "error_code": "CF-SomeError"
   426  }`
   427  				server.AppendHandlers(
   428  					CombineHandlers(
   429  						VerifyRequest(http.MethodGet, "/v2/security_groups/security-group-guid/spaces"),
   430  						RespondWith(http.StatusTeapot, response, http.Header{"X-Cf-Warnings": {"warning-1, warning-2"}}),
   431  					))
   432  			})
   433  
   434  			It("returns an error and all warnings", func() {
   435  				_, warnings, err := client.GetSecurityGroupSpaces("security-group-guid")
   436  
   437  				Expect(err).To(MatchError(ccerror.V2UnexpectedResponseError{
   438  					ResponseCode: http.StatusTeapot,
   439  					V2ErrorResponse: ccerror.V2ErrorResponse{
   440  						Code:        10001,
   441  						Description: "Some Error",
   442  						ErrorCode:   "CF-SomeError",
   443  					},
   444  				}))
   445  				Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
   446  			})
   447  		})
   448  	})
   449  
   450  	Describe("GetSecurityGroupStagingSpaces", func() {
   451  		When("no errors are encountered", func() {
   452  			When("results are paginated", func() {
   453  				BeforeEach(func() {
   454  					response1 := `{
   455  						"next_url": "/v2/security_groups/security-group-guid/staging_spaces?page=2",
   456  						"resources": [
   457  							{
   458  								"metadata": {
   459  									"guid": "space-guid-1"
   460  								},
   461  								"entity": {
   462  									"name": "space-1",
   463  									"allow_ssh": false,
   464  									"space_quota_definition_guid": "some-space-quota-guid-1",
   465  									"organization_guid": "org-guid-1"
   466  								}
   467  							},
   468  							{
   469  								"metadata": {
   470  									"guid": "space-guid-2"
   471  								},
   472  								"entity": {
   473  									"name": "space-2",
   474  									"allow_ssh": true,
   475  									"space_quota_definition_guid": "some-space-quota-guid-2",
   476  									"organization_guid": "org-guid-2"
   477  								}
   478  							}
   479  						]
   480  					}`
   481  					response2 := `{
   482  						"next_url": null,
   483  						"resources": [
   484  							{
   485  								"metadata": {
   486  									"guid": "space-guid-3"
   487  								},
   488  								"entity": {
   489  									"name": "space-3",
   490  									"allow_ssh": false,
   491  									"space_quota_definition_guid": "some-space-quota-guid-3",
   492  									"organization_guid": "org-guid-3"
   493  								}
   494  							},
   495  							{
   496  								"metadata": {
   497  									"guid": "space-guid-4"
   498  								},
   499  								"entity": {
   500  									"name": "space-4",
   501  									"allow_ssh": true,
   502  									"space_quota_definition_guid": "some-space-quota-guid-4",
   503  									"organization_guid": "org-guid-4"
   504  								}
   505  							}
   506  						]
   507  					}`
   508  					server.AppendHandlers(
   509  						CombineHandlers(
   510  							VerifyRequest(http.MethodGet, "/v2/security_groups/security-group-guid/staging_spaces", ""),
   511  							RespondWith(http.StatusOK, response1, http.Header{"X-Cf-Warnings": {"warning-1"}}),
   512  						))
   513  					server.AppendHandlers(
   514  						CombineHandlers(
   515  							VerifyRequest(http.MethodGet, "/v2/security_groups/security-group-guid/staging_spaces", "page=2"),
   516  							RespondWith(http.StatusOK, response2, http.Header{"X-Cf-Warnings": {"warning-2"}}),
   517  						))
   518  				})
   519  
   520  				It("returns paginated results and all warnings", func() {
   521  					spaces, warnings, err := client.GetSecurityGroupStagingSpaces("security-group-guid")
   522  
   523  					Expect(err).NotTo(HaveOccurred())
   524  					Expect(spaces).To(Equal([]Space{
   525  						{
   526  							GUID:                     "space-guid-1",
   527  							OrganizationGUID:         "org-guid-1",
   528  							Name:                     "space-1",
   529  							AllowSSH:                 false,
   530  							SpaceQuotaDefinitionGUID: "some-space-quota-guid-1",
   531  						},
   532  						{
   533  							GUID:                     "space-guid-2",
   534  							OrganizationGUID:         "org-guid-2",
   535  							Name:                     "space-2",
   536  							AllowSSH:                 true,
   537  							SpaceQuotaDefinitionGUID: "some-space-quota-guid-2",
   538  						},
   539  						{
   540  							GUID:                     "space-guid-3",
   541  							OrganizationGUID:         "org-guid-3",
   542  							Name:                     "space-3",
   543  							AllowSSH:                 false,
   544  							SpaceQuotaDefinitionGUID: "some-space-quota-guid-3",
   545  						},
   546  						{
   547  							GUID:                     "space-guid-4",
   548  							OrganizationGUID:         "org-guid-4",
   549  							Name:                     "space-4",
   550  							AllowSSH:                 true,
   551  							SpaceQuotaDefinitionGUID: "some-space-quota-guid-4",
   552  						},
   553  					}))
   554  					Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
   555  				})
   556  			})
   557  		})
   558  
   559  		When("an error is encountered", func() {
   560  			BeforeEach(func() {
   561  				response := `{
   562    "code": 10001,
   563    "description": "Some Error",
   564    "error_code": "CF-SomeError"
   565  }`
   566  				server.AppendHandlers(
   567  					CombineHandlers(
   568  						VerifyRequest(http.MethodGet, "/v2/security_groups/security-group-guid/staging_spaces"),
   569  						RespondWith(http.StatusTeapot, response, http.Header{"X-Cf-Warnings": {"warning-1, warning-2"}}),
   570  					))
   571  			})
   572  
   573  			It("returns an error and all warnings", func() {
   574  				_, warnings, err := client.GetSecurityGroupStagingSpaces("security-group-guid")
   575  
   576  				Expect(err).To(MatchError(ccerror.V2UnexpectedResponseError{
   577  					ResponseCode: http.StatusTeapot,
   578  					V2ErrorResponse: ccerror.V2ErrorResponse{
   579  						Code:        10001,
   580  						Description: "Some Error",
   581  						ErrorCode:   "CF-SomeError",
   582  					},
   583  				}))
   584  				Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
   585  			})
   586  		})
   587  	})
   588  
   589  	Describe("UpdateSpaceDeveloper", func() {
   590  		var (
   591  			executeErr error
   592  			warnings   Warnings
   593  		)
   594  
   595  		JustBeforeEach(func() {
   596  			warnings, executeErr = client.UpdateSpaceDeveloper("some-space-guid", "some-uaa-id")
   597  		})
   598  
   599  		When("no errors are encountered", func() {
   600  			BeforeEach(func() {
   601  				jsonResponse := `{
   602  				"metadata": {
   603  					"guid": "some-space-guid"
   604  				},
   605  				"entity": {
   606  					"name": "some-space-name"
   607  				}
   608  				}`
   609  
   610  				server.AppendHandlers(
   611  					CombineHandlers(
   612  						VerifyRequest(http.MethodPut, "/v2/spaces/some-space-guid/developers/some-uaa-id"),
   613  						RespondWith(http.StatusCreated, jsonResponse, http.Header{"X-Cf-Warnings": {"warning-1, warning-2"}}),
   614  					))
   615  			})
   616  
   617  			It("makes the user a space developer and returns warnings", func() {
   618  				Expect(executeErr).ToNot(HaveOccurred())
   619  				Expect(warnings).To(ConsistOf(Warnings{"warning-1", "warning-2"}))
   620  			})
   621  		})
   622  
   623  		When("the server errors", func() {
   624  			BeforeEach(func() {
   625  				jsonResponse := `{
   626  							"code": 10001,
   627  							"description": "Some Error",
   628  							"error_code": "CF-SomeError"
   629  						  }`
   630  
   631  				server.AppendHandlers(
   632  					CombineHandlers(
   633  						VerifyRequest(http.MethodPut, "/v2/spaces/some-space-guid/developers/some-uaa-id"),
   634  						RespondWith(http.StatusTeapot, jsonResponse, http.Header{"X-Cf-Warnings": {"warning-1, warning-2"}}),
   635  					))
   636  			})
   637  
   638  			It("returns the error and all warnings", func() {
   639  				Expect(executeErr).To(MatchError(ccerror.V2UnexpectedResponseError{
   640  					ResponseCode: http.StatusTeapot,
   641  					V2ErrorResponse: ccerror.V2ErrorResponse{
   642  						Code:        10001,
   643  						Description: "Some Error",
   644  						ErrorCode:   "CF-SomeError",
   645  					},
   646  				}))
   647  				Expect(warnings).To(ConsistOf(Warnings{"warning-1", "warning-2"}))
   648  			})
   649  		})
   650  	})
   651  	Describe("UpdateSpaceDeveloperByUsername", func() {
   652  		var (
   653  			executeErr error
   654  			warnings   Warnings
   655  		)
   656  
   657  		JustBeforeEach(func() {
   658  			warnings, executeErr = client.UpdateSpaceDeveloperByUsername("some-space-guid", "user@example.com")
   659  		})
   660  
   661  		When("no errors are encountered", func() {
   662  			BeforeEach(func() {
   663  				jsonResponse := `{
   664  				"metadata": {
   665  					"guid": "some-space-guid"
   666  				},
   667  				"entity": {
   668  					"name": "some-space-name",
   669  					"organization_guid": "some-org-guid",
   670  					"space_quota_definition_guid": null,
   671  					"allow_ssh": true
   672  				}
   673  				}`
   674  
   675  				requestBody := map[string]interface{}{
   676  					"username": "user@example.com",
   677  				}
   678  
   679  				server.AppendHandlers(
   680  					CombineHandlers(
   681  						VerifyRequest(http.MethodPut, "/v2/spaces/some-space-guid/developers"),
   682  						VerifyJSONRepresenting(requestBody),
   683  						RespondWith(http.StatusAccepted, jsonResponse, http.Header{"X-Cf-Warnings": {"warning-1, warning-2"}}),
   684  					))
   685  			})
   686  
   687  			It("makes the user a space developer and returns warnings", func() {
   688  				Expect(server.ReceivedRequests()).To(HaveLen(2))
   689  				Expect(executeErr).ToNot(HaveOccurred())
   690  				Expect(warnings).To(ConsistOf(Warnings{"warning-1", "warning-2"}))
   691  			})
   692  		})
   693  
   694  		When("the server errors", func() {
   695  			BeforeEach(func() {
   696  				jsonResponse := `{
   697  					"code": 10001,
   698  					"description": "Some Error",
   699  					"error_code": "CF-SomeError"
   700  				  }`
   701  
   702  				server.AppendHandlers(
   703  					CombineHandlers(
   704  						VerifyRequest(http.MethodPut, "/v2/spaces/some-space-guid/developers"),
   705  						RespondWith(http.StatusTeapot, jsonResponse, http.Header{"X-Cf-Warnings": {"warning-1, warning-2"}}),
   706  					))
   707  			})
   708  
   709  			It("returns the error and all warnings", func() {
   710  				Expect(executeErr).To(MatchError(ccerror.V2UnexpectedResponseError{
   711  					ResponseCode: http.StatusTeapot,
   712  					V2ErrorResponse: ccerror.V2ErrorResponse{
   713  						Code:        10001,
   714  						Description: "Some Error",
   715  						ErrorCode:   "CF-SomeError",
   716  					},
   717  				}))
   718  				Expect(warnings).To(ConsistOf(Warnings{"warning-1", "warning-2"}))
   719  			})
   720  		})
   721  	})
   722  
   723  	Describe("UpdateSpaceManager", func() {
   724  		var (
   725  			warnings   Warnings
   726  			executeErr error
   727  		)
   728  		JustBeforeEach(func() {
   729  			warnings, executeErr = client.UpdateSpaceManager("some-space-guid", "some-uaa-id")
   730  		})
   731  
   732  		When("no errors are encountered", func() {
   733  			BeforeEach(func() {
   734  				server.AppendHandlers(
   735  					CombineHandlers(
   736  						VerifyRequest(http.MethodPut, "/v2/spaces/some-space-guid/managers/some-uaa-id"),
   737  						RespondWith(http.StatusCreated, `{}`, http.Header{"X-Cf-Warnings": {"warning-1, warning-2"}}),
   738  					))
   739  			})
   740  
   741  			It("makes the user a space developer and returns warnings", func() {
   742  				Expect(executeErr).ToNot(HaveOccurred())
   743  				Expect(warnings).To(ConsistOf(Warnings{"warning-1", "warning-2"}))
   744  			})
   745  		})
   746  
   747  		When("an error is encountered", func() {
   748  			BeforeEach(func() {
   749  				jsonResponse := `{
   750  					"code": 10001,
   751  					"description": "Some Error",
   752  					"error_code": "CF-SomeError"
   753  				  }`
   754  
   755  				server.AppendHandlers(
   756  					CombineHandlers(
   757  						VerifyRequest(http.MethodPut, "/v2/spaces/some-space-guid/managers/some-uaa-id"),
   758  						RespondWith(http.StatusTeapot, jsonResponse, http.Header{"X-Cf-Warnings": {"warning-1, warning-2"}}),
   759  					))
   760  			})
   761  
   762  			It("returns the error and warnings", func() {
   763  				Expect(executeErr).To(MatchError(ccerror.V2UnexpectedResponseError{
   764  					ResponseCode: http.StatusTeapot,
   765  					V2ErrorResponse: ccerror.V2ErrorResponse{
   766  						Code:        10001,
   767  						Description: "Some Error",
   768  						ErrorCode:   "CF-SomeError",
   769  					},
   770  				}))
   771  				Expect(warnings).To(ConsistOf(Warnings{"warning-1", "warning-2"}))
   772  			})
   773  		})
   774  	})
   775  
   776  	Describe("UpdateSpaceManagerByUsername", func() {
   777  		When("no errors are encountered", func() {
   778  			BeforeEach(func() {
   779  				jsonResponse := `{
   780  					"metadata": {
   781  					  "guid": "some-space-guid"
   782  					},
   783  					"entity": {
   784  					  "name": "some-space-name",
   785  					  "organization_guid": "some-org-guid",
   786  					  "space_quota_definition_guid": null,
   787  					  "allow_ssh": true
   788  					}
   789  				  }`
   790  
   791  				requestBody := map[string]interface{}{
   792  					"username": "user@example.com",
   793  				}
   794  
   795  				server.AppendHandlers(
   796  					CombineHandlers(
   797  						VerifyRequest(http.MethodPut, "/v2/spaces/some-space-guid/managers"),
   798  						VerifyJSONRepresenting(requestBody),
   799  						RespondWith(http.StatusAccepted, jsonResponse, http.Header{"X-Cf-Warnings": {"warning-1, warning-2"}}),
   800  					))
   801  			})
   802  
   803  			It("grants the permission and returns all warnings", func() {
   804  				warnings, err := client.UpdateSpaceManagerByUsername("some-space-guid", "user@example.com")
   805  
   806  				Expect(err).NotTo(HaveOccurred())
   807  				Expect(warnings).To(ConsistOf(Warnings{"warning-1", "warning-2"}))
   808  			})
   809  		})
   810  
   811  		When("an error is encountered", func() {
   812  			BeforeEach(func() {
   813  				jsonResponse := `{
   814  					"code": 10001,
   815  					"description": "Some Error",
   816  					"error_code": "CF-SomeError"
   817  				  }`
   818  
   819  				server.AppendHandlers(
   820  					CombineHandlers(
   821  						VerifyRequest(http.MethodPut, "/v2/spaces/some-space-guid/managers"),
   822  						RespondWith(http.StatusTeapot, jsonResponse, http.Header{"X-Cf-Warnings": {"warning-1, warning-2"}}),
   823  					))
   824  			})
   825  
   826  			It("grants the permission and returns all warnings", func() {
   827  				warnings, err := client.UpdateSpaceManagerByUsername("some-space-guid", "user@example.com")
   828  
   829  				Expect(err).To(MatchError(ccerror.V2UnexpectedResponseError{
   830  					ResponseCode: http.StatusTeapot,
   831  					V2ErrorResponse: ccerror.V2ErrorResponse{
   832  						Code:        10001,
   833  						Description: "Some Error",
   834  						ErrorCode:   "CF-SomeError",
   835  					},
   836  				}))
   837  				Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
   838  			})
   839  
   840  		})
   841  	})
   842  })