github.com/arunkumar7540/cli@v6.45.0+incompatible/actor/v7pushaction/scale_web_process_for_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/types"
     8  	"errors"
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  	. "github.com/onsi/gomega/gstruct"
    12  )
    13  
    14  var _ = Describe("ScaleWebProcessForApplication", 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<- Event) {
    39  			_, warnings, executeErr = actor.ScaleWebProcessForApplication(paramPlan, eventStream, nil)
    40  		})
    41  	})
    42  
    43  	When("a scale override is passed", func() {
    44  		When("the scale is successful", func() {
    45  			var memory types.NullUint64
    46  
    47  			BeforeEach(func() {
    48  				paramPlan.Application.GUID = "some-app-guid"
    49  
    50  				paramPlan.ScaleWebProcessNeedsUpdate = true
    51  				memory = types.NullUint64{IsSet: true, Value: 2048}
    52  				paramPlan.ScaleWebProcess = v7action.Process{
    53  					MemoryInMB: memory,
    54  				}
    55  
    56  				fakeV7Actor.ScaleProcessByApplicationReturns(v7action.Warnings{"scaling-warnings"}, nil)
    57  				fakeV7Actor.UpdateApplicationReturns(
    58  					v7action.Application{
    59  						Name: "some-app",
    60  						GUID: paramPlan.Application.GUID,
    61  					},
    62  					v7action.Warnings{"some-app-update-warnings"},
    63  					nil)
    64  			})
    65  
    66  			It("returns warnings and continues", func() {
    67  				Expect(executeErr).ToNot(HaveOccurred())
    68  				Expect(warnings).To(ConsistOf("scaling-warnings"))
    69  				Expect(events).To(ConsistOf(ScaleWebProcess, ScaleWebProcessComplete))
    70  
    71  				Expect(fakeV7Actor.ScaleProcessByApplicationCallCount()).To(Equal(1))
    72  				passedAppGUID, passedProcess := fakeV7Actor.ScaleProcessByApplicationArgsForCall(0)
    73  				Expect(passedAppGUID).To(Equal("some-app-guid"))
    74  				Expect(passedProcess).To(MatchFields(IgnoreExtras,
    75  					Fields{
    76  						"MemoryInMB": Equal(memory),
    77  					}))
    78  			})
    79  		})
    80  
    81  		When("the scale errors", func() {
    82  			var expectedErr error
    83  
    84  			BeforeEach(func() {
    85  				paramPlan.ScaleWebProcessNeedsUpdate = true
    86  
    87  				expectedErr = errors.New("nopes")
    88  				fakeV7Actor.ScaleProcessByApplicationReturns(v7action.Warnings{"scaling-warnings"}, expectedErr)
    89  			})
    90  
    91  			It("returns warnings and an error", func() {
    92  				Expect(executeErr).To(MatchError(expectedErr))
    93  				Expect(warnings).To(ConsistOf("scaling-warnings"))
    94  				Expect(events).To(ConsistOf(ScaleWebProcess))
    95  			})
    96  		})
    97  	})
    98  
    99  	When("a scale override is not provided", func() {
   100  		It("should not scale the application", func() {
   101  			Expect(executeErr).ToNot(HaveOccurred())
   102  			Expect(events).To(BeEmpty())
   103  			Expect(fakeV7Actor.ScaleProcessByApplicationCallCount()).To(Equal(0))
   104  		})
   105  	})
   106  })