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