github.com/orange-cloudfoundry/cli@v7.1.0+incompatible/actor/v7action/space_manifest_test.go (about)

     1  package v7action_test
     2  
     3  import (
     4  	"errors"
     5  
     6  	"code.cloudfoundry.org/cli/actor/actionerror"
     7  	. "code.cloudfoundry.org/cli/actor/v7action"
     8  	"code.cloudfoundry.org/cli/actor/v7action/v7actionfakes"
     9  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
    10  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
    11  
    12  	. "github.com/onsi/ginkgo"
    13  	. "github.com/onsi/gomega"
    14  )
    15  
    16  var _ = Describe("Application Manifest Actions", func() {
    17  	var (
    18  		actor                     *Actor
    19  		fakeCloudControllerClient *v7actionfakes.FakeCloudControllerClient
    20  	)
    21  
    22  	BeforeEach(func() {
    23  		fakeCloudControllerClient = new(v7actionfakes.FakeCloudControllerClient)
    24  		actor = NewActor(fakeCloudControllerClient, nil, nil, nil, nil, nil)
    25  	})
    26  
    27  	Describe("SetSpaceManifest", func() {
    28  		var (
    29  			spaceGUID   string
    30  			rawManifest []byte
    31  
    32  			warnings   Warnings
    33  			executeErr error
    34  		)
    35  
    36  		BeforeEach(func() {
    37  			spaceGUID = "some-space-guid"
    38  			rawManifest = []byte("---\n- applications:\n name: my-app")
    39  		})
    40  
    41  		JustBeforeEach(func() {
    42  			warnings, executeErr = actor.SetSpaceManifest(spaceGUID, rawManifest)
    43  		})
    44  
    45  		When("applying the manifest succeeds", func() {
    46  			BeforeEach(func() {
    47  				fakeCloudControllerClient.UpdateSpaceApplyManifestReturns(
    48  					"some-job-url",
    49  					ccv3.Warnings{"apply-manifest-1-warning"},
    50  					nil,
    51  				)
    52  			})
    53  
    54  			When("polling finishes successfully", func() {
    55  				BeforeEach(func() {
    56  					fakeCloudControllerClient.PollJobReturns(
    57  						ccv3.Warnings{"poll-1-warning"},
    58  						nil,
    59  					)
    60  				})
    61  
    62  				It("uploads the app manifest", func() {
    63  					Expect(executeErr).ToNot(HaveOccurred())
    64  					Expect(warnings).To(ConsistOf("apply-manifest-1-warning", "poll-1-warning"))
    65  
    66  					Expect(fakeCloudControllerClient.UpdateSpaceApplyManifestCallCount()).To(Equal(1))
    67  					guidInCall, appManifest := fakeCloudControllerClient.UpdateSpaceApplyManifestArgsForCall(0)
    68  					Expect(guidInCall).To(Equal("some-space-guid"))
    69  					Expect(appManifest).To(Equal(rawManifest))
    70  
    71  					Expect(fakeCloudControllerClient.PollJobCallCount()).To(Equal(1))
    72  					jobURL := fakeCloudControllerClient.PollJobArgsForCall(0)
    73  					Expect(jobURL).To(Equal(ccv3.JobURL("some-job-url")))
    74  				})
    75  			})
    76  
    77  			When("polling returns a generic error", func() {
    78  				var expectedErr error
    79  
    80  				BeforeEach(func() {
    81  					expectedErr = errors.New("poll-1-error")
    82  					fakeCloudControllerClient.PollJobReturns(
    83  						ccv3.Warnings{"poll-1-warning"},
    84  						expectedErr,
    85  					)
    86  				})
    87  
    88  				It("reports a polling error", func() {
    89  					Expect(executeErr).To(Equal(expectedErr))
    90  					Expect(warnings).To(ConsistOf("apply-manifest-1-warning", "poll-1-warning"))
    91  				})
    92  			})
    93  
    94  			When("polling returns an job failed error", func() {
    95  				var expectedErr error
    96  
    97  				BeforeEach(func() {
    98  					expectedErr = ccerror.V3JobFailedError{Detail: "some-job-failed"}
    99  					fakeCloudControllerClient.PollJobReturns(
   100  						ccv3.Warnings{"poll-1-warning"},
   101  						expectedErr,
   102  					)
   103  				})
   104  
   105  				It("reports a polling error", func() {
   106  					Expect(executeErr).To(Equal(actionerror.ApplicationManifestError{Message: "some-job-failed"}))
   107  					Expect(warnings).To(ConsistOf("apply-manifest-1-warning", "poll-1-warning"))
   108  				})
   109  			})
   110  		})
   111  
   112  		When("applying the manifest errors", func() {
   113  			var applyErr error
   114  
   115  			BeforeEach(func() {
   116  				applyErr = errors.New("some-apply-manifest-error")
   117  				fakeCloudControllerClient.UpdateSpaceApplyManifestReturns(
   118  					"",
   119  					ccv3.Warnings{"apply-manifest-1-warning"},
   120  					applyErr,
   121  				)
   122  			})
   123  
   124  			It("reports a error trying to apply the manifest", func() {
   125  				Expect(executeErr).To(Equal(applyErr))
   126  				Expect(warnings).To(ConsistOf("apply-manifest-1-warning"))
   127  			})
   128  		})
   129  	})
   130  })