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

     1  package v7pushaction_test
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/actor/v7action"
     5  	. "code.cloudfoundry.org/cli/actor/v7pushaction"
     6  	"code.cloudfoundry.org/cli/actor/v7pushaction/v7pushactionfakes"
     7  	"errors"
     8  
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  	. "github.com/onsi/gomega/gstruct"
    12  )
    13  
    14  var _ = Describe("UpdateApplication", func() {
    15  	var (
    16  		actor       *Actor
    17  		fakeV7Actor *v7pushactionfakes.FakeV7Actor
    18  
    19  		paramPlan PushPlan
    20  
    21  		returnedPlan PushPlan
    22  		warnings     Warnings
    23  		executeErr   error
    24  	)
    25  
    26  	BeforeEach(func() {
    27  		actor, _, fakeV7Actor, _ = getTestPushActor()
    28  
    29  		paramPlan = PushPlan{
    30  			Application: v7action.Application{
    31  				GUID: "some-app-guid",
    32  			},
    33  		}
    34  	})
    35  
    36  	JustBeforeEach(func() {
    37  		returnedPlan, warnings, executeErr = actor.UpdateApplication(paramPlan, nil, nil)
    38  	})
    39  
    40  	When("the apps needs an update", func() {
    41  		BeforeEach(func() {
    42  			paramPlan.ApplicationNeedsUpdate = true
    43  		})
    44  
    45  		When("updating is successful", func() {
    46  			BeforeEach(func() {
    47  				fakeV7Actor.UpdateApplicationReturns(
    48  					v7action.Application{
    49  						Name:                "some-app",
    50  						GUID:                "some-app-guid",
    51  						LifecycleBuildpacks: []string{"some-buildpack-1"},
    52  					},
    53  					v7action.Warnings{"some-app-update-warnings"},
    54  					nil)
    55  			})
    56  
    57  			It("puts the updated application in the stream", func() {
    58  				Expect(executeErr).NotTo(HaveOccurred())
    59  				Expect(warnings).To(ConsistOf("some-app-update-warnings"))
    60  
    61  				Expect(returnedPlan).To(MatchFields(IgnoreExtras,
    62  					Fields{
    63  						"Application": Equal(v7action.Application{
    64  							Name:                "some-app",
    65  							GUID:                "some-app-guid",
    66  							LifecycleBuildpacks: []string{"some-buildpack-1"},
    67  						}),
    68  					}))
    69  			})
    70  		})
    71  
    72  		When("updating errors", func() {
    73  			var expectedErr error
    74  
    75  			BeforeEach(func() {
    76  				expectedErr = errors.New("some-error")
    77  				fakeV7Actor.UpdateApplicationReturns(
    78  					v7action.Application{},
    79  					v7action.Warnings{"some-app-update-warnings"},
    80  					expectedErr)
    81  			})
    82  
    83  			It("returns the warnings and error", func() {
    84  				Expect(executeErr).To(MatchError(expectedErr))
    85  				Expect(warnings).To(ConsistOf("some-app-update-warnings"))
    86  			})
    87  		})
    88  	})
    89  
    90  	When("the plan does not need an app update", func() {
    91  		BeforeEach(func() {
    92  			paramPlan.ApplicationNeedsUpdate = false
    93  		})
    94  
    95  		It("does not update the application", func() {
    96  			Expect(executeErr).NotTo(HaveOccurred())
    97  			Consistently(fakeV7Actor.UpdateApplicationCallCount).Should(Equal(0))
    98  		})
    99  	})
   100  })