github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/integration/isolated/delete_isolation_segment_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 . "github.com/onsi/gomega/ghttp" 10 ) 11 12 var _ = Describe("delete-isolation-segment command", func() { 13 var isolationSegmentName string 14 15 BeforeEach(func() { 16 isolationSegmentName = helpers.NewIsolationSegmentName() 17 }) 18 19 Describe("help", func() { 20 Context("when --help flag is set", func() { 21 It("Displays command usage to output", func() { 22 session := helpers.CF("delete-isolation-segment", "--help") 23 Eventually(session).Should(Say("NAME:")) 24 Eventually(session).Should(Say("delete-isolation-segment - Delete an isolation segment")) 25 Eventually(session).Should(Say("USAGE:")) 26 Eventually(session).Should(Say("cf delete-isolation-segment SEGMENT_NAME")) 27 Eventually(session).Should(Say("SEE ALSO:")) 28 Eventually(session).Should(Say("disable-org-isolation, isolation-segments")) 29 Eventually(session).Should(Exit(0)) 30 }) 31 }) 32 }) 33 34 Context("when the environment is not setup correctly", func() { 35 Context("when no API endpoint is set", func() { 36 BeforeEach(func() { 37 helpers.UnsetAPI() 38 }) 39 40 It("fails with no API endpoint set message", func() { 41 session := helpers.CF("delete-isolation-segment", isolationSegmentName) 42 Eventually(session).Should(Say("FAILED")) 43 Eventually(session.Err).Should(Say("No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint.")) 44 Eventually(session).Should(Exit(1)) 45 }) 46 }) 47 48 Context("when the v3 api does not exist", func() { 49 var server *Server 50 51 BeforeEach(func() { 52 server = helpers.StartAndTargetServerWithoutV3API() 53 }) 54 55 AfterEach(func() { 56 server.Close() 57 }) 58 59 It("fails with error message that the minimum version is not met", func() { 60 session := helpers.CF("delete-isolation-segment", isolationSegmentName) 61 Eventually(session).Should(Say("FAILED")) 62 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.11\\.0 or higher\\.")) 63 Eventually(session).Should(Exit(1)) 64 }) 65 }) 66 67 Context("when the v3 api version is lower than the minimum version", func() { 68 var server *Server 69 70 BeforeEach(func() { 71 server = helpers.StartAndTargetServerWithV3Version("3.0.0") 72 }) 73 74 AfterEach(func() { 75 server.Close() 76 }) 77 78 It("fails with error message that the minimum version is not met", func() { 79 session := helpers.CF("delete-isolation-segment", isolationSegmentName) 80 Eventually(session).Should(Say("FAILED")) 81 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.11\\.0 or higher\\.")) 82 Eventually(session).Should(Exit(1)) 83 }) 84 }) 85 86 Context("when not logged in", func() { 87 BeforeEach(func() { 88 helpers.LogoutCF() 89 }) 90 91 It("fails with not logged in message", func() { 92 session := helpers.CF("delete-isolation-segment", isolationSegmentName) 93 Eventually(session).Should(Say("FAILED")) 94 Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' to log in.")) 95 Eventually(session).Should(Exit(1)) 96 }) 97 }) 98 }) 99 100 Context("when the environment is set up correctly", func() { 101 BeforeEach(func() { 102 helpers.LoginCF() 103 }) 104 105 Context("when the isolation segment exists", func() { 106 BeforeEach(func() { 107 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0)) 108 }) 109 110 Context("when passed the force flag", func() { 111 It("deletes the isolation segment", func() { 112 session := helpers.CF("delete-isolation-segment", "-f", isolationSegmentName) 113 userName, _ := helpers.GetCredentials() 114 Eventually(session).Should(Say("Deleting isolation segment %s as %s...", isolationSegmentName, userName)) 115 Eventually(session).Should(Say("OK")) 116 Eventually(session).Should(Exit(0)) 117 }) 118 }) 119 120 Context("when the force flag is not provided", func() { 121 var buffer *Buffer 122 123 BeforeEach(func() { 124 buffer = NewBuffer() 125 }) 126 127 Context("when 'yes' is inputted", func() { 128 BeforeEach(func() { 129 buffer.Write([]byte("y\n")) 130 }) 131 132 It("deletes the isolation segment", func() { 133 session := helpers.CFWithStdin(buffer, "delete-isolation-segment", isolationSegmentName) 134 Eventually(session).Should(Say("Really delete the isolation segment %s\\?", isolationSegmentName)) 135 136 userName, _ := helpers.GetCredentials() 137 Eventually(session).Should(Say("Deleting isolation segment %s as %s...", isolationSegmentName, userName)) 138 Eventually(session).Should(Say("OK")) 139 Eventually(session).Should(Exit(0)) 140 }) 141 }) 142 143 Context("when 'no' is inputted", func() { 144 BeforeEach(func() { 145 buffer.Write([]byte("n\n")) 146 }) 147 148 It("cancels the deletion", func() { 149 session := helpers.CFWithStdin(buffer, "delete-isolation-segment", isolationSegmentName) 150 Eventually(session).Should(Say("Really delete the isolation segment %s\\?", isolationSegmentName)) 151 Eventually(session).Should(Say("Delete cancelled")) 152 Eventually(session).Should(Exit(0)) 153 }) 154 }) 155 156 Context("when using the default value", func() { 157 BeforeEach(func() { 158 buffer.Write([]byte("\n")) 159 }) 160 161 It("cancels the deletion", func() { 162 session := helpers.CFWithStdin(buffer, "delete-isolation-segment", isolationSegmentName) 163 Eventually(session).Should(Say("Really delete the isolation segment %s\\?", isolationSegmentName)) 164 Eventually(session).Should(Say("Delete cancelled")) 165 Eventually(session).Should(Exit(0)) 166 }) 167 }) 168 }) 169 }) 170 171 Context("when the isolation segment does not exist", func() { 172 It("returns an ok and warning", func() { 173 session := helpers.CF("delete-isolation-segment", "-f", isolationSegmentName) 174 Eventually(session.Err).Should(Say("Isolation segment %s does not exist.", isolationSegmentName)) 175 Eventually(session).Should(Say("OK")) 176 Eventually(session).Should(Exit(0)) 177 }) 178 }) 179 }) 180 })