github.com/arunkumar7540/cli@v6.45.0+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  
    79  		When("the app exists", func() {
    80  			BeforeEach(func() {
    81  				helpers.WithProcfileApp(func(appDir string) {
    82  					Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "push", appName)).Should(Exit(0))
    83  				})
    84  			})
    85  
    86  			It("displays the health check types for each process", func() {
    87  				session := helpers.CF("get-health-check", appName)
    88  
    89  				Eventually(session).Should(Say(`Getting health check type for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, username))
    90  				Eventually(session).Should(Say(`process\s+health check\s+endpoint \(for http\)\s+invocation timeout\n`))
    91  				Eventually(session).Should(Say(`web\s+port\s+1\n`))
    92  				Eventually(session).Should(Say(`console\s+process\s+1\n`))
    93  
    94  				Eventually(session).Should(Exit(0))
    95  			})
    96  
    97  			When("the health check type is http", func() {
    98  				BeforeEach(func() {
    99  					Eventually(helpers.CF("set-health-check", appName, "http")).Should(Exit(0))
   100  				})
   101  
   102  				It("shows the health check type is http with an endpoint of `/`", func() {
   103  					session := helpers.CF("get-health-check", appName)
   104  
   105  					Eventually(session).Should(Say(`Getting health check type for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, username))
   106  					Eventually(session).Should(Say(`process\s+health check\s+endpoint \(for http\)\s+invocation timeout\n`))
   107  					Eventually(session).Should(Say(`web\s+http\s+/\s+1\n`))
   108  					Eventually(session).Should(Say(`console\s+process\s+1\n`))
   109  
   110  					Eventually(session).Should(Exit(0))
   111  				})
   112  			})
   113  
   114  			When("the health check type is http with a custom endpoint", func() {
   115  				BeforeEach(func() {
   116  					Eventually(helpers.CF("set-health-check", appName, "http", "--endpoint", "/some-endpoint")).Should(Exit(0))
   117  				})
   118  
   119  				It("shows the health check type is http with the custom endpoint", func() {
   120  					session := helpers.CF("get-health-check", appName)
   121  
   122  					Eventually(session).Should(Say(`Getting health check type for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, username))
   123  					Eventually(session).Should(Say(`process\s+health check\s+endpoint \(for http\)\s+invocation timeout\n`))
   124  					Eventually(session).Should(Say(`web\s+http\s+/some-endpoint\s+1\n`))
   125  					Eventually(session).Should(Say(`console\s+process\s+1\n`))
   126  
   127  					Eventually(session).Should(Exit(0))
   128  				})
   129  			})
   130  
   131  			When("the health check type is port", func() {
   132  				BeforeEach(func() {
   133  					Eventually(helpers.CF("set-health-check", appName, "port")).Should(Exit(0))
   134  				})
   135  
   136  				It("shows that the health check type is port", func() {
   137  					session := helpers.CF("get-health-check", appName)
   138  
   139  					Eventually(session).Should(Say(`Getting health check type for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, username))
   140  					Eventually(session).Should(Say(`web\s+port\s+\d+`))
   141  
   142  					Eventually(session).Should(Exit(0))
   143  				})
   144  			})
   145  
   146  			When("the health check type is process", func() {
   147  				BeforeEach(func() {
   148  					Eventually(helpers.CF("set-health-check", appName, "process")).Should(Exit(0))
   149  				})
   150  
   151  				It("shows that the health check type is process", func() {
   152  					session := helpers.CF("get-health-check", appName)
   153  
   154  					Eventually(session).Should(Say(`Getting health check type for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, username))
   155  					Eventually(session).Should(Say(`web\s+process\s+\d+`))
   156  
   157  					Eventually(session).Should(Exit(0))
   158  				})
   159  			})
   160  
   161  			When("the health check type changes from http to another type", func() {
   162  				BeforeEach(func() {
   163  					Eventually(helpers.CF("set-health-check", appName, "http", "--endpoint", "/some-endpoint")).Should(Exit(0))
   164  					Eventually(helpers.CF("set-health-check", appName, "process")).Should(Exit(0))
   165  				})
   166  
   167  				It("does not show an endpoint", func() {
   168  					session := helpers.CF("get-health-check", appName)
   169  
   170  					Consistently(session).ShouldNot(Say("/some-endpoint"))
   171  					Eventually(session).Should(Say(`Getting health check type for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, username))
   172  					Eventually(session).Should(Say("\n\n"))
   173  					Eventually(session).Should(Say(`web\s+process\s+\d+`))
   174  					Eventually(session).Should(Say(`console\s+process\s+\d+`))
   175  
   176  					Eventually(session).Should(Exit(0))
   177  				})
   178  			})
   179  		})
   180  
   181  		When("the app does not exist", func() {
   182  			It("displays app not found and exits 1", func() {
   183  				session := helpers.CF("get-health-check", appName)
   184  
   185  				Eventually(session).Should(Say(`Getting health check type for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, username))
   186  				Eventually(session.Err).Should(Say("App '%s' not found", appName))
   187  				Eventually(session).Should(Say("FAILED"))
   188  
   189  				Eventually(session).Should(Exit(1))
   190  			})
   191  		})
   192  	})
   193  })