github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+incompatible/api/cloudcontroller/ccv3/process_test.go (about)

     1  package ccv3_test
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  
     7  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
     8  	. "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  	. "github.com/onsi/gomega/ghttp"
    12  )
    13  
    14  var _ = Describe("Process", func() {
    15  	var client *Client
    16  
    17  	BeforeEach(func() {
    18  		client = NewTestClient()
    19  	})
    20  
    21  	Describe("GetApplicationProcesses", func() {
    22  		Context("when the application exists", func() {
    23  			BeforeEach(func() {
    24  				response1 := fmt.Sprintf(`
    25  					{
    26  						"pagination": {
    27  							"next": {
    28  								"href": "%s/v3/apps/some-app-guid/processes?page=2"
    29  							}
    30  						},
    31  						"resources": [
    32  							{
    33  								"guid": "process-1-guid",
    34  								"type": "web",
    35  								"memory_in_mb": 32
    36  							},
    37  							{
    38  								"guid": "process-2-guid",
    39  								"type": "worker",
    40  								"memory_in_mb": 64
    41  							}
    42  						]
    43  					}`, server.URL())
    44  				response2 := `
    45  					{
    46  						"pagination": {
    47  							"next": null
    48  						},
    49  						"resources": [
    50  							{
    51  								"guid": "process-3-guid",
    52  								"type": "console",
    53  								"memory_in_mb": 128
    54  							}
    55  						]
    56  					}`
    57  				server.AppendHandlers(
    58  					CombineHandlers(
    59  						VerifyRequest(http.MethodGet, "/v3/apps/some-app-guid/processes"),
    60  						RespondWith(http.StatusOK, response1, http.Header{"X-Cf-Warnings": {"warning-1"}}),
    61  					),
    62  				)
    63  				server.AppendHandlers(
    64  					CombineHandlers(
    65  						VerifyRequest(http.MethodGet, "/v3/apps/some-app-guid/processes", "page=2"),
    66  						RespondWith(http.StatusOK, response2, http.Header{"X-Cf-Warnings": {"warning-2"}}),
    67  					),
    68  				)
    69  			})
    70  
    71  			It("returns a list of processes associated with the application and all warnings", func() {
    72  				processes, warnings, err := client.GetApplicationProcesses("some-app-guid")
    73  				Expect(err).ToNot(HaveOccurred())
    74  
    75  				Expect(processes).To(ConsistOf(
    76  					Process{
    77  						GUID:       "process-1-guid",
    78  						Type:       "web",
    79  						MemoryInMB: 32,
    80  					},
    81  					Process{
    82  						GUID:       "process-2-guid",
    83  						Type:       "worker",
    84  						MemoryInMB: 64,
    85  					},
    86  					Process{
    87  						GUID:       "process-3-guid",
    88  						Type:       "console",
    89  						MemoryInMB: 128,
    90  					},
    91  				))
    92  				Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
    93  			})
    94  		})
    95  
    96  		Context("when cloud controller returns an error", func() {
    97  			BeforeEach(func() {
    98  				response := `{
    99  					"errors": [
   100  						{
   101  							"code": 10010,
   102  							"detail": "App not found",
   103  							"title": "CF-ResourceNotFound"
   104  						}
   105  					]
   106  				}`
   107  				server.AppendHandlers(
   108  					CombineHandlers(
   109  						VerifyRequest(http.MethodGet, "/v3/apps/some-app-guid/processes"),
   110  						RespondWith(http.StatusNotFound, response),
   111  					),
   112  				)
   113  			})
   114  
   115  			It("returns the error", func() {
   116  				_, _, err := client.GetApplicationProcesses("some-app-guid")
   117  				Expect(err).To(MatchError(ccerror.ResourceNotFoundError{Message: "App not found"}))
   118  			})
   119  		})
   120  	})
   121  })