github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/api/cloudcontroller/ccv2/application_test.go (about)

     1  package ccv2_test
     2  
     3  import (
     4  	"net/http"
     5  	"time"
     6  
     7  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
     8  	. "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2"
     9  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/constant"
    10  	"code.cloudfoundry.org/cli/types"
    11  	. "github.com/onsi/ginkgo"
    12  	. "github.com/onsi/gomega"
    13  	. "github.com/onsi/gomega/ghttp"
    14  )
    15  
    16  var _ = Describe("Application", func() {
    17  	var client *Client
    18  
    19  	BeforeEach(func() {
    20  		client = NewTestClient()
    21  	})
    22  
    23  	Describe("CreateApplication", func() {
    24  		Context("when the update is successful", func() {
    25  			Context("when setting the minimum", func() { // are we **only** encoding the things we want
    26  				BeforeEach(func() {
    27  					response := `
    28  						{
    29  							"metadata": {
    30  								"guid": "some-app-guid"
    31  							},
    32  							"entity": {
    33  								"name": "some-app-name",
    34  								"space_guid": "some-space-guid"
    35  							}
    36  						}`
    37  					requestBody := map[string]string{
    38  						"name":       "some-app-name",
    39  						"space_guid": "some-space-guid",
    40  					}
    41  					server.AppendHandlers(
    42  						CombineHandlers(
    43  							VerifyRequest(http.MethodPost, "/v2/apps"),
    44  							VerifyJSONRepresenting(requestBody),
    45  							RespondWith(http.StatusCreated, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}),
    46  						),
    47  					)
    48  				})
    49  
    50  				It("returns the created object and warnings", func() {
    51  					app, warnings, err := client.CreateApplication(Application{
    52  						Name:      "some-app-name",
    53  						SpaceGUID: "some-space-guid",
    54  					})
    55  					Expect(err).NotTo(HaveOccurred())
    56  
    57  					Expect(app).To(Equal(Application{
    58  						GUID: "some-app-guid",
    59  						Name: "some-app-name",
    60  					}))
    61  					Expect(warnings).To(ConsistOf(Warnings{"this is a warning"}))
    62  				})
    63  			})
    64  		})
    65  
    66  		Context("when the create returns an error", func() {
    67  			BeforeEach(func() {
    68  				response := `
    69  					{
    70  						"description": "Request invalid due to parse error: Field: name, Error: Missing field name, Field: space_guid, Error: Missing field space_guid",
    71  						"error_code": "CF-MessageParseError",
    72  						"code": 1001
    73  					}
    74  			`
    75  				server.AppendHandlers(
    76  					CombineHandlers(
    77  						VerifyRequest(http.MethodPost, "/v2/apps"),
    78  						RespondWith(http.StatusBadRequest, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}),
    79  					),
    80  				)
    81  			})
    82  
    83  			It("returns the error and warnings", func() {
    84  				_, warnings, err := client.CreateApplication(Application{})
    85  				Expect(err).To(MatchError(ccerror.BadRequestError{Message: "Request invalid due to parse error: Field: name, Error: Missing field name, Field: space_guid, Error: Missing field space_guid"}))
    86  				Expect(warnings).To(ConsistOf(Warnings{"this is a warning"}))
    87  			})
    88  		})
    89  	})
    90  
    91  	Describe("GetApplication", func() {
    92  		BeforeEach(func() {
    93  			response := `{
    94  						"metadata": {
    95  							"guid": "app-guid-1",
    96  							"updated_at": null
    97  						},
    98  						"entity": {
    99  							"buildpack": "ruby 1.6.29",
   100  							"command": "some-command",
   101  							"detected_start_command": "echo 'I am a banana'",
   102  							"disk_quota": 586,
   103  							"detected_buildpack": null,
   104  							"docker_credentials": {
   105  								"username": "docker-username",
   106  								"password": "docker-password"
   107  							},
   108  							"docker_image": "some-docker-path",
   109  							"environment_json": {
   110  								"key1": "val1",
   111  								"key2": 83493475092347,
   112  								"key3": true,
   113  								"key4": 75821.521
   114  							},
   115  							"health_check_timeout": 120,
   116  							"health_check_type": "port",
   117  							"health_check_http_endpoint": "/",
   118  							"instances": 13,
   119  							"memory": 1024,
   120  							"name": "app-name-1",
   121  							"package_state": "FAILED",
   122  							"package_updated_at": "2015-03-10T23:11:54Z",
   123  							"stack_guid": "some-stack-guid",
   124  							"staging_failed_description": "some-staging-failed-description",
   125  							"staging_failed_reason": "some-reason",
   126  							"state": "STOPPED"
   127  						}
   128  			}`
   129  			server.AppendHandlers(
   130  				CombineHandlers(
   131  					VerifyRequest(http.MethodGet, "/v2/apps/app-guid-1"),
   132  					RespondWith(http.StatusOK, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}),
   133  				),
   134  			)
   135  		})
   136  
   137  		Context("when apps exist", func() {
   138  			It("returns the app", func() {
   139  				app, warnings, err := client.GetApplication("app-guid-1")
   140  				Expect(err).NotTo(HaveOccurred())
   141  
   142  				updatedAt, err := time.Parse(time.RFC3339, "2015-03-10T23:11:54Z")
   143  				Expect(err).NotTo(HaveOccurred())
   144  
   145  				Expect(app).To(Equal(Application{
   146  					Buildpack:            types.FilteredString{IsSet: true, Value: "ruby 1.6.29"},
   147  					Command:              types.FilteredString{IsSet: true, Value: "some-command"},
   148  					DetectedBuildpack:    types.FilteredString{},
   149  					DetectedStartCommand: types.FilteredString{IsSet: true, Value: "echo 'I am a banana'"},
   150  					DiskQuota:            types.NullByteSizeInMb{IsSet: true, Value: 586},
   151  					DockerCredentials: DockerCredentials{
   152  						Username: "docker-username",
   153  						Password: "docker-password",
   154  					},
   155  					DockerImage: "some-docker-path",
   156  					EnvironmentVariables: map[string]string{
   157  						"key1": "val1",
   158  						"key2": "83493475092347",
   159  						"key3": "true",
   160  						"key4": "75821.521",
   161  					},
   162  					GUID:                     "app-guid-1",
   163  					HealthCheckTimeout:       120,
   164  					HealthCheckType:          "port",
   165  					HealthCheckHTTPEndpoint:  "/",
   166  					Instances:                types.NullInt{Value: 13, IsSet: true},
   167  					Memory:                   types.NullByteSizeInMb{IsSet: true, Value: 1024},
   168  					Name:                     "app-name-1",
   169  					PackageState:             constant.ApplicationPackageFailed,
   170  					PackageUpdatedAt:         updatedAt,
   171  					StackGUID:                "some-stack-guid",
   172  					StagingFailedDescription: "some-staging-failed-description",
   173  					StagingFailedReason:      "some-reason",
   174  					State:                    constant.ApplicationStopped,
   175  				}))
   176  				Expect(warnings).To(ConsistOf(Warnings{"this is a warning"}))
   177  			})
   178  		})
   179  	})
   180  
   181  	Describe("GetApplications", func() {
   182  		BeforeEach(func() {
   183  			response1 := `{
   184  				"next_url": "/v2/apps?q=space_guid:some-space-guid&page=2",
   185  				"resources": [
   186  					{
   187  						"metadata": {
   188  							"guid": "app-guid-1",
   189  							"updated_at": null
   190  						},
   191  						"entity": {
   192  							"buildpack": "ruby 1.6.29",
   193  							"detected_start_command": "echo 'I am a banana'",
   194  							"disk_quota": 586,
   195  							"detected_buildpack": null,
   196  							"health_check_type": "port",
   197  							"health_check_http_endpoint": "/",
   198  							"instances": 13,
   199  							"memory": 1024,
   200  							"name": "app-name-1",
   201  							"package_state": "FAILED",
   202  							"package_updated_at": "2015-03-10T23:11:54Z",
   203  							"stack_guid": "some-stack-guid",
   204  							"staging_failed_reason": "some-reason",
   205  							"state": "STOPPED"
   206  						}
   207  					},
   208  					{
   209  						"metadata": {
   210  							"guid": "app-guid-2",
   211  							"updated_at": null
   212  						},
   213  						"entity": {
   214  							"name": "app-name-2",
   215  							"detected_buildpack": "ruby 1.6.29",
   216  							"package_updated_at": null
   217  						}
   218  					}
   219  				]
   220  			}`
   221  			response2 := `{
   222  				"next_url": null,
   223  				"resources": [
   224  					{
   225  						"metadata": {
   226  							"guid": "app-guid-3",
   227  							"updated_at": null
   228  						},
   229  						"entity": {
   230  							"name": "app-name-3"
   231  						}
   232  					},
   233  					{
   234  						"metadata": {
   235  							"guid": "app-guid-4",
   236  							"updated_at": null
   237  						},
   238  						"entity": {
   239  							"name": "app-name-4"
   240  						}
   241  					}
   242  				]
   243  			}`
   244  			server.AppendHandlers(
   245  				CombineHandlers(
   246  					VerifyRequest(http.MethodGet, "/v2/apps", "q=space_guid:some-space-guid"),
   247  					RespondWith(http.StatusOK, response1, http.Header{"X-Cf-Warnings": {"this is a warning"}}),
   248  				),
   249  			)
   250  			server.AppendHandlers(
   251  				CombineHandlers(
   252  					VerifyRequest(http.MethodGet, "/v2/apps", "q=space_guid:some-space-guid&page=2"),
   253  					RespondWith(http.StatusOK, response2, http.Header{"X-Cf-Warnings": {"this is another warning"}}),
   254  				),
   255  			)
   256  		})
   257  
   258  		Context("when apps exist", func() {
   259  			It("returns all the queried apps", func() {
   260  				apps, warnings, err := client.GetApplications(Filter{
   261  					Type:     constant.SpaceGUIDFilter,
   262  					Operator: constant.EqualOperator,
   263  					Values:   []string{"some-space-guid"},
   264  				})
   265  				Expect(err).NotTo(HaveOccurred())
   266  
   267  				updatedAt, err := time.Parse(time.RFC3339, "2015-03-10T23:11:54Z")
   268  				Expect(err).NotTo(HaveOccurred())
   269  
   270  				Expect(apps).To(ConsistOf([]Application{
   271  					{
   272  						Buildpack:               types.FilteredString{IsSet: true, Value: "ruby 1.6.29"},
   273  						DetectedBuildpack:       types.FilteredString{},
   274  						DetectedStartCommand:    types.FilteredString{IsSet: true, Value: "echo 'I am a banana'"},
   275  						DiskQuota:               types.NullByteSizeInMb{IsSet: true, Value: 586},
   276  						GUID:                    "app-guid-1",
   277  						HealthCheckType:         "port",
   278  						HealthCheckHTTPEndpoint: "/",
   279  						Instances:               types.NullInt{Value: 13, IsSet: true},
   280  						Memory:                  types.NullByteSizeInMb{IsSet: true, Value: 1024},
   281  						Name:                    "app-name-1",
   282  						PackageState:            constant.ApplicationPackageFailed,
   283  						PackageUpdatedAt:        updatedAt,
   284  						StackGUID:               "some-stack-guid",
   285  						StagingFailedReason:     "some-reason",
   286  						State:                   constant.ApplicationStopped,
   287  					},
   288  					{
   289  						Name:              "app-name-2",
   290  						GUID:              "app-guid-2",
   291  						DetectedBuildpack: types.FilteredString{IsSet: true, Value: "ruby 1.6.29"},
   292  					},
   293  					{Name: "app-name-3", GUID: "app-guid-3"},
   294  					{Name: "app-name-4", GUID: "app-guid-4"},
   295  				}))
   296  				Expect(warnings).To(ConsistOf(Warnings{"this is a warning", "this is another warning"}))
   297  			})
   298  		})
   299  	})
   300  
   301  	Describe("UpdateApplication", func() {
   302  		Context("when the update is successful", func() {
   303  			Context("when updating all fields", func() { //are we encoding everything correctly?
   304  				BeforeEach(func() {
   305  					response1 := `{
   306  				"metadata": {
   307  					"guid": "some-app-guid",
   308  					"updated_at": null
   309  				},
   310  				"entity": {
   311  					"detected_start_command": "echo 'I am a banana'",
   312  					"disk_quota": 586,
   313  					"detected_buildpack": null,
   314  					"docker_credentials": {
   315  						"username": "docker-username",
   316  						"password": "docker-password"
   317  					},
   318  					"docker_image": "some-docker-path",
   319  					"environment_json": {
   320  						"key1": "val1",
   321  						"key2": 83493475092347,
   322  						"key3": true,
   323  						"key4": 75821.521
   324  					},
   325  					"health_check_timeout": 120,
   326  					"health_check_type": "some-health-check-type",
   327  					"health_check_http_endpoint": "/anything",
   328  					"instances": 0,
   329  					"memory": 1024,
   330  					"name": "app-name-1",
   331  					"package_updated_at": "2015-03-10T23:11:54Z",
   332  					"stack_guid": "some-stack-guid",
   333  					"state": "STARTED"
   334  				}
   335  			}`
   336  					expectedBody := map[string]interface{}{
   337  						"buildpack":  "",
   338  						"command":    "",
   339  						"disk_quota": 0,
   340  						"docker_credentials": map[string]string{
   341  							"username": "docker-username",
   342  							"password": "docker-password",
   343  						},
   344  						"docker_image": "some-docker-path",
   345  						"environment_json": map[string]string{
   346  							"key1": "val1",
   347  							"key2": "83493475092347",
   348  							"key3": "true",
   349  							"key4": "75821.521",
   350  						},
   351  						"health_check_http_endpoint": "/anything",
   352  						"health_check_type":          "some-health-check-type",
   353  						"instances":                  0,
   354  						"memory":                     0,
   355  						"stack_guid":                 "some-stack-guid",
   356  						"state":                      "STARTED",
   357  					}
   358  
   359  					server.AppendHandlers(
   360  						CombineHandlers(
   361  							VerifyRequest(http.MethodPut, "/v2/apps/some-app-guid"),
   362  							VerifyJSONRepresenting(expectedBody),
   363  							RespondWith(http.StatusCreated, response1, http.Header{"X-Cf-Warnings": {"this is a warning"}}),
   364  						),
   365  					)
   366  				})
   367  
   368  				It("returns the updated object and warnings and sends all updated field", func() {
   369  					app, warnings, err := client.UpdateApplication(Application{
   370  						Buildpack: types.FilteredString{IsSet: true, Value: ""},
   371  						Command:   types.FilteredString{IsSet: true, Value: ""},
   372  						DiskQuota: types.NullByteSizeInMb{IsSet: true},
   373  						DockerCredentials: DockerCredentials{
   374  							Username: "docker-username",
   375  							Password: "docker-password",
   376  						},
   377  						DockerImage: "some-docker-path",
   378  						EnvironmentVariables: map[string]string{
   379  							"key1": "val1",
   380  							"key2": "83493475092347",
   381  							"key3": "true",
   382  							"key4": "75821.521",
   383  						},
   384  						GUID: "some-app-guid",
   385  						HealthCheckHTTPEndpoint: "/anything",
   386  						HealthCheckType:         "some-health-check-type",
   387  						Instances:               types.NullInt{Value: 0, IsSet: true},
   388  						Memory:                  types.NullByteSizeInMb{IsSet: true},
   389  						StackGUID:               "some-stack-guid",
   390  						State:                   constant.ApplicationStarted,
   391  					})
   392  					Expect(err).NotTo(HaveOccurred())
   393  
   394  					updatedAt, err := time.Parse(time.RFC3339, "2015-03-10T23:11:54Z")
   395  					Expect(err).NotTo(HaveOccurred())
   396  
   397  					Expect(app).To(Equal(Application{
   398  						DetectedBuildpack:    types.FilteredString{},
   399  						DetectedStartCommand: types.FilteredString{IsSet: true, Value: "echo 'I am a banana'"},
   400  						DiskQuota:            types.NullByteSizeInMb{IsSet: true, Value: 586},
   401  						DockerCredentials: DockerCredentials{
   402  							Username: "docker-username",
   403  							Password: "docker-password",
   404  						},
   405  						DockerImage: "some-docker-path",
   406  						EnvironmentVariables: map[string]string{
   407  							"key1": "val1",
   408  							"key2": "83493475092347",
   409  							"key3": "true",
   410  							"key4": "75821.521",
   411  						},
   412  						GUID: "some-app-guid",
   413  						HealthCheckHTTPEndpoint: "/anything",
   414  						HealthCheckTimeout:      120,
   415  						HealthCheckType:         "some-health-check-type",
   416  						Instances:               types.NullInt{Value: 0, IsSet: true},
   417  						Memory:                  types.NullByteSizeInMb{IsSet: true, Value: 1024},
   418  						Name:                    "app-name-1",
   419  						PackageUpdatedAt:        updatedAt,
   420  						StackGUID:               "some-stack-guid",
   421  						State:                   constant.ApplicationStarted,
   422  					}))
   423  					Expect(warnings).To(ConsistOf(Warnings{"this is a warning"}))
   424  				})
   425  			})
   426  
   427  			Context("when only updating one field", func() { // are we **only** encoding the things we want
   428  				BeforeEach(func() {
   429  					response1 := `{
   430  				"metadata": {
   431  					"guid": "some-app-guid",
   432  					"updated_at": null
   433  				},
   434  				"entity": {
   435  					"buildpack": "ruby 1.6.29",
   436  					"detected_start_command": "echo 'I am a banana'",
   437  					"disk_quota": 586,
   438  					"detected_buildpack": null,
   439  					"health_check_type": "some-health-check-type",
   440  					"health_check_http_endpoint": "/",
   441  					"instances": 7,
   442  					"memory": 1024,
   443  					"name": "app-name-1",
   444  					"package_updated_at": "2015-03-10T23:11:54Z",
   445  					"stack_guid": "some-stack-guid",
   446  					"state": "STOPPED"
   447  				}
   448  			}`
   449  					server.AppendHandlers(
   450  						CombineHandlers(
   451  							VerifyRequest(http.MethodPut, "/v2/apps/some-app-guid"),
   452  							VerifyBody([]byte(`{"instances":7}`)),
   453  							RespondWith(http.StatusCreated, response1, http.Header{"X-Cf-Warnings": {"this is a warning"}}),
   454  						),
   455  					)
   456  				})
   457  
   458  				It("returns the updated object and warnings and sends only updated field", func() {
   459  					app, warnings, err := client.UpdateApplication(Application{
   460  						GUID:      "some-app-guid",
   461  						Instances: types.NullInt{IsSet: true, Value: 7},
   462  					})
   463  					Expect(err).NotTo(HaveOccurred())
   464  
   465  					updatedAt, err := time.Parse(time.RFC3339, "2015-03-10T23:11:54Z")
   466  					Expect(err).NotTo(HaveOccurred())
   467  
   468  					Expect(app).To(Equal(Application{
   469  						Buildpack:               types.FilteredString{IsSet: true, Value: "ruby 1.6.29"},
   470  						DetectedBuildpack:       types.FilteredString{},
   471  						DetectedStartCommand:    types.FilteredString{IsSet: true, Value: "echo 'I am a banana'"},
   472  						DiskQuota:               types.NullByteSizeInMb{IsSet: true, Value: 586},
   473  						GUID:                    "some-app-guid",
   474  						HealthCheckType:         "some-health-check-type",
   475  						HealthCheckHTTPEndpoint: "/",
   476  						Instances:               types.NullInt{Value: 7, IsSet: true},
   477  						Memory:                  types.NullByteSizeInMb{IsSet: true, Value: 1024},
   478  						Name:                    "app-name-1",
   479  						PackageUpdatedAt:        updatedAt,
   480  						StackGUID:               "some-stack-guid",
   481  						State:                   constant.ApplicationStopped,
   482  					}))
   483  					Expect(warnings).To(ConsistOf(Warnings{"this is a warning"}))
   484  				})
   485  			})
   486  		})
   487  
   488  		Context("when the update returns an error", func() {
   489  			BeforeEach(func() {
   490  				response := `
   491  {
   492    "code": 210002,
   493    "description": "The app could not be found: some-app-guid",
   494    "error_code": "CF-AppNotFound"
   495  }
   496  			`
   497  				server.AppendHandlers(
   498  					CombineHandlers(
   499  						VerifyRequest(http.MethodPut, "/v2/apps/some-app-guid"),
   500  						// VerifyBody([]byte(`{"health_check_type":"some-health-check-type"}`)),
   501  						RespondWith(http.StatusNotFound, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}),
   502  					),
   503  				)
   504  			})
   505  
   506  			It("returns the error and warnings", func() {
   507  				_, warnings, err := client.UpdateApplication(Application{
   508  					GUID:            "some-app-guid",
   509  					HealthCheckType: "some-health-check-type",
   510  				})
   511  				Expect(err).To(MatchError(ccerror.ResourceNotFoundError{Message: "The app could not be found: some-app-guid"}))
   512  				Expect(warnings).To(ConsistOf(Warnings{"this is a warning"}))
   513  			})
   514  		})
   515  	})
   516  
   517  	Describe("RestageApplication", func() {
   518  		Context("when the restage is successful", func() {
   519  			BeforeEach(func() {
   520  				response := `{
   521  					"metadata": {
   522  						"guid": "some-app-guid",
   523  						"url": "/v2/apps/some-app-guid"
   524  					},
   525  					"entity": {
   526  						"buildpack": "ruby 1.6.29",
   527  						"detected_start_command": "echo 'I am a banana'",
   528  						"disk_quota": 586,
   529  						"detected_buildpack": null,
   530  						"docker_image": "some-docker-path",
   531  						"health_check_type": "some-health-check-type",
   532  						"health_check_http_endpoint": "/anything",
   533  						"instances": 13,
   534  						"memory": 1024,
   535  						"name": "app-name-1",
   536  						"package_updated_at": "2015-03-10T23:11:54Z",
   537  						"stack_guid": "some-stack-guid",
   538  						"state": "STARTED"
   539  					}
   540  				}`
   541  
   542  				server.AppendHandlers(
   543  					CombineHandlers(
   544  						VerifyRequest(http.MethodPost, "/v2/apps/some-app-guid/restage"),
   545  						RespondWith(http.StatusCreated, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}),
   546  					),
   547  				)
   548  			})
   549  
   550  			It("returns the updated object and warnings and sends all updated field", func() {
   551  				app, warnings, err := client.RestageApplication(Application{
   552  					DockerImage:             "some-docker-path",
   553  					GUID:                    "some-app-guid",
   554  					HealthCheckType:         "some-health-check-type",
   555  					HealthCheckHTTPEndpoint: "/anything",
   556  					State: constant.ApplicationStarted,
   557  				})
   558  				Expect(err).NotTo(HaveOccurred())
   559  
   560  				updatedAt, err := time.Parse(time.RFC3339, "2015-03-10T23:11:54Z")
   561  				Expect(err).NotTo(HaveOccurred())
   562  
   563  				Expect(app).To(Equal(Application{
   564  					Buildpack:               types.FilteredString{IsSet: true, Value: "ruby 1.6.29"},
   565  					DetectedBuildpack:       types.FilteredString{},
   566  					DetectedStartCommand:    types.FilteredString{IsSet: true, Value: "echo 'I am a banana'"},
   567  					DiskQuota:               types.NullByteSizeInMb{IsSet: true, Value: 586},
   568  					DockerImage:             "some-docker-path",
   569  					GUID:                    "some-app-guid",
   570  					HealthCheckType:         "some-health-check-type",
   571  					HealthCheckHTTPEndpoint: "/anything",
   572  					Instances:               types.NullInt{Value: 13, IsSet: true},
   573  					Memory:                  types.NullByteSizeInMb{IsSet: true, Value: 1024},
   574  					Name:                    "app-name-1",
   575  					PackageUpdatedAt:        updatedAt,
   576  					StackGUID:               "some-stack-guid",
   577  					State:                   constant.ApplicationStarted,
   578  				}))
   579  				Expect(warnings).To(ConsistOf(Warnings{"this is a warning"}))
   580  			})
   581  		})
   582  
   583  		Context("when the restage returns an error", func() {
   584  			BeforeEach(func() {
   585  				response := `
   586  {
   587    "code": 210002,
   588    "description": "The app could not be found: some-app-guid",
   589    "error_code": "CF-AppNotFound"
   590  }
   591  			`
   592  				server.AppendHandlers(
   593  					CombineHandlers(
   594  						VerifyRequest(http.MethodPost, "/v2/apps/some-app-guid/restage"),
   595  						RespondWith(http.StatusNotFound, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}),
   596  					),
   597  				)
   598  			})
   599  
   600  			It("returns the error and warnings", func() {
   601  				_, warnings, err := client.RestageApplication(Application{
   602  					GUID:            "some-app-guid",
   603  					HealthCheckType: "some-health-check-type",
   604  				})
   605  				Expect(err).To(MatchError(ccerror.ResourceNotFoundError{Message: "The app could not be found: some-app-guid"}))
   606  				Expect(warnings).To(ConsistOf(Warnings{"this is a warning"}))
   607  			})
   608  		})
   609  	})
   610  
   611  	Describe("GetRouteApplications", func() {
   612  		Context("when the route guid is not found", func() {
   613  			BeforeEach(func() {
   614  				response := `
   615  {
   616    "code": 210002,
   617    "description": "The route could not be found: some-route-guid",
   618    "error_code": "CF-RouteNotFound"
   619  }
   620  			`
   621  				server.AppendHandlers(
   622  					CombineHandlers(
   623  						VerifyRequest(http.MethodGet, "/v2/routes/some-route-guid/apps"),
   624  						RespondWith(http.StatusNotFound, response),
   625  					),
   626  				)
   627  			})
   628  
   629  			It("returns an error", func() {
   630  				_, _, err := client.GetRouteApplications("some-route-guid")
   631  				Expect(err).To(MatchError(ccerror.ResourceNotFoundError{
   632  					Message: "The route could not be found: some-route-guid",
   633  				}))
   634  			})
   635  		})
   636  
   637  		Context("when there are applications associated with this route", func() {
   638  			BeforeEach(func() {
   639  				response1 := `{
   640  				"next_url": "/v2/routes/some-route-guid/apps?q=space_guid:some-space-guid&page=2",
   641  				"resources": [
   642  					{
   643  						"metadata": {
   644  							"guid": "app-guid-1",
   645  							"updated_at": null
   646  						},
   647  						"entity": {
   648  							"name": "app-name-1"
   649  						}
   650  					},
   651  					{
   652  						"metadata": {
   653  							"guid": "app-guid-2",
   654  							"updated_at": null
   655  						},
   656  						"entity": {
   657  							"name": "app-name-2"
   658  						}
   659  					}
   660  				]
   661  			}`
   662  				response2 := `{
   663  				"next_url": null,
   664  				"resources": [
   665  					{
   666  						"metadata": {
   667  							"guid": "app-guid-3",
   668  							"updated_at": null
   669  						},
   670  						"entity": {
   671  							"name": "app-name-3"
   672  						}
   673  					},
   674  					{
   675  						"metadata": {
   676  							"guid": "app-guid-4",
   677  							"updated_at": null
   678  						},
   679  						"entity": {
   680  							"name": "app-name-4"
   681  						}
   682  					}
   683  				]
   684  			}`
   685  				server.AppendHandlers(
   686  					CombineHandlers(
   687  						VerifyRequest(http.MethodGet, "/v2/routes/some-route-guid/apps", "q=space_guid:some-space-guid"),
   688  						RespondWith(http.StatusOK, response1, http.Header{"X-Cf-Warnings": {"this is a warning"}}),
   689  					),
   690  				)
   691  				server.AppendHandlers(
   692  					CombineHandlers(
   693  						VerifyRequest(http.MethodGet, "/v2/routes/some-route-guid/apps", "q=space_guid:some-space-guid&page=2"),
   694  						RespondWith(http.StatusOK, response2, http.Header{"X-Cf-Warnings": {"this is another warning"}}),
   695  					),
   696  				)
   697  			})
   698  
   699  			It("returns all the applications and all warnings", func() {
   700  				apps, warnings, err := client.GetRouteApplications("some-route-guid", Filter{
   701  					Type:     constant.SpaceGUIDFilter,
   702  					Operator: constant.EqualOperator,
   703  					Values:   []string{"some-space-guid"},
   704  				})
   705  				Expect(err).NotTo(HaveOccurred())
   706  				Expect(apps).To(ConsistOf([]Application{
   707  					{Name: "app-name-1", GUID: "app-guid-1"},
   708  					{Name: "app-name-2", GUID: "app-guid-2"},
   709  					{Name: "app-name-3", GUID: "app-guid-3"},
   710  					{Name: "app-name-4", GUID: "app-guid-4"},
   711  				}))
   712  				Expect(warnings).To(ConsistOf(Warnings{"this is a warning", "this is another warning"}))
   713  			})
   714  		})
   715  
   716  		Context("when there are no applications associated with this route", func() {
   717  			BeforeEach(func() {
   718  				response := `{
   719  				"next_url": "",
   720  				"resources": []
   721  			}`
   722  				server.AppendHandlers(
   723  					CombineHandlers(
   724  						VerifyRequest(http.MethodGet, "/v2/routes/some-route-guid/apps"),
   725  						RespondWith(http.StatusOK, response),
   726  					),
   727  				)
   728  			})
   729  
   730  			It("returns an empty list of applications", func() {
   731  				apps, _, err := client.GetRouteApplications("some-route-guid")
   732  				Expect(err).NotTo(HaveOccurred())
   733  				Expect(apps).To(BeEmpty())
   734  			})
   735  		})
   736  	})
   737  })