github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/integration/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  	Context("when instances flag is provided", func() {
    22  		Context("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  		Context("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  					Eventually(session).Should(Say("\\s+instances:\\s+0"))
    62  					Eventually(session).Should(Exit(0))
    63  
    64  					session = helpers.CF("app", appName)
    65  					Eventually(session).Should(Say("instances:\\s+\\d/0"))
    66  					Eventually(session).Should(Exit(0))
    67  
    68  					By("updating an app to 1 instance")
    69  					session = helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir},
    70  						PushCommandName, appName,
    71  						"-i", "1",
    72  					)
    73  					Eventually(session).Should(Say("\\-\\s+instances:\\s+0"))
    74  					Eventually(session).Should(Say("\\+\\s+instances:\\s+1"))
    75  					Eventually(session).Should(Exit(0))
    76  
    77  					session = helpers.CF("app", appName)
    78  					Eventually(session).Should(Say("instances:\\s+\\d/1"))
    79  					Eventually(session).Should(Exit(0))
    80  
    81  					By("updating an app back to 0 instances")
    82  					session = helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir},
    83  						PushCommandName, appName,
    84  						"-i", "0",
    85  					)
    86  					Eventually(session).Should(Say("\\-\\s+instances:\\s+1"))
    87  					Eventually(session).Should(Say("\\+\\s+instances:\\s+0"))
    88  					Eventually(session).Should(Exit(0))
    89  
    90  					session = helpers.CF("app", appName)
    91  					Eventually(session).Should(Say("instances:\\s+\\d/0"))
    92  					Eventually(session).Should(Exit(0))
    93  				})
    94  			})
    95  		})
    96  	})
    97  
    98  	Context("when instances flag is not provided", func() {
    99  		Context("when app does not exist", func() {
   100  			It("pushes an app with default number of instances", func() {
   101  				helpers.WithHelloWorldApp(func(dir string) {
   102  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir},
   103  						PushCommandName, appName,
   104  					)
   105  					Eventually(session).Should(Say("\\s+instances:\\s+1"))
   106  					Eventually(session).Should(Exit(0))
   107  				})
   108  
   109  				session := helpers.CF("app", appName)
   110  				Eventually(session).Should(Say("instances:\\s+\\d/1"))
   111  				Eventually(session).Should(Exit(0))
   112  			})
   113  		})
   114  
   115  		Context("when app exists with some instances", func() {
   116  			It("does not update the number of instances", func() {
   117  				helpers.WithHelloWorldApp(func(dir string) {
   118  					By("pushing an app with 2 instances")
   119  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir},
   120  						PushCommandName, appName,
   121  						"-i", "2",
   122  					)
   123  					Eventually(session).Should(Say("\\s+instances:\\s+2"))
   124  					Eventually(session).Should(Exit(0))
   125  
   126  					session = helpers.CF("app", appName)
   127  					Eventually(session).Should(Say("instances:\\s+\\d/2"))
   128  					Eventually(session).Should(Exit(0))
   129  
   130  					By("pushing an app with no instances specified")
   131  					session = helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir},
   132  						PushCommandName, appName,
   133  					)
   134  					Eventually(session).Should(Say("\\s+instances:\\s+2"))
   135  					Eventually(session).Should(Exit(0))
   136  				})
   137  			})
   138  		})
   139  	})
   140  })