github.com/arunkumar7540/cli@v6.45.0+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("GetUpdateSequence", func() {
    24  		JustBeforeEach(func() {
    25  			sequence = actor.GetUpdateSequence(plan)
    26  		})
    27  
    28  		When("the plan requires updating application", func() {
    29  			BeforeEach(func() {
    30  				plan = PushPlan{
    31  					ApplicationNeedsUpdate: true,
    32  					NoRouteFlag:            true,
    33  				}
    34  			})
    35  
    36  			It("returns a sequence including UpdateApplication", func() {
    37  				Expect(sequence).To(matchers.MatchFuncsByName(actor.UpdateApplication))
    38  			})
    39  		})
    40  
    41  		When("the plan requires updating routes", func() {
    42  			BeforeEach(func() {
    43  				plan = PushPlan{}
    44  			})
    45  
    46  			It("returns a sequence including updating the routes for the app", func() {
    47  				Expect(sequence).To(matchers.MatchFuncsByName(actor.UpdateRoutesForApplication))
    48  			})
    49  		})
    50  
    51  		When("the plan requires scaling the web process", func() {
    52  			BeforeEach(func() {
    53  				plan = PushPlan{
    54  					ScaleWebProcessNeedsUpdate: true,
    55  					NoRouteFlag:                true,
    56  				}
    57  			})
    58  
    59  			It("returns a sequence including scaling web process", func() {
    60  				Expect(sequence).To(matchers.MatchFuncsByName(actor.ScaleWebProcessForApplication))
    61  			})
    62  		})
    63  
    64  		When("the plan requires updating the web process", func() {
    65  			BeforeEach(func() {
    66  				plan = PushPlan{
    67  					UpdateWebProcessNeedsUpdate: true,
    68  					NoRouteFlag:                 true,
    69  				}
    70  			})
    71  
    72  			It("returns a sequence including updating a web process", func() {
    73  				Expect(sequence).To(matchers.MatchFuncsByName(actor.UpdateWebProcessForApplication))
    74  			})
    75  		})
    76  	})
    77  
    78  	Describe("GetPrepareApplicationSourceSequence", func() {
    79  		JustBeforeEach(func() {
    80  			sequence = actor.GetPrepareApplicationSourceSequence(plan)
    81  		})
    82  
    83  		When("the plan requires creating a bits package", func() {
    84  			BeforeEach(func() {
    85  				plan = PushPlan{
    86  					DockerImageCredentialsNeedsUpdate: false,
    87  				}
    88  			})
    89  
    90  			It("returns a sequence including creating a bits package", func() {
    91  				Expect(sequence).To(matchers.MatchFuncsByName(actor.CreateBitsPackageForApplication))
    92  			})
    93  		})
    94  
    95  		When("the plan requires creating a docker package", func() {
    96  			BeforeEach(func() {
    97  				plan = PushPlan{
    98  					DockerImageCredentialsNeedsUpdate: true,
    99  				}
   100  			})
   101  
   102  			It("returns a sequence including creating a docker package", func() {
   103  				Expect(sequence).To(matchers.MatchFuncsByName(actor.CreateDockerPackageForApplication))
   104  			})
   105  		})
   106  
   107  		When("the plan requires uploading a droplet", func() {
   108  			BeforeEach(func() {
   109  				plan = PushPlan{
   110  					DropletPath: "path",
   111  				}
   112  			})
   113  
   114  			It("returns a sequence including creating a droplet", func() {
   115  				Expect(sequence).To(matchers.MatchFuncsByName(actor.CreateDropletForApplication))
   116  			})
   117  		})
   118  	})
   119  
   120  	Describe("GetRuntimeSequence", func() {
   121  		JustBeforeEach(func() {
   122  			sequence = actor.GetRuntimeSequence(plan)
   123  		})
   124  
   125  		When("the plan requires staging a package", func() {
   126  			BeforeEach(func() {
   127  				plan = PushPlan{}
   128  			})
   129  
   130  			It("returns a sequence including staging, setting the droplet, and restarting", func() {
   131  				Expect(sequence).To(matchers.MatchFuncsByName(actor.StagePackageForApplication, actor.SetDropletForApplication, actor.RestartApplication))
   132  			})
   133  		})
   134  
   135  		When("the plan requires stopping an app", func() {
   136  			BeforeEach(func() {
   137  				plan = PushPlan{
   138  					NoStart:     true,
   139  					Application: v7action.Application{State: constant.ApplicationStarted},
   140  				}
   141  			})
   142  
   143  			It("returns a sequence including stopping the application", func() {
   144  				Expect(sequence).To(matchers.MatchFuncsByName(actor.StopApplication))
   145  			})
   146  		})
   147  
   148  		When("the plan requires setting a droplet", func() {
   149  			BeforeEach(func() {
   150  				plan = PushPlan{
   151  					DropletPath: "path",
   152  				}
   153  			})
   154  
   155  			It("returns a sequence including setting the droplet and restarting", func() {
   156  				Expect(sequence).To(matchers.MatchFuncsByName(actor.SetDropletForApplication, actor.RestartApplication))
   157  			})
   158  		})
   159  	})
   160  })