github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/ssh_enabled_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("ssh-enabled command", func() {
    14  	var (
    15  		orgName   string
    16  		spaceName string
    17  		appName   string
    18  	)
    19  
    20  	BeforeEach(func() {
    21  		orgName = helpers.NewOrgName()
    22  		spaceName = helpers.NewSpaceName()
    23  		appName = helpers.PrefixedRandomName("app")
    24  	})
    25  
    26  	Describe("help", func() {
    27  		When("--help flag is set", func() {
    28  			It("appears in cf help -a", func() {
    29  				session := helpers.CF("help", "-a")
    30  				Eventually(session).Should(Exit(0))
    31  				Expect(session).To(HaveCommandInCategoryWithDescription("ssh-enabled", "APPS", "Reports whether SSH is enabled on an application container instance"))
    32  			})
    33  
    34  			It("displays command usage to output", func() {
    35  				session := helpers.CF("ssh-enabled", "--help")
    36  
    37  				Eventually(session).Should(Say("NAME:"))
    38  				Eventually(session).Should(Say("ssh-enabled - Reports whether SSH is enabled on an application container instance"))
    39  				Eventually(session).Should(Say("USAGE:"))
    40  				Eventually(session).Should(Say("cf ssh-enabled APP_NAME"))
    41  				Eventually(session).Should(Say("SEE ALSO:"))
    42  				Eventually(session).Should(Say("enable-ssh, space-ssh-allowed, ssh"))
    43  				Eventually(session).Should(Exit(0))
    44  			})
    45  		})
    46  	})
    47  
    48  	When("the app name is not provided", func() {
    49  		It("tells the user that the app name is required, prints help text, and exits 1", func() {
    50  			session := helpers.CF("ssh-enabled")
    51  
    52  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided"))
    53  			Eventually(session).Should(Say("NAME:"))
    54  			Eventually(session).Should(Exit(1))
    55  		})
    56  	})
    57  
    58  	When("the environment is not setup correctly", func() {
    59  		It("fails with the appropriate errors", func() {
    60  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "ssh-enabled", appName)
    61  		})
    62  	})
    63  
    64  	When("the environment is set up correctly", func() {
    65  		BeforeEach(func() {
    66  			helpers.SetupCF(orgName, spaceName)
    67  		})
    68  
    69  		AfterEach(func() {
    70  			helpers.QuickDeleteOrg(orgName)
    71  		})
    72  
    73  		When("the app does not exist", func() {
    74  			It("displays app not found and exits 1", func() {
    75  				invalidAppName := "invalid-app-name"
    76  				session := helpers.CF("ssh-enabled", invalidAppName)
    77  
    78  				Eventually(session.Err).Should(Say("App '%s' not found", invalidAppName))
    79  				Eventually(session).Should(Say("FAILED"))
    80  				Eventually(session).Should(Exit(1))
    81  			})
    82  		})
    83  
    84  		When("the app exists", func() {
    85  			BeforeEach(func() {
    86  				helpers.WithHelloWorldApp(func(appDir string) {
    87  					Eventually(helpers.CF("push", appName, "-p", appDir, "--no-start")).Should(Exit(0))
    88  				})
    89  			})
    90  
    91  			When("SSH is enabled", func() {
    92  				It("displays the appropriate output", func() {
    93  					session := helpers.CF("ssh-enabled", appName)
    94  
    95  					Eventually(session).Should(Say(`ssh support is enabled for app '%s'\.`, appName))
    96  					Eventually(session).Should(Exit(0))
    97  				})
    98  			})
    99  
   100  			When("SSH is disabled", func() {
   101  				BeforeEach(func() {
   102  					Eventually(helpers.CF("disable-ssh", appName)).Should(Exit(0))
   103  				})
   104  
   105  				It("displays the appropriate output", func() {
   106  					session := helpers.CF("ssh-enabled", appName)
   107  
   108  					Eventually(session).Should(Say(`ssh support is disabled for app '%s'\.`, appName))
   109  					Eventually(session).Should(Say("ssh is disabled for app"))
   110  					Eventually(session).Should(Exit(0))
   111  				})
   112  			})
   113  		})
   114  	})
   115  })