github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/integration/shared/experimental/v3_apply_manifest_command_test.go (about) 1 package experimental 2 3 import ( 4 "io/ioutil" 5 "os" 6 "path/filepath" 7 "regexp" 8 9 "code.cloudfoundry.org/cli/api/cloudcontroller/ccversion" 10 "code.cloudfoundry.org/cli/integration/helpers" 11 . "github.com/onsi/ginkgo" 12 . "github.com/onsi/gomega" 13 . "github.com/onsi/gomega/gbytes" 14 . "github.com/onsi/gomega/gexec" 15 . "github.com/onsi/gomega/ghttp" 16 ) 17 18 var _ = Describe("v3-apply-manifest command", func() { 19 var ( 20 orgName string 21 spaceName string 22 appName string 23 manifestPath string 24 appDir string 25 ) 26 27 BeforeEach(func() { 28 orgName = helpers.NewOrgName() 29 spaceName = helpers.NewSpaceName() 30 appName = helpers.PrefixedRandomName("app") 31 appDir, _ = ioutil.TempDir("", "simple-app") 32 manifestPath = filepath.Join(appDir, "manifest.yml") 33 // Ensure the file exists at the minimum 34 helpers.WriteManifest(manifestPath, map[string]interface{}{}) 35 }) 36 37 AfterEach(func() { 38 Expect(os.RemoveAll(appDir)).ToNot(HaveOccurred()) 39 }) 40 41 Describe("help", func() { 42 When("--help flag is set", func() { 43 It("displays command usage to output", func() { 44 session := helpers.CF("v3-apply-manifest", "--help") 45 46 Eventually(session).Should(Say("NAME:")) 47 Eventually(session).Should(Say("v3-apply-manifest - Applies manifest properties to an application")) 48 Eventually(session).Should(Say("USAGE:")) 49 Eventually(session).Should(Say("cf v3-apply-manifest -f APP_MANIFEST_PATH")) 50 51 Eventually(session).Should(Exit(0)) 52 }) 53 }) 54 }) 55 56 When("the -f flag is not given an arg", func() { 57 It("tells the user that the flag requires an arg, prints help text, and exits 1", func() { 58 session := helpers.CF("v3-apply-manifest", "-f") 59 60 Eventually(session.Err).Should(Say("Incorrect Usage: expected argument for flag `-f'")) 61 Eventually(session).Should(Say("NAME:")) 62 Eventually(session).Should(Exit(1)) 63 }) 64 }) 65 66 When("the -f flag path does not exist", func() { 67 It("tells the user that the provided path doesn't exist, prints help text, and exits 1", func() { 68 session := helpers.CF("v3-apply-manifest", "-f", "path/that/does/not/exist") 69 70 Eventually(session.Err).Should(Say("Incorrect Usage: The specified path 'path/that/does/not/exist' does not exist.")) 71 Eventually(session).Should(Say("NAME:")) 72 Eventually(session).Should(Exit(1)) 73 }) 74 }) 75 76 When("the environment is not setup correctly", func() { 77 When("the v3 api version is lower than the minimum version", func() { 78 var server *Server 79 80 BeforeEach(func() { 81 server = helpers.StartAndTargetServerWithAPIVersions(helpers.DefaultV2Version, ccversion.MinV3ClientVersion) 82 }) 83 84 AfterEach(func() { 85 server.Close() 86 }) 87 88 It("fails with error message that the minimum version is not met", func() { 89 session := helpers.CF("v3-apply-manifest", "-f", manifestPath) 90 Eventually(session).Should(Say("FAILED")) 91 Eventually(session.Err).Should(Say(`This command requires CF API version 3\.27\.0 or higher\.`)) 92 Eventually(session).Should(Exit(1)) 93 }) 94 }) 95 96 It("fails with the appropriate errors", func() { 97 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "v3-apply-manifest", "-f", manifestPath) 98 }) 99 }) 100 101 When("the environment is set up correctly", func() { 102 BeforeEach(func() { 103 helpers.SetupCF(orgName, spaceName) 104 }) 105 106 AfterEach(func() { 107 helpers.QuickDeleteOrg(orgName) 108 }) 109 110 When("the app exists", func() { 111 BeforeEach(func() { 112 helpers.WithHelloWorldApp(func(appDir string) { 113 Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName)).Should(Exit(0)) 114 }) 115 }) 116 117 When("the app name in the manifest is missing", func() { 118 BeforeEach(func() { 119 helpers.WriteManifest(manifestPath, map[string]interface{}{ 120 "applications": []map[string]interface{}{ 121 { 122 "instances": 3, 123 }, 124 }, 125 }) 126 }) 127 128 It("reports an error", func() { 129 session := helpers.CF("v3-apply-manifest", "-f", manifestPath) 130 Eventually(session.Err).Should(Say("Found an application with no name specified")) 131 Eventually(session).Should(Say("FAILED")) 132 Eventually(session).Should(Exit(1)) 133 }) 134 }) 135 136 When("the app name in the manifest doesn't exist", func() { 137 var invalidAppName string 138 BeforeEach(func() { 139 invalidAppName = "no-such-app" 140 helpers.WriteManifest(manifestPath, map[string]interface{}{ 141 "applications": []map[string]interface{}{ 142 { 143 "name": invalidAppName, 144 "instances": 3, 145 }, 146 }, 147 }) 148 }) 149 150 It("reports an error", func() { 151 session := helpers.CF("v3-apply-manifest", "-f", manifestPath) 152 Eventually(session.Err).Should(Say("App %s not found", invalidAppName)) 153 Eventually(session).Should(Say("FAILED")) 154 155 Eventually(session).Should(Exit(1)) 156 }) 157 }) 158 159 When("the app name in the manifest does exist", func() { 160 When("the instances value is negative", func() { 161 BeforeEach(func() { 162 helpers.WriteManifest(manifestPath, map[string]interface{}{ 163 "applications": []map[string]interface{}{ 164 { 165 "name": appName, 166 "instances": -1, 167 }, 168 }, 169 }) 170 }) 171 172 It("reports an error", func() { 173 session := helpers.CF("v3-apply-manifest", "-f", manifestPath) 174 Eventually(session.Err).Should(Say("Instances must be greater than or equal to 0")) 175 Eventually(session).Should(Say("FAILED")) 176 177 Eventually(session).Should(Exit(1)) 178 }) 179 }) 180 181 When("the instances value is more than the space quota limit", func() { 182 BeforeEach(func() { 183 Eventually(helpers.CF("create-space-quota", "some-space-quota-name", "-a", "4")).Should(Exit(0)) 184 Eventually(helpers.CF("set-space-quota", spaceName, "some-space-quota-name")).Should(Exit(0)) 185 helpers.WriteManifest(manifestPath, map[string]interface{}{ 186 "applications": []map[string]interface{}{ 187 { 188 "name": appName, 189 "instances": 5, 190 }, 191 }, 192 }) 193 }) 194 195 It("reports an error", func() { 196 session := helpers.CF("v3-apply-manifest", "-f", manifestPath) 197 Eventually(session.Err).Should(Say("memory space_quota_exceeded, app_instance_limit space_app_instance_limit_exceeded")) 198 Eventually(session).Should(Say("FAILED")) 199 200 Eventually(session).Should(Exit(1)) 201 }) 202 }) 203 204 When("instances are specified correctly", func() { 205 BeforeEach(func() { 206 helpers.WriteManifest(manifestPath, map[string]interface{}{ 207 "applications": []map[string]interface{}{ 208 { 209 "name": appName, 210 "instances": 3, 211 }, 212 }, 213 }) 214 }) 215 216 It("displays the experimental warning", func() { 217 session := helpers.CF("v3-apply-manifest", "-f", manifestPath) 218 Eventually(session.Err).Should(Say("This command is in EXPERIMENTAL stage and may change without notice")) 219 Eventually(session).Should(Exit()) 220 }) 221 222 It("rescales the app", func() { 223 session := helpers.CF("app", appName) 224 userName, _ := helpers.GetCredentials() 225 Eventually(session).Should(Say(`instances:\s+%s`, "1/1")) 226 Eventually(session).Should(Exit()) 227 228 session = helpers.CF("v3-apply-manifest", "-f", manifestPath) 229 Eventually(session).Should(Say("Applying manifest %s in org %s / space %s as %s...", regexp.QuoteMeta(manifestPath), orgName, spaceName, userName)) 230 Eventually(session).Should(Exit()) 231 232 session = helpers.CF("app", appName) 233 Eventually(session).Should(Say(`instances:\s+%s`, `\d/3`)) 234 Eventually(session).Should(Exit()) 235 }) 236 }) 237 }) 238 239 }) 240 }) 241 })