github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/integration/v7/isolated/get_health_check_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("get-health-check command", func() {
    12  	var (
    13  		orgName   string
    14  		spaceName string
    15  		appName   string
    16  	)
    17  
    18  	BeforeEach(func() {
    19  		orgName = helpers.NewOrgName()
    20  		spaceName = helpers.NewSpaceName()
    21  		appName = helpers.PrefixedRandomName("app")
    22  	})
    23  
    24  	Describe("help", func() {
    25  		When("--help flag is set", func() {
    26  			It("Displays command usage to output", func() {
    27  				session := helpers.CF("get-health-check", "--help")
    28  
    29  				Eventually(session).Should(Say("NAME:"))
    30  				Eventually(session).Should(Say("get-health-check - Show the type of health check performed on an app"))
    31  				Eventually(session).Should(Say("USAGE:"))
    32  				Eventually(session).Should(Say("cf get-health-check APP_NAME"))
    33  
    34  				Eventually(session).Should(Exit(0))
    35  			})
    36  		})
    37  	})
    38  
    39  	When("the app name is not provided", func() {
    40  		It("tells the user that the app name is required, prints help text, and exits 1", func() {
    41  			session := helpers.CF("get-health-check")
    42  
    43  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided"))
    44  			Eventually(session).Should(Say("NAME:"))
    45  			Eventually(session).Should(Exit(1))
    46  		})
    47  	})
    48  
    49  	When("the environment is not setup correctly", func() {
    50  		It("fails with the appropriate errors", func() {
    51  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "get-health-check", appName)
    52  		})
    53  	})
    54  
    55  	When("the environment is set up correctly", func() {
    56  		var username string
    57  
    58  		BeforeEach(func() {
    59  			helpers.SetupCF(orgName, spaceName)
    60  			username, _ = helpers.GetCredentials()
    61  		})
    62  
    63  		AfterEach(func() {
    64  			helpers.QuickDeleteOrg(orgName)
    65  		})
    66  
    67  		When("the input is invalid", func() {
    68  			When("there are not enough arguments", func() {
    69  				It("outputs the usage and exits 1", func() {
    70  					session := helpers.CF("get-health-check")
    71  
    72  					Eventually(session.Err).Should(Say("Incorrect Usage:"))
    73  					Eventually(session).Should(Say("NAME:"))
    74  					Eventually(session).Should(Exit(1))
    75  				})
    76  			})
    77  
    78  			When("there too many arguments", func() {
    79  				It("ignores the extra arguments", func() {
    80  					session := helpers.CF("get-health-check", appName, "extra")
    81  
    82  					Eventually(session).Should(Say(`Getting health check type for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, username))
    83  					Eventually(session.Err).Should(Say("App %s not found", appName))
    84  					Eventually(session).Should(Say("FAILED"))
    85  					Eventually(session).Should(Exit(1))
    86  				})
    87  			})
    88  		})
    89  
    90  		When("the app exists", func() {
    91  			BeforeEach(func() {
    92  				helpers.WithProcfileApp(func(appDir string) {
    93  					Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "push", appName)).Should(Exit(0))
    94  				})
    95  			})
    96  
    97  			It("displays the health check types for each process", func() {
    98  				session := helpers.CF("get-health-check", appName)
    99  
   100  				Eventually(session).Should(Say(`Getting health check type for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, username))
   101  				Eventually(session).Should(Say(`process\s+health check\s+endpoint \(for http\)\s+invocation timeout\n`))
   102  				Eventually(session).Should(Say(`web\s+port\s+1\n`))
   103  				Eventually(session).Should(Say(`console\s+process\s+1\n`))
   104  
   105  				Eventually(session).Should(Exit(0))
   106  			})
   107  
   108  			When("the health check type is http", func() {
   109  				BeforeEach(func() {
   110  					Eventually(helpers.CF("set-health-check", appName, "http")).Should(Exit(0))
   111  				})
   112  
   113  				It("shows the health check type is http with an endpoint of `/`", func() {
   114  					session := helpers.CF("get-health-check", appName)
   115  
   116  					Eventually(session).Should(Say(`Getting health check type for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, username))
   117  					Eventually(session).Should(Say(`process\s+health check\s+endpoint \(for http\)\s+invocation timeout\n`))
   118  					Eventually(session).Should(Say(`web\s+http\s+/\s+1\n`))
   119  					Eventually(session).Should(Say(`console\s+process\s+1\n`))
   120  
   121  					Eventually(session).Should(Exit(0))
   122  				})
   123  			})
   124  
   125  			When("the health check type is http with a custom endpoint", func() {
   126  				BeforeEach(func() {
   127  					Eventually(helpers.CF("set-health-check", appName, "http", "--endpoint", "/some-endpoint")).Should(Exit(0))
   128  				})
   129  
   130  				It("shows the health check type is http with the custom endpoint", func() {
   131  					session := helpers.CF("get-health-check", appName)
   132  
   133  					Eventually(session).Should(Say(`Getting health check type for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, username))
   134  					Eventually(session).Should(Say(`process\s+health check\s+endpoint \(for http\)\s+invocation timeout\n`))
   135  					Eventually(session).Should(Say(`web\s+http\s+/some-endpoint\s+1\n`))
   136  					Eventually(session).Should(Say(`console\s+process\s+1\n`))
   137  
   138  					Eventually(session).Should(Exit(0))
   139  				})
   140  			})
   141  
   142  			When("the health check type is port", func() {
   143  				BeforeEach(func() {
   144  					Eventually(helpers.CF("set-health-check", appName, "port")).Should(Exit(0))
   145  				})
   146  
   147  				It("shows that the health check type is port", func() {
   148  					session := helpers.CF("get-health-check", appName)
   149  
   150  					Eventually(session).Should(Say(`Getting health check type for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, username))
   151  					Eventually(session).Should(Say(`web\s+port\s+\d+`))
   152  
   153  					Eventually(session).Should(Exit(0))
   154  				})
   155  			})
   156  
   157  			When("the health check type is process", func() {
   158  				BeforeEach(func() {
   159  					Eventually(helpers.CF("set-health-check", appName, "process")).Should(Exit(0))
   160  				})
   161  
   162  				It("shows that the health check type is process", func() {
   163  					session := helpers.CF("get-health-check", appName)
   164  
   165  					Eventually(session).Should(Say(`Getting health check type for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, username))
   166  					Eventually(session).Should(Say(`web\s+process\s+\d+`))
   167  
   168  					Eventually(session).Should(Exit(0))
   169  				})
   170  			})
   171  
   172  			When("the health check type changes from http to another type", func() {
   173  				BeforeEach(func() {
   174  					Eventually(helpers.CF("set-health-check", appName, "http", "--endpoint", "/some-endpoint")).Should(Exit(0))
   175  					Eventually(helpers.CF("set-health-check", appName, "process")).Should(Exit(0))
   176  				})
   177  
   178  				It("does not show an endpoint", func() {
   179  					session := helpers.CF("get-health-check", appName)
   180  
   181  					Consistently(session).ShouldNot(Say("/some-endpoint"))
   182  					Eventually(session).Should(Say(`Getting health check type for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, username))
   183  					Eventually(session).Should(Say("\n\n"))
   184  					Eventually(session).Should(Say(`web\s+process\s+\d+`))
   185  					Eventually(session).Should(Say(`console\s+process\s+\d+`))
   186  
   187  					Eventually(session).Should(Exit(0))
   188  				})
   189  			})
   190  		})
   191  
   192  		When("the app does not exist", func() {
   193  			It("displays app not found and exits 1", func() {
   194  				session := helpers.CF("get-health-check", appName)
   195  
   196  				Eventually(session).Should(Say(`Getting health check type for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, username))
   197  				Eventually(session.Err).Should(Say("App %s not found", appName))
   198  				Eventually(session).Should(Say("FAILED"))
   199  
   200  				Eventually(session).Should(Exit(1))
   201  			})
   202  		})
   203  	})
   204  })