github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/actor/v7pushaction/restart_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  	"code.cloudfoundry.org/cli/resources"
    11  	. "github.com/onsi/ginkgo"
    12  	. "github.com/onsi/gomega"
    13  )
    14  
    15  var _ = Describe("RestartApplication", func() {
    16  	var (
    17  		actor       *Actor
    18  		fakeV7Actor *v7pushactionfakes.FakeV7Actor
    19  
    20  		app       resources.Application
    21  		paramPlan PushPlan
    22  
    23  		warnings   Warnings
    24  		executeErr error
    25  
    26  		events []Event
    27  	)
    28  
    29  	BeforeEach(func() {
    30  		actor, fakeV7Actor, _ = getTestPushActor()
    31  
    32  		app = resources.Application{
    33  			GUID:  "some-app-guid",
    34  			State: constant.ApplicationStarted,
    35  		}
    36  		paramPlan = PushPlan{
    37  			Application: app,
    38  		}
    39  	})
    40  
    41  	JustBeforeEach(func() {
    42  		events = EventFollower(func(eventStream chan<- *PushEvent) {
    43  			_, warnings, executeErr = actor.RestartApplication(paramPlan, eventStream, nil)
    44  		})
    45  	})
    46  
    47  	It("Restarts the app", func() {
    48  		Expect(fakeV7Actor.RestartApplicationCallCount()).To(Equal(1))
    49  		Expect(fakeV7Actor.RestartApplicationArgsForCall(0)).To(Equal("some-app-guid"))
    50  	})
    51  
    52  	When("Restarting the app succeeds", func() {
    53  		BeforeEach(func() {
    54  			fakeV7Actor.PollStartCalls(func(app resources.Application, b bool, handleInstanceDetails func(string)) (warnings v7action.Warnings, err error) {
    55  				handleInstanceDetails("Instances starting...")
    56  				return nil, nil
    57  			})
    58  
    59  			fakeV7Actor.RestartApplicationReturns(v7action.Warnings{"some-restarting-warning"}, nil)
    60  			paramPlan.Application.State = constant.ApplicationStarted
    61  		})
    62  
    63  		When("the noWait flag is set", func() {
    64  			BeforeEach(func() {
    65  				paramPlan.NoWait = true
    66  			})
    67  
    68  			It("calls PollStart with true", func() {
    69  				Expect(fakeV7Actor.PollStartCallCount()).To(Equal(1))
    70  				actualApp, givenNoWait, _ := fakeV7Actor.PollStartArgsForCall(0)
    71  				Expect(givenNoWait).To(Equal(true))
    72  				Expect(actualApp).To(Equal(app))
    73  			})
    74  		})
    75  
    76  		It("calls pollStart", func() {
    77  			Expect(fakeV7Actor.PollStartCallCount()).To(Equal(1))
    78  			actualAppGUID, givenNoWait, _ := fakeV7Actor.PollStartArgsForCall(0)
    79  			Expect(givenNoWait).To(Equal(false))
    80  			Expect(actualAppGUID).To(Equal(app))
    81  			Expect(events).To(ConsistOf(RestartingApplication, InstanceDetails, RestartingApplicationComplete))
    82  		})
    83  
    84  		When("pollStart errors", func() {
    85  			BeforeEach(func() {
    86  				fakeV7Actor.PollStartReturns(
    87  					v7action.Warnings{"poll-start-warning"},
    88  					errors.New("poll-start-error"),
    89  				)
    90  			})
    91  
    92  			It("returns errors and warnings", func() {
    93  				Expect(executeErr).To(MatchError("poll-start-error"))
    94  				Expect(warnings).To(ConsistOf("some-restarting-warning", "poll-start-warning"))
    95  			})
    96  
    97  		})
    98  
    99  		When("pollStart succeeds", func() {
   100  			BeforeEach(func() {
   101  				fakeV7Actor.PollStartReturns(
   102  					v7action.Warnings{"poll-start-warning"},
   103  					nil,
   104  				)
   105  			})
   106  
   107  			It("Uploads a package and exits", func() {
   108  				Expect(executeErr).ToNot(HaveOccurred())
   109  				Expect(warnings).To(ConsistOf("some-restarting-warning", "poll-start-warning"))
   110  				Expect(events).To(ConsistOf(RestartingApplication, RestartingApplicationComplete))
   111  			})
   112  		})
   113  	})
   114  
   115  	When("Restarting the app fails", func() {
   116  		BeforeEach(func() {
   117  			fakeV7Actor.RestartApplicationReturns(v7action.Warnings{"some-restarting-warning"}, errors.New("bummer"))
   118  		})
   119  
   120  		It("returns errors and warnings", func() {
   121  			Expect(executeErr).To(MatchError("bummer"))
   122  			Expect(warnings).To(ConsistOf("some-restarting-warning"))
   123  			Expect(events).To(ConsistOf(RestartingApplication))
   124  		})
   125  	})
   126  
   127  })