github.com/loafoe/cli@v7.1.0+incompatible/integration/v7/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.NewIsolationSegmentName() 16 }) 17 18 Describe("help", func() { 19 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 When("the environment is not setup correctly", func() { 34 It("fails with the appropriate errors", func() { 35 helpers.CheckEnvironmentTargetedCorrectly(false, false, ReadOnlyOrg, "delete-isolation-segment", "isolation-segment-name") 36 }) 37 }) 38 39 When("the environment is set up correctly", func() { 40 BeforeEach(func() { 41 helpers.LoginCF() 42 }) 43 44 When("the isolation segment exists", func() { 45 BeforeEach(func() { 46 Eventually(helpers.CF("create-isolation-segment", isolationSegmentName)).Should(Exit(0)) 47 }) 48 49 When("passed the force flag", func() { 50 It("deletes the isolation segment", func() { 51 session := helpers.CF("delete-isolation-segment", "-f", isolationSegmentName) 52 userName, _ := helpers.GetCredentials() 53 Eventually(session).Should(Say("Deleting isolation segment %s as %s...", isolationSegmentName, userName)) 54 Eventually(session).Should(Say("OK")) 55 Eventually(session).Should(Exit(0)) 56 }) 57 }) 58 59 When("the force flag is not provided", func() { 60 var buffer *Buffer 61 62 BeforeEach(func() { 63 buffer = NewBuffer() 64 }) 65 66 When("'yes' is inputted", func() { 67 BeforeEach(func() { 68 _, err := buffer.Write([]byte("y\n")) 69 Expect(err).ToNot(HaveOccurred()) 70 }) 71 72 It("deletes the isolation segment", func() { 73 session := helpers.CFWithStdin(buffer, "delete-isolation-segment", isolationSegmentName) 74 Eventually(session).Should(Say(`Really delete the isolation segment %s\?`, isolationSegmentName)) 75 76 userName, _ := helpers.GetCredentials() 77 Eventually(session).Should(Say("Deleting isolation segment %s as %s...", isolationSegmentName, userName)) 78 Eventually(session).Should(Say("OK")) 79 Eventually(session).Should(Exit(0)) 80 }) 81 }) 82 83 When("'no' is inputted", func() { 84 BeforeEach(func() { 85 _, err := buffer.Write([]byte("n\n")) 86 Expect(err).ToNot(HaveOccurred()) 87 }) 88 89 It("cancels the deletion", func() { 90 session := helpers.CFWithStdin(buffer, "delete-isolation-segment", isolationSegmentName) 91 Eventually(session).Should(Say(`Really delete the isolation segment %s\?`, isolationSegmentName)) 92 Eventually(session).Should(Say("Delete cancelled")) 93 Eventually(session).Should(Exit(0)) 94 }) 95 }) 96 97 When("using the default value", func() { 98 BeforeEach(func() { 99 _, err := buffer.Write([]byte("\n")) 100 Expect(err).ToNot(HaveOccurred()) 101 }) 102 103 It("cancels the deletion", func() { 104 session := helpers.CFWithStdin(buffer, "delete-isolation-segment", isolationSegmentName) 105 Eventually(session).Should(Say(`Really delete the isolation segment %s\?`, isolationSegmentName)) 106 Eventually(session).Should(Say("Delete cancelled")) 107 Eventually(session).Should(Exit(0)) 108 }) 109 }) 110 }) 111 }) 112 113 When("the isolation segment does not exist", func() { 114 It("returns an ok and warning", func() { 115 session := helpers.CF("delete-isolation-segment", "-f", isolationSegmentName) 116 Eventually(session.Err).Should(Say("Isolation segment %s does not exist.", isolationSegmentName)) 117 Eventually(session).Should(Say("OK")) 118 Eventually(session).Should(Exit(0)) 119 }) 120 }) 121 }) 122 })