github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/actor/v7action/deployment_test.go (about)

     1  package v7action_test
     2  
     3  import (
     4  	"errors"
     5  
     6  	"code.cloudfoundry.org/cli/actor/actionerror"
     7  	. "code.cloudfoundry.org/cli/actor/v7action"
     8  	"code.cloudfoundry.org/cli/actor/v7action/v7actionfakes"
     9  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
    10  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
    11  	. "github.com/onsi/ginkgo"
    12  	. "github.com/onsi/gomega"
    13  )
    14  
    15  var _ = Describe("Deployment Actions", func() {
    16  	var (
    17  		actor                     *Actor
    18  		fakeCloudControllerClient *v7actionfakes.FakeCloudControllerClient
    19  	)
    20  
    21  	BeforeEach(func() {
    22  		actor, fakeCloudControllerClient, _, _, _, _ = NewTestActor()
    23  	})
    24  
    25  	Describe("CreateDeployment", func() {
    26  		It("delegates to the cloud controller client", func() {
    27  			fakeCloudControllerClient.CreateApplicationDeploymentReturns("some-deployment-guid", ccv3.Warnings{"create-warning-1", "create-warning-2"}, errors.New("create-error"))
    28  
    29  			returnedDeploymentGUID, warnings, executeErr := actor.CreateDeployment("some-app-guid", "some-droplet-guid")
    30  
    31  			Expect(fakeCloudControllerClient.CreateApplicationDeploymentCallCount()).To(Equal(1))
    32  			givenAppGUID, givenDropletGUID := fakeCloudControllerClient.CreateApplicationDeploymentArgsForCall(0)
    33  
    34  			Expect(givenAppGUID).To(Equal("some-app-guid"))
    35  			Expect(givenDropletGUID).To(Equal("some-droplet-guid"))
    36  
    37  			Expect(returnedDeploymentGUID).To(Equal("some-deployment-guid"))
    38  			Expect(warnings).To(Equal(Warnings{"create-warning-1", "create-warning-2"}))
    39  			Expect(executeErr).To(MatchError("create-error"))
    40  		})
    41  	})
    42  
    43  	Describe("GetLatestActiveDeploymentForApp", func() {
    44  		var (
    45  			executeErr error
    46  			warnings   Warnings
    47  			deployment Deployment
    48  
    49  			appGUID string
    50  		)
    51  
    52  		BeforeEach(func() {
    53  			appGUID = "some-app-guid"
    54  		})
    55  
    56  		JustBeforeEach(func() {
    57  			deployment, warnings, executeErr = actor.GetLatestActiveDeploymentForApp(appGUID)
    58  		})
    59  
    60  		It("delegates to the CC client", func() {
    61  			Expect(fakeCloudControllerClient.GetDeploymentsCallCount()).To(Equal(1))
    62  			Expect(fakeCloudControllerClient.GetDeploymentsArgsForCall(0)).To(Equal(
    63  				[]ccv3.Query{
    64  					{Key: ccv3.AppGUIDFilter, Values: []string{appGUID}},
    65  					{Key: ccv3.StatusValueFilter, Values: []string{string(constant.DeploymentStatusValueActive)}},
    66  					{Key: ccv3.OrderBy, Values: []string{ccv3.CreatedAtDescendingOrder}},
    67  					{Key: ccv3.PerPage, Values: []string{"1"}},
    68  				},
    69  			))
    70  		})
    71  
    72  		When("the cc client errors", func() {
    73  			BeforeEach(func() {
    74  				fakeCloudControllerClient.GetDeploymentsReturns(
    75  					[]ccv3.Deployment{},
    76  					ccv3.Warnings{"get-deployments-warning"},
    77  					errors.New("get-deployments-error"),
    78  				)
    79  			})
    80  
    81  			It("returns an error and warnings", func() {
    82  				Expect(executeErr).To(MatchError("get-deployments-error"))
    83  				Expect(warnings).To(ConsistOf("get-deployments-warning"))
    84  			})
    85  		})
    86  
    87  		When("there are no deployments returned", func() {
    88  			BeforeEach(func() {
    89  				fakeCloudControllerClient.GetDeploymentsReturns(
    90  					[]ccv3.Deployment{},
    91  					ccv3.Warnings{"get-deployments-warning"},
    92  					nil,
    93  				)
    94  			})
    95  
    96  			It("returns a deployment not found error and warnings", func() {
    97  				Expect(executeErr).To(Equal(actionerror.ActiveDeploymentNotFoundError{}))
    98  				Expect(warnings).To(ConsistOf("get-deployments-warning"))
    99  			})
   100  
   101  		})
   102  
   103  		When("everything succeeds", func() {
   104  			BeforeEach(func() {
   105  				fakeCloudControllerClient.GetDeploymentsReturns(
   106  					[]ccv3.Deployment{{GUID: "dep-guid"}},
   107  					ccv3.Warnings{"get-deployments-warning"},
   108  					nil,
   109  				)
   110  			})
   111  
   112  			It("returns a deployment not found error and warnings", func() {
   113  				Expect(executeErr).ToNot(HaveOccurred())
   114  				Expect(warnings).To(ConsistOf("get-deployments-warning"))
   115  				Expect(deployment).To(Equal(Deployment{GUID: "dep-guid"}))
   116  			})
   117  
   118  		})
   119  	})
   120  
   121  	Describe("CancelDeployment", func() {
   122  		var (
   123  			deploymentGUID string
   124  
   125  			warnings   Warnings
   126  			executeErr error
   127  		)
   128  
   129  		BeforeEach(func() {
   130  			deploymentGUID = "dep-guid"
   131  		})
   132  
   133  		JustBeforeEach(func() {
   134  			warnings, executeErr = actor.CancelDeployment(deploymentGUID)
   135  		})
   136  
   137  		It("delegates to the cc client", func() {
   138  			Expect(fakeCloudControllerClient.CancelDeploymentCallCount()).To(Equal(1))
   139  			Expect(fakeCloudControllerClient.CancelDeploymentArgsForCall(0)).To(Equal(deploymentGUID))
   140  		})
   141  
   142  		When("the client fails", func() {
   143  			BeforeEach(func() {
   144  				fakeCloudControllerClient.CancelDeploymentReturns(ccv3.Warnings{"cancel-deployment-warnings"}, errors.New("cancel-deployment-error"))
   145  			})
   146  
   147  			It("returns the warnings and error", func() {
   148  				Expect(executeErr).To(MatchError("cancel-deployment-error"))
   149  				Expect(warnings).To(ConsistOf("cancel-deployment-warnings"))
   150  			})
   151  
   152  		})
   153  
   154  		When("the client succeeds", func() {
   155  			BeforeEach(func() {
   156  				fakeCloudControllerClient.CancelDeploymentReturns(ccv3.Warnings{"cancel-deployment-warnings"}, nil)
   157  			})
   158  
   159  			It("returns the warnings and error", func() {
   160  				Expect(executeErr).ToNot(HaveOccurred())
   161  				Expect(warnings).To(ConsistOf("cancel-deployment-warnings"))
   162  			})
   163  		})
   164  	})
   165  })