github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v6/isolated/disallow_ssh_command_test.go (about) 1 package isolated 2 3 import ( 4 . "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers" 5 6 "code.cloudfoundry.org/cli/integration/helpers" 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 . "github.com/onsi/gomega/gbytes" 10 . "github.com/onsi/gomega/gexec" 11 ) 12 13 var _ = Describe("disallow-space-ssh command", func() { 14 var ( 15 orgName string 16 spaceName string 17 ) 18 19 BeforeEach(func() { 20 orgName = helpers.NewOrgName() 21 spaceName = helpers.NewSpaceName() 22 }) 23 24 Describe("help", func() { 25 When("--help flag is set", func() { 26 It("appears in cf help -a", func() { 27 session := helpers.CF("help", "-a") 28 Eventually(session).Should(Exit(0)) 29 Expect(session).To(HaveCommandInCategoryWithDescription("disallow-space-ssh", "SPACES", "Disallow SSH access for the space")) 30 }) 31 32 It("displays command usage to output", func() { 33 session := helpers.CF("disallow-space-ssh", "--help") 34 35 Eventually(session).Should(Say("NAME:")) 36 Eventually(session).Should(Say("disallow-space-ssh - Disallow SSH access for the space")) 37 Eventually(session).Should(Say("USAGE:")) 38 Eventually(session).Should(Say("cf disallow-space-ssh SPACE")) 39 Eventually(session).Should(Say("SEE ALSO:")) 40 Eventually(session).Should(Say("disable-ssh, space-ssh-allowed, ssh, ssh-enabled")) 41 Eventually(session).Should(Exit(0)) 42 }) 43 }) 44 }) 45 46 When("the environment is set up correctly", func() { 47 BeforeEach(func() { 48 helpers.SetupCF(orgName, spaceName) 49 }) 50 AfterEach(func() { 51 helpers.QuickDeleteOrg(orgName) 52 }) 53 54 When("the space name is not provided", func() { 55 It("tells the user that the space name is required, prints help text, and exits 1", func() { 56 session := helpers.CF("disallow-space-ssh") 57 58 Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `SPACE` was not provided")) 59 Eventually(session).Should(Say("NAME:")) 60 Eventually(session).Should(Exit(1)) 61 }) 62 }) 63 64 When("the space does not exist", func() { 65 It("displays space not found and exits 1", func() { 66 invalidSpaceName := "invalid-space-name" 67 session := helpers.CF("disallow-space-ssh", invalidSpaceName) 68 69 Eventually(session).Should(Say("FAILED")) 70 Eventually(session).Should(Say("Space %s not found", invalidSpaceName)) 71 Eventually(session).Should(Exit(1)) 72 }) 73 }) 74 75 When("when ssh has not been disallowed yet", func() { 76 It("disallows ssh for the space", func() { 77 session := helpers.CF("disallow-space-ssh", spaceName) 78 79 Eventually(session).Should(Say(`Disabling ssh support for space '%s'\.\.\.`, spaceName)) 80 81 Eventually(session).Should(Say("OK")) 82 Eventually(session).Should(Exit(0)) 83 84 session = helpers.CF("space-ssh-allowed", spaceName) 85 Eventually(session).Should(Say("ssh support is disabled in space '%s'", spaceName)) 86 Eventually(session).Should(Exit(0)) 87 }) 88 }) 89 90 When("ssh was previously disallowed for the space", func() { 91 BeforeEach(func() { 92 Eventually(helpers.CF("disallow-space-ssh", spaceName)).Should(Exit(0)) 93 }) 94 95 It("informs the user and exits 0", func() { 96 session := helpers.CF("disallow-space-ssh", spaceName) 97 98 Eventually(session).Should(Say("ssh support is already disabled in space '%s'", spaceName)) 99 100 session = helpers.CF("space-ssh-allowed", spaceName) 101 Eventually(session).Should(Say("ssh support is disabled in space '%s'", spaceName)) 102 Eventually(session).Should(Exit(0)) 103 }) 104 }) 105 }) 106 })