github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+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)
    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, query := fakeCloudControllerClient.UpdateSpaceApplyManifestArgsForCall(0)
    68  					Expect(guidInCall).To(Equal("some-space-guid"))
    69  					Expect(appManifest).To(Equal(rawManifest))
    70  					Expect(query).To(BeNil())
    71  
    72  					Expect(fakeCloudControllerClient.PollJobCallCount()).To(Equal(1))
    73  					jobURL := fakeCloudControllerClient.PollJobArgsForCall(0)
    74  					Expect(jobURL).To(Equal(ccv3.JobURL("some-job-url")))
    75  				})
    76  			})
    77  
    78  			When("polling returns a generic error", func() {
    79  				var expectedErr error
    80  
    81  				BeforeEach(func() {
    82  					expectedErr = errors.New("poll-1-error")
    83  					fakeCloudControllerClient.PollJobReturns(
    84  						ccv3.Warnings{"poll-1-warning"},
    85  						expectedErr,
    86  					)
    87  				})
    88  
    89  				It("reports a polling error", func() {
    90  					Expect(executeErr).To(Equal(expectedErr))
    91  					Expect(warnings).To(ConsistOf("apply-manifest-1-warning", "poll-1-warning"))
    92  				})
    93  			})
    94  
    95  			When("polling returns an job failed error", func() {
    96  				var expectedErr error
    97  
    98  				BeforeEach(func() {
    99  					expectedErr = ccerror.V3JobFailedError{Detail: "some-job-failed"}
   100  					fakeCloudControllerClient.PollJobReturns(
   101  						ccv3.Warnings{"poll-1-warning"},
   102  						expectedErr,
   103  					)
   104  				})
   105  
   106  				It("reports a polling error", func() {
   107  					Expect(executeErr).To(Equal(actionerror.ApplicationManifestError{Message: "some-job-failed"}))
   108  					Expect(warnings).To(ConsistOf("apply-manifest-1-warning", "poll-1-warning"))
   109  				})
   110  			})
   111  		})
   112  
   113  		When("applying the manifest errors", func() {
   114  			var applyErr error
   115  
   116  			BeforeEach(func() {
   117  				applyErr = errors.New("some-apply-manifest-error")
   118  				fakeCloudControllerClient.UpdateSpaceApplyManifestReturns(
   119  					"",
   120  					ccv3.Warnings{"apply-manifest-1-warning"},
   121  					applyErr,
   122  				)
   123  			})
   124  
   125  			It("reports a error trying to apply the manifest", func() {
   126  				Expect(executeErr).To(Equal(applyErr))
   127  				Expect(warnings).To(ConsistOf("apply-manifest-1-warning"))
   128  			})
   129  		})
   130  	})
   131  })