github.com/cloudfoundry-community/cloudfoundry-cli@v6.44.1-0.20240130060226-cda5ed8e89a5+incompatible/actor/v7action/space_manifest_test.go (about)

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