github.com/orange-cloudfoundry/cli@v7.1.0+incompatible/api/cloudcontroller/ccv3/revisions_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  	"code.cloudfoundry.org/cli/resources"
    11  	. "github.com/onsi/ginkgo"
    12  	. "github.com/onsi/gomega"
    13  )
    14  
    15  var _ = Describe("Revisions", func() {
    16  	var (
    17  		client    *Client
    18  		requester *ccv3fakes.FakeRequester
    19  	)
    20  
    21  	BeforeEach(func() {
    22  		requester = new(ccv3fakes.FakeRequester)
    23  		client, _ = NewFakeRequesterTestClient(requester)
    24  	})
    25  
    26  	Describe("GetApplicationRevisions", func() {
    27  		var (
    28  			query      Query
    29  			revisions  []resources.Revision
    30  			warnings   Warnings
    31  			executeErr error
    32  		)
    33  
    34  		JustBeforeEach(func() {
    35  			revisions, warnings, executeErr = client.GetApplicationRevisions("some-app-guid", query)
    36  		})
    37  
    38  		When("the cloud controller returns errors and warnings", func() {
    39  			BeforeEach(func() {
    40  				errors := []ccerror.V3Error{
    41  					{
    42  						Code:   10008,
    43  						Detail: "The request is semantically invalid: command presence",
    44  						Title:  "CF-UnprocessableEntity",
    45  					},
    46  					{
    47  						Code:   10010,
    48  						Detail: "App not found",
    49  						Title:  "CF-ResourceNotFound",
    50  					},
    51  				}
    52  
    53  				requester.MakeListRequestReturns(
    54  					IncludedResources{},
    55  					Warnings{"this is a warning"},
    56  					ccerror.MultiError{ResponseCode: http.StatusTeapot, Errors: errors},
    57  				)
    58  			})
    59  
    60  			It("returns the error and all warnings", func() {
    61  				Expect(executeErr).To(MatchError(ccerror.MultiError{
    62  					ResponseCode: http.StatusTeapot,
    63  					Errors: []ccerror.V3Error{
    64  						{
    65  							Code:   10008,
    66  							Detail: "The request is semantically invalid: command presence",
    67  							Title:  "CF-UnprocessableEntity",
    68  						},
    69  						{
    70  							Code:   10010,
    71  							Detail: "App not found",
    72  							Title:  "CF-ResourceNotFound",
    73  						},
    74  					},
    75  				}))
    76  				Expect(warnings).To(ConsistOf("this is a warning"))
    77  			})
    78  		})
    79  
    80  		When("applications exist", func() {
    81  			BeforeEach(func() {
    82  				requester.MakeListRequestCalls(func(requestParams RequestParams) (IncludedResources, Warnings, error) {
    83  					err := requestParams.AppendToList(resources.Revision{GUID: "app-guid-1"})
    84  					Expect(err).NotTo(HaveOccurred())
    85  					return IncludedResources{}, Warnings{"this is a warning", "this is another warning"}, nil
    86  				})
    87  				query = Query{Key: OrderBy, Values: []string{"-created_at"}}
    88  			})
    89  
    90  			It("returns the revisions and all warnings", func() {
    91  				Expect(requester.MakeListRequestCallCount()).To(Equal(1))
    92  				actualParams := requester.MakeListRequestArgsForCall(0)
    93  				Expect(actualParams.RequestName).To(Equal(internal.GetApplicationRevisionsRequest))
    94  				Expect(actualParams.Query).To(Equal([]Query{query}))
    95  
    96  				Expect(executeErr).NotTo(HaveOccurred())
    97  				Expect(warnings).To(ConsistOf("this is a warning", "this is another warning"))
    98  
    99  				Expect(revisions).To(ConsistOf([]resources.Revision{{GUID: "app-guid-1"}}))
   100  			})
   101  		})
   102  
   103  	})
   104  })