github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+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 It("fails with the appropriate errors", func() { 36 helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "delete-isolation-segment", "isolation-segment-name") 37 }) 38 39 Context("when the v3 api does not exist", func() { 40 var server *Server 41 42 BeforeEach(func() { 43 server = helpers.StartAndTargetServerWithoutV3API() 44 }) 45 46 AfterEach(func() { 47 server.Close() 48 }) 49 50 It("fails with error message that the minimum version is not met", func() { 51 session := helpers.CF("delete-isolation-segment", isolationSegmentName) 52 Eventually(session).Should(Say("FAILED")) 53 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.11\\.0 or higher\\.")) 54 Eventually(session).Should(Exit(1)) 55 }) 56 }) 57 58 Context("when the v3 api version is lower than the minimum version", func() { 59 var server *Server 60 61 BeforeEach(func() { 62 server = helpers.StartAndTargetServerWithV3Version("3.0.0") 63 }) 64 65 AfterEach(func() { 66 server.Close() 67 }) 68 69 It("fails with error message that the minimum version is not met", func() { 70 session := helpers.CF("delete-isolation-segment", isolationSegmentName) 71 Eventually(session).Should(Say("FAILED")) 72 Eventually(session.Err).Should(Say("This command requires CF API version 3\\.11\\.0 or higher\\.")) 73 Eventually(session).Should(Exit(1)) 74 }) 75 }) 76 }) 77 78 Context("when the environment is set up correctly", func() { 79 BeforeEach(func() { 80 helpers.LoginCF() 81 }) 82 83 Context("when the isolation segment exists", func() { 84 BeforeEach(func() { 85 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0)) 86 }) 87 88 Context("when passed the force flag", func() { 89 It("deletes the isolation segment", func() { 90 session := helpers.CF("delete-isolation-segment", "-f", isolationSegmentName) 91 userName, _ := helpers.GetCredentials() 92 Eventually(session).Should(Say("Deleting isolation segment %s as %s...", isolationSegmentName, userName)) 93 Eventually(session).Should(Say("OK")) 94 Eventually(session).Should(Exit(0)) 95 }) 96 }) 97 98 Context("when the force flag is not provided", func() { 99 var buffer *Buffer 100 101 BeforeEach(func() { 102 buffer = NewBuffer() 103 }) 104 105 Context("when 'yes' is inputted", func() { 106 BeforeEach(func() { 107 buffer.Write([]byte("y\n")) 108 }) 109 110 It("deletes the isolation segment", func() { 111 session := helpers.CFWithStdin(buffer, "delete-isolation-segment", isolationSegmentName) 112 Eventually(session).Should(Say("Really delete the isolation segment %s\\?", isolationSegmentName)) 113 114 userName, _ := helpers.GetCredentials() 115 Eventually(session).Should(Say("Deleting isolation segment %s as %s...", isolationSegmentName, userName)) 116 Eventually(session).Should(Say("OK")) 117 Eventually(session).Should(Exit(0)) 118 }) 119 }) 120 121 Context("when 'no' is inputted", func() { 122 BeforeEach(func() { 123 buffer.Write([]byte("n\n")) 124 }) 125 126 It("cancels the deletion", func() { 127 session := helpers.CFWithStdin(buffer, "delete-isolation-segment", isolationSegmentName) 128 Eventually(session).Should(Say("Really delete the isolation segment %s\\?", isolationSegmentName)) 129 Eventually(session).Should(Say("Delete cancelled")) 130 Eventually(session).Should(Exit(0)) 131 }) 132 }) 133 134 Context("when using the default value", func() { 135 BeforeEach(func() { 136 buffer.Write([]byte("\n")) 137 }) 138 139 It("cancels the deletion", func() { 140 session := helpers.CFWithStdin(buffer, "delete-isolation-segment", isolationSegmentName) 141 Eventually(session).Should(Say("Really delete the isolation segment %s\\?", isolationSegmentName)) 142 Eventually(session).Should(Say("Delete cancelled")) 143 Eventually(session).Should(Exit(0)) 144 }) 145 }) 146 }) 147 }) 148 149 Context("when the isolation segment does not exist", func() { 150 It("returns an ok and warning", func() { 151 session := helpers.CF("delete-isolation-segment", "-f", isolationSegmentName) 152 Eventually(session.Err).Should(Say("Isolation segment %s does not exist.", isolationSegmentName)) 153 Eventually(session).Should(Say("OK")) 154 Eventually(session).Should(Exit(0)) 155 }) 156 }) 157 }) 158 })