github.com/cloudfoundry-community/cloudfoundry-cli@v6.44.1-0.20240130060226-cda5ed8e89a5+incompatible/actor/v7pushaction/stop_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  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
     8  	"errors"
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  )
    12  
    13  var _ = Describe("StopApplication", func() {
    14  	var (
    15  		actor       *Actor
    16  		fakeV7Actor *v7pushactionfakes.FakeV7Actor
    17  
    18  		paramPlan PushPlan
    19  
    20  		warnings   Warnings
    21  		executeErr error
    22  
    23  		events []Event
    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  		events = EventFollower(func(eventStream chan<- Event) {
    38  			_, warnings, executeErr = actor.StopApplication(paramPlan, eventStream, nil)
    39  		})
    40  	})
    41  
    42  	When("The app is stopped", func() {
    43  		BeforeEach(func() {
    44  			paramPlan.Application.State = constant.ApplicationStopped
    45  		})
    46  
    47  		It("Uploads a package and exits", func() {
    48  			Expect(executeErr).ToNot(HaveOccurred())
    49  			Expect(events).To(BeEmpty())
    50  			Expect(fakeV7Actor.StageApplicationPackageCallCount()).To(BeZero())
    51  		})
    52  	})
    53  
    54  	When("The app is running", func() {
    55  		BeforeEach(func() {
    56  			fakeV7Actor.StopApplicationReturns(v7action.Warnings{"some-stopping-warning"}, nil)
    57  			paramPlan.Application.State = constant.ApplicationStarted
    58  		})
    59  
    60  		When("Stopping the app succeeds", func() {
    61  			It("Uploads a package and exits", func() {
    62  				Expect(executeErr).ToNot(HaveOccurred())
    63  				Expect(warnings).To(ConsistOf("some-stopping-warning"))
    64  				Expect(events).To(ConsistOf(StoppingApplication, StoppingApplicationComplete))
    65  
    66  				Expect(fakeV7Actor.StopApplicationCallCount()).To(Equal(1))
    67  				Expect(fakeV7Actor.StopApplicationArgsForCall(0)).To(Equal("some-app-guid"))
    68  				Expect(fakeV7Actor.StageApplicationPackageCallCount()).To(BeZero())
    69  			})
    70  		})
    71  
    72  		When("Stopping the app fails", func() {
    73  			BeforeEach(func() {
    74  				fakeV7Actor.StopApplicationReturns(v7action.Warnings{"some-stopping-warning"}, errors.New("bummer"))
    75  			})
    76  
    77  			It("returns errors and warnings", func() {
    78  				Expect(executeErr).To(MatchError("bummer"))
    79  				Expect(warnings).To(ConsistOf("some-stopping-warning"))
    80  				Expect(events).To(ConsistOf(StoppingApplication))
    81  			})
    82  		})
    83  	})
    84  })