github.com/LukasHeimann/cloudfoundrycli@v7.1.0+incompatible/api/cloudcontroller/ccv3/manifest_test.go (about)

     1  package ccv3_test
     2  
     3  import (
     4  	"net/http"
     5  
     6  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
     7  	. "code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
     8  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/ccv3fakes"
     9  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal"
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  )
    13  
    14  var _ = Describe("Application Manifest", func() {
    15  	var (
    16  		client    *Client
    17  		requester *ccv3fakes.FakeRequester
    18  	)
    19  
    20  	BeforeEach(func() {
    21  		requester = new(ccv3fakes.FakeRequester)
    22  		client, _ = NewFakeRequesterTestClient(requester)
    23  	})
    24  
    25  	Describe("GetApplicationManifest", func() {
    26  		var (
    27  			appGUID string
    28  
    29  			rawManifest []byte
    30  			warnings    Warnings
    31  			executeErr  error
    32  
    33  			expectedYAML []byte
    34  		)
    35  
    36  		BeforeEach(func() {
    37  			appGUID = "some-app-guid"
    38  		})
    39  
    40  		JustBeforeEach(func() {
    41  			rawManifest, warnings, executeErr = client.GetApplicationManifest(appGUID)
    42  		})
    43  
    44  		When("getting the manifest is successful", func() {
    45  			BeforeEach(func() {
    46  				expectedYAML = []byte("---\n- banana")
    47  				requester.MakeRequestReceiveRawReturns(expectedYAML, Warnings{"this is a warning"}, nil)
    48  			})
    49  
    50  			It("makes the correct request", func() {
    51  				Expect(requester.MakeRequestReceiveRawCallCount()).To(Equal(1))
    52  				requestName, uriParams, responseBody := requester.MakeRequestReceiveRawArgsForCall(0)
    53  				Expect(requestName).To(Equal(internal.GetApplicationManifestRequest))
    54  				Expect(uriParams).To(Equal(internal.Params{"app_guid": appGUID}))
    55  				Expect(responseBody).To(Equal("application/x-yaml"))
    56  			})
    57  
    58  			It("the manifest and warnings", func() {
    59  				Expect(executeErr).NotTo(HaveOccurred())
    60  				Expect(warnings).To(ConsistOf("this is a warning"))
    61  
    62  				Expect(rawManifest).To(Equal(expectedYAML))
    63  			})
    64  		})
    65  
    66  		When("the cloud controller returns errors and warnings", func() {
    67  			BeforeEach(func() {
    68  				errors := []ccerror.V3Error{
    69  					{
    70  						Code:   10008,
    71  						Detail: "The request is semantically invalid: command presence",
    72  						Title:  "CF-UnprocessableEntity",
    73  					},
    74  					{
    75  						Code:   10010,
    76  						Detail: "App not found",
    77  						Title:  "CF-AppNotFound",
    78  					},
    79  				}
    80  
    81  				requester.MakeRequestReceiveRawReturns(
    82  					nil,
    83  					Warnings{"this is a warning"},
    84  					ccerror.MultiError{ResponseCode: http.StatusTeapot, Errors: errors},
    85  				)
    86  
    87  			})
    88  
    89  			It("returns the error and all warnings", func() {
    90  				Expect(executeErr).To(MatchError(ccerror.MultiError{
    91  					ResponseCode: http.StatusTeapot,
    92  					Errors: []ccerror.V3Error{
    93  						{
    94  							Code:   10008,
    95  							Detail: "The request is semantically invalid: command presence",
    96  							Title:  "CF-UnprocessableEntity",
    97  						},
    98  						{
    99  							Code:   10010,
   100  							Detail: "App not found",
   101  							Title:  "CF-AppNotFound",
   102  						},
   103  					},
   104  				}))
   105  				Expect(warnings).To(ConsistOf("this is a warning"))
   106  			})
   107  		})
   108  	})
   109  })