github.com/arunkumar7540/cli@v6.45.0+incompatible/actor/v7pushaction/update_web_process_for_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/types"
    11  	. "github.com/onsi/ginkgo"
    12  	. "github.com/onsi/gomega"
    13  	. "github.com/onsi/gomega/gstruct"
    14  )
    15  
    16  var _ = Describe("UpdateWebProcessForApplication", func() {
    17  	var (
    18  		actor       *Actor
    19  		fakeV7Actor *v7pushactionfakes.FakeV7Actor
    20  
    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  		paramPlan = PushPlan{
    33  			Application: v7action.Application{
    34  				GUID: "some-app-guid",
    35  			},
    36  		}
    37  	})
    38  
    39  	JustBeforeEach(func() {
    40  		events = EventFollower(func(eventStream chan<- Event) {
    41  			_, warnings, executeErr = actor.UpdateWebProcessForApplication(paramPlan, eventStream, nil)
    42  		})
    43  	})
    44  
    45  	When("process configuration is provided", func() {
    46  		var startCommand types.FilteredString
    47  
    48  		BeforeEach(func() {
    49  			paramPlan.UpdateWebProcessNeedsUpdate = true
    50  
    51  			startCommand = types.FilteredString{IsSet: true, Value: "some-start-command"}
    52  			paramPlan.UpdateWebProcess = v7action.Process{
    53  				Command: startCommand,
    54  			}
    55  		})
    56  
    57  		When("the update is successful", func() {
    58  			BeforeEach(func() {
    59  				paramPlan.Application.GUID = "some-app-guid"
    60  
    61  				fakeV7Actor.UpdateApplicationReturns(
    62  					v7action.Application{
    63  						Name: "some-app",
    64  						GUID: paramPlan.Application.GUID,
    65  					},
    66  					v7action.Warnings{"some-app-update-warnings"},
    67  					nil)
    68  
    69  				fakeV7Actor.UpdateProcessByTypeAndApplicationReturns(v7action.Warnings{"health-check-warnings"}, nil)
    70  			})
    71  
    72  			It("sets the process config and returns warnings", func() {
    73  				Expect(executeErr).ToNot(HaveOccurred())
    74  				Expect(warnings).To(ConsistOf("health-check-warnings"))
    75  				Expect(events).To(ConsistOf(SetProcessConfiguration, SetProcessConfigurationComplete))
    76  
    77  				Expect(fakeV7Actor.UpdateProcessByTypeAndApplicationCallCount()).To(Equal(1))
    78  				passedProcessType, passedAppGUID, passedProcess := fakeV7Actor.UpdateProcessByTypeAndApplicationArgsForCall(0)
    79  				Expect(passedProcessType).To(Equal(constant.ProcessTypeWeb))
    80  				Expect(passedAppGUID).To(Equal("some-app-guid"))
    81  				Expect(passedProcess).To(MatchFields(IgnoreExtras,
    82  					Fields{
    83  						"Command": Equal(startCommand),
    84  					}))
    85  			})
    86  		})
    87  
    88  		When("the update errors", func() {
    89  			var expectedErr error
    90  
    91  			BeforeEach(func() {
    92  				expectedErr = errors.New("nopes")
    93  				fakeV7Actor.UpdateProcessByTypeAndApplicationReturns(v7action.Warnings{"health-check-warnings"}, expectedErr)
    94  			})
    95  
    96  			It("returns warnings and an error", func() {
    97  				Expect(executeErr).To(MatchError(expectedErr))
    98  				Expect(warnings).To(ConsistOf("health-check-warnings"))
    99  				Expect(events).To(ConsistOf(SetProcessConfiguration))
   100  			})
   101  		})
   102  	})
   103  })