github.com/wanddynosios/cli@v7.1.0+incompatible/integration/v6/isolated/set_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/ginkgo/extensions/table"
     7  	. "github.com/onsi/gomega"
     8  	. "github.com/onsi/gomega/gbytes"
     9  	. "github.com/onsi/gomega/gexec"
    10  )
    11  
    12  var _ = Describe("set-health-check command", func() {
    13  	Describe("help", func() {
    14  		When("--help flag is set", func() {
    15  			It("Displays command usage to output", func() {
    16  				session := helpers.CF("set-health-check", "--help")
    17  				Eventually(session).Should(Say("NAME:"))
    18  				Eventually(session).Should(Say("set-health-check - Change type of health check performed on an app"))
    19  				Eventually(session).Should(Say("USAGE:"))
    20  				Eventually(session).Should(Say("cf set-health-check APP_NAME \\(process \\| port \\| http \\[--endpoint PATH\\]\\)"))
    21  				Eventually(session).Should(Say("TIP: 'none' has been deprecated but is accepted for 'process'."))
    22  				Eventually(session).Should(Say("EXAMPLES:"))
    23  				Eventually(session).Should(Say("   cf set-health-check worker-app process"))
    24  				Eventually(session).Should(Say("   cf set-health-check my-web-app http --endpoint /foo"))
    25  				Eventually(session).Should(Say("OPTIONS:"))
    26  				Eventually(session).Should(Say("   --endpoint      Path on the app \\(Default: /\\)"))
    27  				Eventually(session).Should(Exit(0))
    28  			})
    29  		})
    30  	})
    31  
    32  	When("the environment is not setup correctly", func() {
    33  		It("fails with the appropriate errors", func() {
    34  			helpers.CheckEnvironmentTargetedCorrectly(true, true, ReadOnlyOrg, "set-health-check", "app-name", "port")
    35  		})
    36  	})
    37  
    38  	When("the input is invalid", func() {
    39  		DescribeTable("fails with incorrect usage method",
    40  			func(args ...string) {
    41  				cmd := append([]string{"set-health-check"}, args...)
    42  				session := helpers.CF(cmd...)
    43  				Eventually(session.Err).Should(Say("Incorrect Usage:"))
    44  				Eventually(session).Should(Say("NAME:"))
    45  				Eventually(session).Should(Exit(1))
    46  			},
    47  			Entry("when app-name and health-check-type are not passed in"),
    48  			Entry("when health-check-type is not passed in", "some-app"),
    49  			Entry("when health-check-type is invalid", "some-app", "wut"),
    50  		)
    51  	})
    52  
    53  	When("the environment is set up correctly", func() {
    54  		var (
    55  			orgName   string
    56  			spaceName string
    57  		)
    58  
    59  		BeforeEach(func() {
    60  			orgName = helpers.NewOrgName()
    61  			spaceName = helpers.NewSpaceName()
    62  
    63  			helpers.SetupCF(orgName, spaceName)
    64  		})
    65  
    66  		AfterEach(func() {
    67  			helpers.QuickDeleteOrg(orgName)
    68  		})
    69  
    70  		When("the app does not exist", func() {
    71  			It("tells the user that the app is not found and exits 1", func() {
    72  				appName := helpers.PrefixedRandomName("app")
    73  				session := helpers.CF("set-health-check", appName, "port")
    74  
    75  				Eventually(session).Should(Say("FAILED"))
    76  				Eventually(session.Err).Should(Say("App '%s' not found", appName))
    77  				Eventually(session).Should(Exit(1))
    78  			})
    79  		})
    80  
    81  		When("the app exists", func() {
    82  			var appName string
    83  
    84  			BeforeEach(func() {
    85  				appName = helpers.PrefixedRandomName("app")
    86  				helpers.WithHelloWorldApp(func(appDir string) {
    87  					Eventually(helpers.CF("push", appName, "-p", appDir, "-b", "staticfile_buildpack", "--no-start")).Should(Exit(0))
    88  				})
    89  			})
    90  
    91  			DescribeTable("Updates health-check-type and exits 0",
    92  				func(settingType string) {
    93  					session := helpers.CF("set-health-check", appName, settingType)
    94  
    95  					username, _ := helpers.GetCredentials()
    96  					Eventually(session).Should(Say("Updating health check type for app %s in org %s / space %s as %s", appName, orgName, spaceName, username))
    97  					Eventually(session).Should(Say("OK"))
    98  					Eventually(session).Should(Exit(0))
    99  
   100  					getSession := helpers.CF("get-health-check", appName)
   101  					Eventually(getSession).Should(Say("health check type:\\s+%s", settingType))
   102  					Eventually(getSession).Should(Exit(0))
   103  				},
   104  				Entry("when setting the health-check-type to 'none'", "none"),
   105  				Entry("when setting the health-check-type to 'process'", "process"),
   106  				Entry("when setting the health-check-type to 'port'", "port"),
   107  				Entry("when setting the health-check-type to 'http'", "http"),
   108  			)
   109  
   110  			When("no http health check endpoint is given", func() {
   111  				BeforeEach(func() {
   112  					Eventually(helpers.CF("set-health-check", appName, "http")).Should(Exit(0))
   113  				})
   114  
   115  				It("sets the http health check endpoint to /", func() {
   116  					session := helpers.CF("get-health-check", appName)
   117  					Eventually(session).Should(Say("endpoint \\(for http type\\):\\s+/"))
   118  					Eventually(session).Should(Exit(0))
   119  				})
   120  			})
   121  
   122  			When("a valid http health check endpoint is given", func() {
   123  				BeforeEach(func() {
   124  					Eventually(helpers.CF("set-health-check", appName, "http", "--endpoint", "/foo")).Should(Exit(0))
   125  				})
   126  
   127  				It("sets the http health check endpoint to the given endpoint", func() {
   128  					session := helpers.CF("get-health-check", appName)
   129  					Eventually(session).Should(Say("endpoint \\(for http type\\):\\s+/foo"))
   130  					Eventually(session).Should(Exit(0))
   131  				})
   132  			})
   133  
   134  			When("an invalid http health check endpoint is given", func() {
   135  				It("outputs an error and exits 1", func() {
   136  					session := helpers.CF("set-health-check", appName, "http", "--endpoint", "invalid")
   137  					Eventually(session.Err).Should(Say("The app is invalid: health_check_http_endpoint HTTP health check endpoint is not a valid URI path: invalid"))
   138  					Eventually(session).Should(Exit(1))
   139  				})
   140  			})
   141  
   142  			When("an endpoint is given with a non-http health check type", func() {
   143  				It("outputs an error and exits 1", func() {
   144  					session := helpers.CF("set-health-check", appName, "port", "--endpoint", "/foo")
   145  					Eventually(session.Err).Should(Say("Health check type must be 'http' to set a health check HTTP endpoint\\."))
   146  					Eventually(session).Should(Exit(1))
   147  				})
   148  			})
   149  
   150  			When("the app is started", func() {
   151  				BeforeEach(func() {
   152  					appName = helpers.PrefixedRandomName("app")
   153  					helpers.WithHelloWorldApp(func(appDir string) {
   154  						Eventually(helpers.CF("push", appName, "-p", appDir, "-b", "staticfile_buildpack")).Should(Exit(0))
   155  					})
   156  				})
   157  
   158  				It("displays tip to restart the app", func() {
   159  					session := helpers.CF("set-health-check", appName, "port")
   160  					Eventually(session).Should(Say("TIP: An app restart is required for the change to take effect\\."))
   161  					Eventually(session).Should(Exit(0))
   162  				})
   163  			})
   164  		})
   165  	})
   166  })