github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+incompatible/integration/v7/isolated/delete_command_test.go (about) 1 package isolated 2 3 import ( 4 "code.cloudfoundry.org/cli/integration/helpers" 5 . "github.com/onsi/ginkgo" 6 . "github.com/onsi/gomega" 7 . "github.com/onsi/gomega/gbytes" 8 . "github.com/onsi/gomega/gexec" 9 ) 10 11 var _ = Describe("delete command", func() { 12 var ( 13 orgName string 14 spaceName string 15 appName string 16 ) 17 18 BeforeEach(func() { 19 orgName = helpers.NewOrgName() 20 spaceName = helpers.NewSpaceName() 21 appName = helpers.PrefixedRandomName("app") 22 }) 23 24 When("--help flag is set", func() { 25 It("Displays command usage to output", func() { 26 session := helpers.CF("delete", "--help") 27 Eventually(session).Should(Say("NAME:")) 28 Eventually(session).Should(Say("delete - Delete an app")) 29 Eventually(session).Should(Say("USAGE:")) 30 Eventually(session).Should(Say(`cf delete APP_NAME \[-r\] \[-f\]`)) 31 Eventually(session).Should(Say("OPTIONS:")) 32 Eventually(session).Should(Say(`\s+-f\s+Force deletion without confirmation`)) 33 Eventually(session).Should(Say(`\s+-r\s+Also delete any mapped routes \[Not currently functional\]`)) 34 Eventually(session).Should(Exit(0)) 35 }) 36 }) 37 38 When("the app name is not provided", func() { 39 It("tells the user that the app name is required, prints help text, and exits 1", func() { 40 session := helpers.CF("delete") 41 42 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided")) 43 Eventually(session).Should(Say("NAME:")) 44 Eventually(session).Should(Exit(1)) 45 }) 46 }) 47 48 When("the environment is not setup correctly", func() { 49 It("fails with the appropriate errors", func() { 50 helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "delete", "-f", appName) 51 }) 52 }) 53 54 When("the environment is setup correctly", func() { 55 BeforeEach(func() { 56 helpers.SetupCF(orgName, spaceName) 57 }) 58 59 AfterEach(func() { 60 helpers.QuickDeleteOrg(orgName) 61 }) 62 63 When("the app does not exist", func() { 64 When("the -f flag is provided", func() { 65 It("it displays the app does not exist", func() { 66 username, _ := helpers.GetCredentials() 67 session := helpers.CF("delete", appName, "-f") 68 Eventually(session).Should(Say("Deleting app %s in org %s / space %s as %s...", appName, orgName, spaceName, username)) 69 Eventually(session).Should(Say("App %s does not exist", appName)) 70 Eventually(session).Should(Say("OK")) 71 Eventually(session).Should(Exit(0)) 72 }) 73 }) 74 75 When("the -f flag not is provided", func() { 76 var buffer *Buffer 77 78 BeforeEach(func() { 79 buffer = NewBuffer() 80 }) 81 82 When("the user enters 'y'", func() { 83 BeforeEach(func() { 84 buffer.Write([]byte("y\n")) 85 }) 86 87 It("it displays the app does not exist", func() { 88 username, _ := helpers.GetCredentials() 89 session := helpers.CFWithStdin(buffer, "delete", appName) 90 Eventually(session).Should(Say(`Really delete the app %s\? \[yN\]`, appName)) 91 Eventually(session).Should(Say("Deleting app %s in org %s / space %s as %s...", appName, orgName, spaceName, username)) 92 Eventually(session).Should(Say("App %s does not exist", appName)) 93 Eventually(session).Should(Say("OK")) 94 Eventually(session).Should(Exit(0)) 95 }) 96 }) 97 98 When("the user enters 'n'", func() { 99 BeforeEach(func() { 100 buffer.Write([]byte("n\n")) 101 }) 102 103 It("does not delete the app", func() { 104 session := helpers.CFWithStdin(buffer, "delete", appName) 105 Eventually(session).Should(Say(`Really delete the app %s\? \[yN\]`, appName)) 106 Eventually(session).Should(Say("Delete cancelled")) 107 Eventually(session).Should(Exit(0)) 108 }) 109 }) 110 111 When("the user enters the default input (hits return)", func() { 112 BeforeEach(func() { 113 buffer.Write([]byte("\n")) 114 }) 115 116 It("does not delete the app", func() { 117 session := helpers.CFWithStdin(buffer, "delete", appName) 118 Eventually(session).Should(Say(`Really delete the app %s\? \[yN\]`, appName)) 119 Eventually(session).Should(Say("Delete cancelled")) 120 Eventually(session).Should(Exit(0)) 121 }) 122 }) 123 124 When("the user enters an invalid answer", func() { 125 BeforeEach(func() { 126 // The second '\n' is intentional. Otherwise the buffer will be 127 // closed while the interaction is still waiting for input; it gets 128 // an EOF and causes an error. 129 buffer.Write([]byte("wat\n\n")) 130 }) 131 132 It("asks again", func() { 133 session := helpers.CFWithStdin(buffer, "delete", appName) 134 Eventually(session).Should(Say(`Really delete the app %s\? \[yN\]`, appName)) 135 Eventually(session).Should(Say(`invalid input \(not y, n, yes, or no\)`)) 136 Eventually(session).Should(Say(`Really delete the app %s\? \[yN\]`, appName)) 137 Eventually(session).Should(Exit(0)) 138 }) 139 }) 140 }) 141 }) 142 143 When("the app exists", func() { 144 BeforeEach(func() { 145 helpers.WithHelloWorldApp(func(appDir string) { 146 Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "push", appName)).Should(Exit(0)) 147 }) 148 }) 149 150 It("deletes the app", func() { 151 session := helpers.CF("delete", appName, "-f") 152 username, _ := helpers.GetCredentials() 153 Eventually(session).Should(Say("Deleting app %s in org %s / space %s as %s...", appName, orgName, spaceName, username)) 154 Eventually(session).Should(Say("OK")) 155 Eventually(session).Should(Exit(0)) 156 157 Eventually(helpers.CF("app", appName)).Should(Exit(1)) 158 }) 159 }) 160 }) 161 })