github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/integration/isolated/delete_org_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-org command", func() { 12 Context("when the environment is not setup correctly", func() { 13 It("fails with the appropriate errors", func() { 14 helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "delete-org", "some-org") 15 }) 16 }) 17 18 Context("when the org name is not provided", func() { 19 It("displays an error and help", func() { 20 session := helpers.CF("delete-org") 21 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `ORG` was not provided")) 22 Eventually(session).Should(Say("USAGE")) 23 Eventually(session).Should(Exit(1)) 24 }) 25 }) 26 27 Context("when the org does not exist", func() { 28 BeforeEach(func() { 29 helpers.LoginCF() 30 }) 31 32 It("displays a warning and exits 0", func() { 33 username, _ := helpers.GetCredentials() 34 session := helpers.CF("delete-org", "-f", "please-do-not-exist-in-real-life") 35 Eventually(session).Should(Say("Deleting org please-do-not-exist-in-real-life as %s...", username)) 36 Eventually(session).Should(Say("Org please-do-not-exist-in-real-life does not exist.")) 37 Eventually(session).Should(Say("OK")) 38 Eventually(session).Should(Exit(0)) 39 }) 40 }) 41 42 Context("when the org exists", func() { 43 var orgName string 44 45 BeforeEach(func() { 46 helpers.LoginCF() 47 48 orgName = helpers.NewOrgName() 49 helpers.CreateOrgAndSpace(orgName, helpers.NewSpaceName()) 50 }) 51 52 AfterEach(func() { 53 helpers.QuickDeleteOrgIfExists(orgName) 54 }) 55 56 Context("when the -f flag not is provided", func() { 57 var buffer *Buffer 58 59 BeforeEach(func() { 60 buffer = NewBuffer() 61 }) 62 63 Context("when the user enters 'y'", func() { 64 BeforeEach(func() { 65 buffer.Write([]byte("y\n")) 66 }) 67 68 It("deletes the org", func() { 69 username, _ := helpers.GetCredentials() 70 session := helpers.CFWithStdin(buffer, "delete-org", orgName) 71 Eventually(session).Should(Say("Really delete the org %s, including its spaces, apps, service instances, routes, private domains and space-scoped service brokers\\?", orgName)) 72 Eventually(session).Should(Say("Deleting org %s as %s...", orgName, username)) 73 Eventually(session).Should(Say("OK")) 74 Eventually(session).Should(Exit(0)) 75 Eventually(helpers.CF("org", orgName)).Should(Exit(1)) 76 }) 77 }) 78 79 Context("when the user enters 'n'", func() { 80 BeforeEach(func() { 81 buffer.Write([]byte("n\n")) 82 }) 83 84 It("does not delete the org", func() { 85 session := helpers.CFWithStdin(buffer, "delete-org", orgName) 86 Eventually(session).Should(Say("Really delete the org %s, including its spaces, apps, service instances, routes, private domains and space-scoped service brokers\\?", orgName)) 87 Eventually(session).Should(Say("Delete cancelled")) 88 Eventually(session).Should(Exit(0)) 89 Eventually(helpers.CF("org", orgName)).Should(Exit(0)) 90 }) 91 }) 92 93 Context("when the user enters the default input (hits return)", func() { 94 BeforeEach(func() { 95 buffer.Write([]byte("\n")) 96 }) 97 98 It("does not delete the org", func() { 99 session := helpers.CFWithStdin(buffer, "delete-org", orgName) 100 Eventually(session).Should(Say("Really delete the org %s, including its spaces, apps, service instances, routes, private domains and space-scoped service brokers\\?", orgName)) 101 Eventually(session).Should(Say("Delete cancelled")) 102 Eventually(session).Should(Exit(0)) 103 Eventually(helpers.CF("org", orgName)).Should(Exit(0)) 104 }) 105 }) 106 107 Context("when the user enters an invalid answer", func() { 108 BeforeEach(func() { 109 // The second '\n' is intentional. Otherwise the buffer will be 110 // closed while the interaction is still waiting for input; it gets 111 // an EOF and causes an error. 112 buffer.Write([]byte("wat\n\n")) 113 }) 114 115 It("asks again", func() { 116 session := helpers.CFWithStdin(buffer, "delete-org", orgName) 117 Eventually(session).Should(Say("Really delete the org %s, including its spaces, apps, service instances, routes, private domains and space-scoped service brokers\\?", orgName)) 118 Eventually(session).Should(Say("invalid input \\(not y, n, yes, or no\\)")) 119 Eventually(session).Should(Say("Really delete the org %s, including its spaces, apps, service instances, routes, private domains and space-scoped service brokers\\?", orgName)) 120 Eventually(session).Should(Exit(0)) 121 Eventually(helpers.CF("org", orgName)).Should(Exit(0)) 122 }) 123 }) 124 }) 125 126 Context("when the -f flag is provided", func() { 127 It("deletes the org", func() { 128 username, _ := helpers.GetCredentials() 129 session := helpers.CF("delete-org", orgName, "-f") 130 Eventually(session).Should(Say("Deleting org %s as %s...", orgName, username)) 131 Eventually(session).Should(Say("OK")) 132 Eventually(session).Should(Exit(0)) 133 Eventually(helpers.CF("org", orgName)).Should(Exit(1)) 134 }) 135 }) 136 }) 137 138 Context("when deleting an org that is targeted", func() { 139 var orgName string 140 141 BeforeEach(func() { 142 helpers.LoginCF() 143 144 orgName = helpers.NewOrgName() 145 spaceName := helpers.NewSpaceName() 146 helpers.CreateOrgAndSpace(orgName, spaceName) 147 helpers.TargetOrgAndSpace(orgName, spaceName) 148 }) 149 150 AfterEach(func() { 151 helpers.QuickDeleteOrgIfExists(orgName) 152 }) 153 154 It("clears the targeted org and space", func() { 155 session := helpers.CF("delete-org", orgName, "-f") 156 Eventually(session).Should(Exit(0)) 157 158 session = helpers.CF("target") 159 Eventually(session).Should(Say("No org or space targeted, use 'cf target -o ORG -s SPACE'")) 160 Eventually(session).Should(Exit(0)) 161 }) 162 }) 163 164 Context("when deleting an org that is not targeted", func() { 165 var orgName string 166 167 BeforeEach(func() { 168 helpers.LoginCF() 169 170 orgName = helpers.NewOrgName() 171 helpers.TargetOrgAndSpace(ReadOnlyOrg, ReadOnlySpace) 172 }) 173 174 It("does not clear the targeted org and space", func() { 175 session := helpers.CF("delete-org", orgName, "-f") 176 Eventually(session).Should(Exit(0)) 177 178 session = helpers.CF("target") 179 Eventually(session).Should(Say("org:\\s+%s", ReadOnlyOrg)) 180 Eventually(session).Should(Say("space:\\s+%s", ReadOnlySpace)) 181 Eventually(session).Should(Exit(0)) 182 }) 183 }) 184 })