github.com/lukasheimann/cloudfoundrycli@v7.1.0+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("CreateDeploymentByApplicationAndRevision", func() {
    26  		It("delegates to the cloud controller client", func() {
    27  			fakeCloudControllerClient.CreateApplicationDeploymentByRevisionReturns(
    28  				"some-deployment-guid",
    29  				ccv3.Warnings{"create-warning-1", "create-warning-2"},
    30  				errors.New("create-error"),
    31  			)
    32  
    33  			returnedDeploymentGUID, warnings, _ := actor.CreateDeploymentByApplicationAndRevision("some-app-guid", "some-revision-guid")
    34  
    35  			Expect(fakeCloudControllerClient.CreateApplicationDeploymentByRevisionCallCount()).To(Equal(1), "CreateApplicationDeploymentByRevision call count")
    36  			givenAppGUID, givenRevisionGUID := fakeCloudControllerClient.CreateApplicationDeploymentByRevisionArgsForCall(0)
    37  
    38  			Expect(givenAppGUID).To(Equal("some-app-guid"))
    39  			Expect(givenRevisionGUID).To(Equal("some-revision-guid"))
    40  
    41  			Expect(returnedDeploymentGUID).To(Equal("some-deployment-guid"))
    42  			Expect(warnings).To(Equal(Warnings{"create-warning-1", "create-warning-2"}))
    43  		})
    44  	})
    45  
    46  	Describe("CreateDeploymentByApplicationAndDroplet", func() {
    47  		It("delegates to the cloud controller client", func() {
    48  			fakeCloudControllerClient.CreateApplicationDeploymentReturns("some-deployment-guid", ccv3.Warnings{"create-warning-1", "create-warning-2"}, errors.New("create-error"))
    49  
    50  			returnedDeploymentGUID, warnings, executeErr := actor.CreateDeploymentByApplicationAndDroplet("some-app-guid", "some-droplet-guid")
    51  
    52  			Expect(fakeCloudControllerClient.CreateApplicationDeploymentCallCount()).To(Equal(1))
    53  			givenAppGUID, givenDropletGUID := fakeCloudControllerClient.CreateApplicationDeploymentArgsForCall(0)
    54  
    55  			Expect(givenAppGUID).To(Equal("some-app-guid"))
    56  			Expect(givenDropletGUID).To(Equal("some-droplet-guid"))
    57  
    58  			Expect(returnedDeploymentGUID).To(Equal("some-deployment-guid"))
    59  			Expect(warnings).To(Equal(Warnings{"create-warning-1", "create-warning-2"}))
    60  			Expect(executeErr).To(MatchError("create-error"))
    61  		})
    62  	})
    63  
    64  	Describe("GetLatestActiveDeploymentForApp", func() {
    65  		var (
    66  			executeErr error
    67  			warnings   Warnings
    68  			deployment Deployment
    69  
    70  			appGUID string
    71  		)
    72  
    73  		BeforeEach(func() {
    74  			appGUID = "some-app-guid"
    75  		})
    76  
    77  		JustBeforeEach(func() {
    78  			deployment, warnings, executeErr = actor.GetLatestActiveDeploymentForApp(appGUID)
    79  		})
    80  
    81  		It("delegates to the CC client", func() {
    82  			Expect(fakeCloudControllerClient.GetDeploymentsCallCount()).To(Equal(1))
    83  			Expect(fakeCloudControllerClient.GetDeploymentsArgsForCall(0)).To(Equal(
    84  				[]ccv3.Query{
    85  					{Key: ccv3.AppGUIDFilter, Values: []string{appGUID}},
    86  					{Key: ccv3.StatusValueFilter, Values: []string{string(constant.DeploymentStatusValueActive)}},
    87  					{Key: ccv3.OrderBy, Values: []string{ccv3.CreatedAtDescendingOrder}},
    88  					{Key: ccv3.PerPage, Values: []string{"1"}},
    89  				},
    90  			))
    91  		})
    92  
    93  		When("the cc client errors", func() {
    94  			BeforeEach(func() {
    95  				fakeCloudControllerClient.GetDeploymentsReturns(
    96  					[]ccv3.Deployment{},
    97  					ccv3.Warnings{"get-deployments-warning"},
    98  					errors.New("get-deployments-error"),
    99  				)
   100  			})
   101  
   102  			It("returns an error and warnings", func() {
   103  				Expect(executeErr).To(MatchError("get-deployments-error"))
   104  				Expect(warnings).To(ConsistOf("get-deployments-warning"))
   105  			})
   106  		})
   107  
   108  		When("there are no deployments returned", func() {
   109  			BeforeEach(func() {
   110  				fakeCloudControllerClient.GetDeploymentsReturns(
   111  					[]ccv3.Deployment{},
   112  					ccv3.Warnings{"get-deployments-warning"},
   113  					nil,
   114  				)
   115  			})
   116  
   117  			It("returns a deployment not found error and warnings", func() {
   118  				Expect(executeErr).To(Equal(actionerror.ActiveDeploymentNotFoundError{}))
   119  				Expect(warnings).To(ConsistOf("get-deployments-warning"))
   120  			})
   121  
   122  		})
   123  
   124  		When("everything succeeds", func() {
   125  			BeforeEach(func() {
   126  				fakeCloudControllerClient.GetDeploymentsReturns(
   127  					[]ccv3.Deployment{{GUID: "dep-guid"}},
   128  					ccv3.Warnings{"get-deployments-warning"},
   129  					nil,
   130  				)
   131  			})
   132  
   133  			It("returns a deployment not found error and warnings", func() {
   134  				Expect(executeErr).ToNot(HaveOccurred())
   135  				Expect(warnings).To(ConsistOf("get-deployments-warning"))
   136  				Expect(deployment).To(Equal(Deployment{GUID: "dep-guid"}))
   137  			})
   138  
   139  		})
   140  	})
   141  
   142  	Describe("CancelDeployment", func() {
   143  		var (
   144  			deploymentGUID string
   145  
   146  			warnings   Warnings
   147  			executeErr error
   148  		)
   149  
   150  		BeforeEach(func() {
   151  			deploymentGUID = "dep-guid"
   152  		})
   153  
   154  		JustBeforeEach(func() {
   155  			warnings, executeErr = actor.CancelDeployment(deploymentGUID)
   156  		})
   157  
   158  		It("delegates to the cc client", func() {
   159  			Expect(fakeCloudControllerClient.CancelDeploymentCallCount()).To(Equal(1))
   160  			Expect(fakeCloudControllerClient.CancelDeploymentArgsForCall(0)).To(Equal(deploymentGUID))
   161  		})
   162  
   163  		When("the client fails", func() {
   164  			BeforeEach(func() {
   165  				fakeCloudControllerClient.CancelDeploymentReturns(ccv3.Warnings{"cancel-deployment-warnings"}, errors.New("cancel-deployment-error"))
   166  			})
   167  
   168  			It("returns the warnings and error", func() {
   169  				Expect(executeErr).To(MatchError("cancel-deployment-error"))
   170  				Expect(warnings).To(ConsistOf("cancel-deployment-warnings"))
   171  			})
   172  
   173  		})
   174  
   175  		When("the client succeeds", func() {
   176  			BeforeEach(func() {
   177  				fakeCloudControllerClient.CancelDeploymentReturns(ccv3.Warnings{"cancel-deployment-warnings"}, nil)
   178  			})
   179  
   180  			It("returns the warnings and error", func() {
   181  				Expect(executeErr).ToNot(HaveOccurred())
   182  				Expect(warnings).To(ConsistOf("cancel-deployment-warnings"))
   183  			})
   184  		})
   185  	})
   186  })