github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+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 ) 10 11 var _ = Describe("delete-isolation-segment command", func() { 12 var isolationSegmentName string 13 14 BeforeEach(func() { 15 isolationSegmentName = helpers.IsolationSegmentName() 16 }) 17 18 Describe("help", func() { 19 Context("when --help flag is set", func() { 20 It("Displays command usage to output", func() { 21 session := helpers.CF("delete-isolation-segment", "--help") 22 Eventually(session).Should(Say("NAME:")) 23 Eventually(session).Should(Say("delete-isolation-segment - Delete an isolation segment")) 24 Eventually(session).Should(Say("USAGE:")) 25 Eventually(session).Should(Say("cf delete-isolation-segment SEGMENT_NAME")) 26 Eventually(session).Should(Say("SEE ALSO:")) 27 Eventually(session).Should(Say("disable-org-isolation, isolation-segments")) 28 Eventually(session).Should(Exit(0)) 29 }) 30 }) 31 }) 32 33 Context("when the environment is not setup correctly", func() { 34 Context("when no API endpoint is set", func() { 35 BeforeEach(func() { 36 helpers.UnsetAPI() 37 }) 38 39 It("fails with no API endpoint set message", func() { 40 session := helpers.CF("delete-isolation-segment", isolationSegmentName) 41 Eventually(session).Should(Say("FAILED")) 42 Eventually(session.Err).Should(Say("No API endpoint set. Use 'cf login' or 'cf api' to target an endpoint.")) 43 Eventually(session).Should(Exit(1)) 44 }) 45 }) 46 47 Context("when not logged in", func() { 48 BeforeEach(func() { 49 helpers.LogoutCF() 50 }) 51 52 It("fails with not logged in message", func() { 53 session := helpers.CF("delete-isolation-segment", isolationSegmentName) 54 Eventually(session).Should(Say("FAILED")) 55 Eventually(session.Err).Should(Say("Not logged in. Use 'cf login' to log in.")) 56 Eventually(session).Should(Exit(1)) 57 }) 58 }) 59 }) 60 61 Context("when the environment is set up correctly", func() { 62 BeforeEach(func() { 63 helpers.LoginCF() 64 }) 65 66 Context("when the isolation segment exists", func() { 67 BeforeEach(func() { 68 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0)) 69 }) 70 71 Context("when passed the force flag", func() { 72 It("deletes the isolation segment", func() { 73 session := helpers.CF("delete-isolation-segment", "-f", isolationSegmentName) 74 userName, _ := helpers.GetCredentials() 75 Eventually(session).Should(Say("Deleting isolation segment %s as %s...", isolationSegmentName, userName)) 76 Eventually(session).Should(Say("OK")) 77 Eventually(session).Should(Exit(0)) 78 }) 79 }) 80 81 Context("when the force flag is not provided", func() { 82 var buffer *Buffer 83 84 BeforeEach(func() { 85 buffer = NewBuffer() 86 }) 87 88 Context("when 'yes' is inputted", func() { 89 BeforeEach(func() { 90 buffer.Write([]byte("y\n")) 91 }) 92 93 It("deletes the isolation segment", func() { 94 session := helpers.CFWithStdin(buffer, "delete-isolation-segment", isolationSegmentName) 95 Eventually(session).Should(Say("Really delete the isolation segment %s\\?", isolationSegmentName)) 96 97 userName, _ := helpers.GetCredentials() 98 Eventually(session).Should(Say("Deleting isolation segment %s as %s...", isolationSegmentName, userName)) 99 Eventually(session).Should(Say("OK")) 100 Eventually(session).Should(Exit(0)) 101 }) 102 }) 103 104 Context("when 'no' is inputted", func() { 105 BeforeEach(func() { 106 buffer.Write([]byte("n\n")) 107 }) 108 109 It("cancels the deletion", func() { 110 session := helpers.CFWithStdin(buffer, "delete-isolation-segment", isolationSegmentName) 111 Eventually(session).Should(Say("Really delete the isolation segment %s\\?", isolationSegmentName)) 112 Eventually(session).Should(Say("Delete cancelled")) 113 Eventually(session).Should(Exit(0)) 114 }) 115 }) 116 117 Context("when using the default value", func() { 118 BeforeEach(func() { 119 buffer.Write([]byte("\n")) 120 }) 121 122 It("cancels the deletion", func() { 123 session := helpers.CFWithStdin(buffer, "delete-isolation-segment", isolationSegmentName) 124 Eventually(session).Should(Say("Really delete the isolation segment %s\\?", isolationSegmentName)) 125 Eventually(session).Should(Say("Delete cancelled")) 126 Eventually(session).Should(Exit(0)) 127 }) 128 }) 129 }) 130 }) 131 132 Context("when the isolation segment does not exist", func() { 133 It("returns an ok and warning", func() { 134 session := helpers.CF("delete-isolation-segment", "-f", isolationSegmentName) 135 Eventually(session.Err).Should(Say("Isolation segment %s does not exist.", isolationSegmentName)) 136 Eventually(session).Should(Say("OK")) 137 Eventually(session).Should(Exit(0)) 138 }) 139 }) 140 }) 141 })