github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/actor/v7pushaction/sequence_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/api/cloudcontroller/ccv3/constant"
     7  	"code.cloudfoundry.org/cli/cf/util/testhelpers/matchers"
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  )
    11  
    12  var _ = Describe("Actor", func() {
    13  	var (
    14  		actor    *Actor
    15  		plan     PushPlan
    16  		sequence []ChangeApplicationFunc
    17  	)
    18  
    19  	BeforeEach(func() {
    20  		actor, _, _ = getTestPushActor()
    21  	})
    22  
    23  	Describe("GetPrepareApplicationSourceSequence", func() {
    24  		JustBeforeEach(func() {
    25  			sequence = actor.GetPrepareApplicationSourceSequence(plan)
    26  		})
    27  
    28  		When("the plan requires creating a bits package", func() {
    29  			BeforeEach(func() {
    30  				plan = PushPlan{}
    31  			})
    32  
    33  			It("returns a sequence including creating a bits package", func() {
    34  				Expect(sequence).To(matchers.MatchFuncsByName(actor.CreateBitsPackageForApplication))
    35  			})
    36  		})
    37  
    38  		When("the plan requires creating a docker package", func() {
    39  			BeforeEach(func() {
    40  				plan = PushPlan{
    41  					DockerImageCredentials: v7action.DockerImageCredentials{Path: "not empty"},
    42  				}
    43  			})
    44  
    45  			It("returns a sequence including creating a docker package", func() {
    46  				Expect(sequence).To(matchers.MatchFuncsByName(actor.CreateDockerPackageForApplication))
    47  			})
    48  		})
    49  
    50  		When("the plan requires uploading a droplet", func() {
    51  			BeforeEach(func() {
    52  				plan = PushPlan{
    53  					DropletPath: "path",
    54  				}
    55  			})
    56  
    57  			It("returns a sequence including creating a droplet", func() {
    58  				Expect(sequence).To(matchers.MatchFuncsByName(actor.CreateDropletForApplication))
    59  			})
    60  		})
    61  	})
    62  
    63  	Describe("GetRuntimeSequence", func() {
    64  		JustBeforeEach(func() {
    65  			sequence = actor.GetRuntimeSequence(plan)
    66  		})
    67  
    68  		When("the plan requires staging a package", func() {
    69  			BeforeEach(func() {
    70  				plan = PushPlan{}
    71  			})
    72  
    73  			It("returns a sequence including staging, setting the droplet, and restarting", func() {
    74  				Expect(sequence).To(matchers.MatchFuncsByName(actor.StagePackageForApplication, actor.SetDropletForApplication, actor.RestartApplication))
    75  			})
    76  		})
    77  
    78  		When("the plan requires stopping an app", func() {
    79  			BeforeEach(func() {
    80  				plan = PushPlan{
    81  					NoStart:     true,
    82  					Application: v7action.Application{State: constant.ApplicationStarted},
    83  				}
    84  			})
    85  
    86  			It("returns a sequence including stopping the application", func() {
    87  				Expect(sequence).To(matchers.MatchFuncsByName(actor.StopApplication))
    88  			})
    89  		})
    90  
    91  		When("the plan requires setting a droplet", func() {
    92  			BeforeEach(func() {
    93  				plan = PushPlan{
    94  					DropletPath: "path",
    95  				}
    96  			})
    97  
    98  			It("returns a sequence including setting the droplet and restarting", func() {
    99  				Expect(sequence).To(matchers.MatchFuncsByName(actor.SetDropletForApplication, actor.RestartApplication))
   100  			})
   101  		})
   102  
   103  		When("the plan has strategy 'rolling'", func() {
   104  			BeforeEach(func() {
   105  				plan = PushPlan{
   106  					Strategy: constant.DeploymentStrategyRolling,
   107  				}
   108  			})
   109  
   110  			It("returns a sequence that creates a deployment without stopping/restarting the app", func() {
   111  				Expect(sequence).To(matchers.MatchFuncsByName(actor.StagePackageForApplication, actor.CreateDeploymentForApplication))
   112  			})
   113  		})
   114  
   115  		When("the plan has task application type", func() {
   116  			BeforeEach(func() {
   117  				plan = PushPlan{
   118  					TaskTypeApplication: true,
   119  				}
   120  			})
   121  
   122  			It("returns a sequence that stages, sets droplet, and stops the app", func() {
   123  				Expect(sequence).To(matchers.MatchFuncsByName(actor.StagePackageForApplication, actor.StopApplication, actor.SetDropletForApplication))
   124  			})
   125  		})
   126  	})
   127  })