github.com/nimakaviani/cli@v6.37.1-0.20180619223813-e734901a73fa+incompatible/integration/isolated/set_health_check_command_test.go (about)

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