github.com/cloudfoundry/cli@v7.1.0+incompatible/actor/v3action/process_test.go (about)

     1  package v3action_test
     2  
     3  import (
     4  	"errors"
     5  
     6  	"code.cloudfoundry.org/cli/actor/actionerror"
     7  	. "code.cloudfoundry.org/cli/actor/v3action"
     8  	"code.cloudfoundry.org/cli/actor/v3action/v3actionfakes"
     9  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
    10  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
    11  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
    12  	"code.cloudfoundry.org/cli/types"
    13  
    14  	. "github.com/onsi/ginkgo"
    15  	. "github.com/onsi/gomega"
    16  )
    17  
    18  var _ = Describe("Process Actions", func() {
    19  	var (
    20  		actor                     *Actor
    21  		fakeCloudControllerClient *v3actionfakes.FakeCloudControllerClient
    22  	)
    23  
    24  	BeforeEach(func() {
    25  		fakeCloudControllerClient = new(v3actionfakes.FakeCloudControllerClient)
    26  		actor = NewActor(fakeCloudControllerClient, nil, nil, nil)
    27  	})
    28  
    29  	Describe("ScaleProcessByApplication", func() {
    30  		var passedProcess Process
    31  
    32  		BeforeEach(func() {
    33  			passedProcess = Process{
    34  				Type:       constant.ProcessTypeWeb,
    35  				Instances:  types.NullInt{Value: 2, IsSet: true},
    36  				MemoryInMB: types.NullUint64{Value: 100, IsSet: true},
    37  				DiskInMB:   types.NullUint64{Value: 200, IsSet: true},
    38  			}
    39  		})
    40  
    41  		When("no errors are encountered scaling the application process", func() {
    42  			BeforeEach(func() {
    43  				fakeCloudControllerClient.CreateApplicationProcessScaleReturns(
    44  					ccv3.Process{GUID: "some-process-guid"},
    45  					ccv3.Warnings{"scale-process-warning"},
    46  					nil)
    47  			})
    48  
    49  			It("scales correct process", func() {
    50  				warnings, err := actor.ScaleProcessByApplication("some-app-guid", passedProcess)
    51  
    52  				Expect(err).ToNot(HaveOccurred())
    53  				Expect(warnings).To(ConsistOf("scale-process-warning"))
    54  
    55  				Expect(fakeCloudControllerClient.CreateApplicationProcessScaleCallCount()).To(Equal(1))
    56  				appGUIDArg, processArg := fakeCloudControllerClient.CreateApplicationProcessScaleArgsForCall(0)
    57  				Expect(appGUIDArg).To(Equal("some-app-guid"))
    58  				Expect(processArg).To(Equal(ccv3.Process{
    59  					Type:       constant.ProcessTypeWeb,
    60  					Instances:  passedProcess.Instances,
    61  					MemoryInMB: passedProcess.MemoryInMB,
    62  					DiskInMB:   passedProcess.DiskInMB,
    63  				}))
    64  			})
    65  		})
    66  
    67  		When("an error is encountered scaling the application process", func() {
    68  			var expectedErr error
    69  
    70  			BeforeEach(func() {
    71  				expectedErr = errors.New("scale process error")
    72  				fakeCloudControllerClient.CreateApplicationProcessScaleReturns(
    73  					ccv3.Process{GUID: "some-process-guid"},
    74  					ccv3.Warnings{"scale-process-warning"},
    75  					expectedErr)
    76  			})
    77  
    78  			It("returns the error and all warnings", func() {
    79  				warnings, err := actor.ScaleProcessByApplication("some-app-guid", passedProcess)
    80  				Expect(err).To(MatchError(expectedErr))
    81  				Expect(warnings).To(ConsistOf("scale-process-warning"))
    82  			})
    83  		})
    84  
    85  		When("a ProcessNotFoundError error is encountered scaling the application process", func() {
    86  			BeforeEach(func() {
    87  				fakeCloudControllerClient.CreateApplicationProcessScaleReturns(
    88  					ccv3.Process{GUID: "some-process-guid"},
    89  					ccv3.Warnings{"scale-process-warning"},
    90  					ccerror.ProcessNotFoundError{},
    91  				)
    92  			})
    93  
    94  			It("returns the error and all warnings", func() {
    95  				warnings, err := actor.ScaleProcessByApplication("some-app-guid", passedProcess)
    96  				Expect(err).To(Equal(actionerror.ProcessNotFoundError{ProcessType: constant.ProcessTypeWeb}))
    97  				Expect(warnings).To(ConsistOf("scale-process-warning"))
    98  			})
    99  		})
   100  	})
   101  })