github.com/wanddynosios/cli@v7.1.0+incompatible/integration/v6/push/instances_test.go (about)

     1  package push
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/integration/helpers"
     5  
     6  	. "github.com/onsi/ginkgo"
     7  	. "github.com/onsi/gomega"
     8  	. "github.com/onsi/gomega/gbytes"
     9  	. "github.com/onsi/gomega/gexec"
    10  )
    11  
    12  var _ = Describe("push with different instances values", func() {
    13  	var (
    14  		appName string
    15  	)
    16  
    17  	BeforeEach(func() {
    18  		appName = helpers.NewAppName()
    19  	})
    20  
    21  	When("instances flag is provided", func() {
    22  		When("instances flag is greater than 0", func() {
    23  			It("pushes an app with specified number of instances", func() {
    24  				helpers.WithHelloWorldApp(func(dir string) {
    25  					By("pushing an app with 2 instances")
    26  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir},
    27  						PushCommandName, appName,
    28  						"-i", "2",
    29  					)
    30  					Eventually(session).Should(Say(`\s+instances:\s+2`))
    31  					Eventually(session).Should(Exit(0))
    32  
    33  					session = helpers.CF("app", appName)
    34  					Eventually(session).Should(Say(`instances:\s+\d/2`))
    35  					Eventually(session).Should(Exit(0))
    36  
    37  					By("updating an app with 1 instance")
    38  					session = helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir},
    39  						PushCommandName, appName,
    40  						"-i", "1",
    41  					)
    42  					Eventually(session).Should(Say(`\-\s+instances:\s+2`))
    43  					Eventually(session).Should(Say(`\+\s+instances:\s+1`))
    44  					Eventually(session).Should(Exit(0))
    45  
    46  					session = helpers.CF("app", appName)
    47  					Eventually(session).Should(Say(`instances:\s+\d/1`))
    48  					Eventually(session).Should(Exit(0))
    49  				})
    50  			})
    51  		})
    52  
    53  		When("instances flag is set to 0", func() {
    54  			It("pushes an app with 0 instances", func() {
    55  				helpers.WithHelloWorldApp(func(dir string) {
    56  					By("pushing an app with 0 instances")
    57  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir},
    58  						PushCommandName, appName,
    59  						"-i", "0",
    60  					)
    61  
    62  					Eventually(session).Should(Say(`\s+instances:\s+0`))
    63  					Eventually(session).Should(Exit(0))
    64  
    65  					session = helpers.CF("app", appName)
    66  					Eventually(session).Should(Say("There are no running instances of this process."))
    67  					Eventually(session).Should(Exit(0))
    68  
    69  					By("updating an app to 1 instance")
    70  					session = helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir},
    71  						PushCommandName, appName,
    72  						"-i", "1",
    73  					)
    74  					Eventually(session).Should(Say(`\-\s+instances:\s+0`))
    75  					Eventually(session).Should(Say(`\+\s+instances:\s+1`))
    76  					Eventually(session).Should(Exit(0))
    77  
    78  					session = helpers.CF("app", appName)
    79  					Eventually(session).Should(Say(`instances:\s+\d/1`))
    80  					Eventually(session).Should(Exit(0))
    81  
    82  					By("updating an app back to 0 instances")
    83  					session = helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir},
    84  						PushCommandName, appName,
    85  						"-i", "0",
    86  					)
    87  					Eventually(session).Should(Say(`\-\s+instances:\s+1`))
    88  					Eventually(session).Should(Say(`\+\s+instances:\s+0`))
    89  					Eventually(session).Should(Exit(0))
    90  
    91  					session = helpers.CF("app", appName)
    92  					Eventually(session).Should(Say("There are no running instances of this process."))
    93  					Eventually(session).Should(Exit(0))
    94  				})
    95  			})
    96  		})
    97  	})
    98  
    99  	When("instances flag is not provided", func() {
   100  		When("app does not exist", func() {
   101  			It("pushes an app with default number of instances", func() {
   102  				helpers.WithHelloWorldApp(func(dir string) {
   103  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir},
   104  						PushCommandName, appName,
   105  					)
   106  					Eventually(session).Should(Say(`\s+instances:\s+1`))
   107  					Eventually(session).Should(Exit(0))
   108  				})
   109  
   110  				session := helpers.CF("app", appName)
   111  				Eventually(session).Should(Say(`instances:\s+\d/1`))
   112  				Eventually(session).Should(Exit(0))
   113  			})
   114  		})
   115  
   116  		When("app exists with some instances", func() {
   117  			It("does not update the number of instances", func() {
   118  				helpers.WithHelloWorldApp(func(dir string) {
   119  					By("pushing an app with 2 instances")
   120  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir},
   121  						PushCommandName, appName,
   122  						"-i", "2",
   123  					)
   124  					Eventually(session).Should(Say(`\s+instances:\s+2`))
   125  					Eventually(session).Should(Exit(0))
   126  
   127  					session = helpers.CF("app", appName)
   128  					Eventually(session).Should(Say(`instances:\s+\d/2`))
   129  					Eventually(session).Should(Exit(0))
   130  
   131  					By("pushing an app with no instances specified")
   132  					session = helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir},
   133  						PushCommandName, appName,
   134  					)
   135  					Eventually(session).Should(Say(`\s+instances:\s+2`))
   136  					Eventually(session).Should(Exit(0))
   137  				})
   138  			})
   139  		})
   140  	})
   141  })