github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/actor/v7pushaction/stop_application_test.go (about)

     1  package v7pushaction_test
     2  
     3  import (
     4  	"errors"
     5  
     6  	"code.cloudfoundry.org/cli/actor/v7action"
     7  	. "code.cloudfoundry.org/cli/actor/v7pushaction"
     8  	"code.cloudfoundry.org/cli/actor/v7pushaction/v7pushactionfakes"
     9  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  )
    13  
    14  var _ = Describe("StopApplication", func() {
    15  	var (
    16  		actor       *Actor
    17  		fakeV7Actor *v7pushactionfakes.FakeV7Actor
    18  
    19  		paramPlan PushPlan
    20  
    21  		warnings   Warnings
    22  		executeErr error
    23  
    24  		events []Event
    25  	)
    26  
    27  	BeforeEach(func() {
    28  		actor, fakeV7Actor, _ = getTestPushActor()
    29  
    30  		paramPlan = PushPlan{
    31  			Application: v7action.Application{
    32  				GUID: "some-app-guid",
    33  			},
    34  		}
    35  	})
    36  
    37  	JustBeforeEach(func() {
    38  		events = EventFollower(func(eventStream chan<- *PushEvent) {
    39  			_, warnings, executeErr = actor.StopApplication(paramPlan, eventStream, nil)
    40  		})
    41  	})
    42  
    43  	When("The app is running", func() {
    44  		BeforeEach(func() {
    45  			fakeV7Actor.StopApplicationReturns(v7action.Warnings{"some-stopping-warning"}, nil)
    46  			paramPlan.Application.State = constant.ApplicationStarted
    47  		})
    48  
    49  		When("Stopping the app succeeds", func() {
    50  			It("Uploads a package and exits", func() {
    51  				Expect(executeErr).ToNot(HaveOccurred())
    52  				Expect(warnings).To(ConsistOf("some-stopping-warning"))
    53  				Expect(events).To(ConsistOf(StoppingApplication, StoppingApplicationComplete))
    54  
    55  				Expect(fakeV7Actor.StopApplicationCallCount()).To(Equal(1))
    56  				Expect(fakeV7Actor.StopApplicationArgsForCall(0)).To(Equal("some-app-guid"))
    57  				Expect(fakeV7Actor.StageApplicationPackageCallCount()).To(BeZero())
    58  			})
    59  		})
    60  
    61  		When("Stopping the app fails", func() {
    62  			BeforeEach(func() {
    63  				fakeV7Actor.StopApplicationReturns(v7action.Warnings{"some-stopping-warning"}, errors.New("bummer"))
    64  			})
    65  
    66  			It("returns errors and warnings", func() {
    67  				Expect(executeErr).To(MatchError("bummer"))
    68  				Expect(warnings).To(ConsistOf("some-stopping-warning"))
    69  				Expect(events).To(ConsistOf(StoppingApplication))
    70  			})
    71  		})
    72  	})
    73  })