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