github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/integration/experimental/v3_set_health_check_command_test.go (about)

     1  package experimental
     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  	. "github.com/onsi/gomega/ghttp"
    10  )
    11  
    12  var _ = Describe("v3-set-health-check command", func() {
    13  	var (
    14  		orgName   string
    15  		spaceName string
    16  		appName   string
    17  	)
    18  
    19  	BeforeEach(func() {
    20  		orgName = helpers.NewOrgName()
    21  		spaceName = helpers.NewSpaceName()
    22  		appName = helpers.PrefixedRandomName("app")
    23  	})
    24  
    25  	Describe("help", func() {
    26  		Context("when --help flag is set", func() {
    27  			It("Displays command usage to output", func() {
    28  				session := helpers.CF("v3-set-health-check", "--help")
    29  
    30  				Eventually(session).Should(Say("NAME:"))
    31  				Eventually(session).Should(Say("v3-set-health-check - Change type of health check performed on an app's process"))
    32  				Eventually(session).Should(Say("USAGE:"))
    33  				Eventually(session).Should(Say(`cf v3-set-health-check APP_NAME \(process \| port \| http \[--endpoint PATH\]\) \[--process PROCESS\]`))
    34  
    35  				Eventually(session).Should(Say("EXAMPLES:"))
    36  				Eventually(session).Should(Say("cf v3-set-health-check worker-app process --process worker"))
    37  				Eventually(session).Should(Say("cf v3-set-health-check my-web-app http --endpoint /foo"))
    38  
    39  				Eventually(session).Should(Say("OPTIONS:"))
    40  				Eventually(session).Should(Say(`--endpoint\s+Path on the app \(Default: /\)`))
    41  				Eventually(session).Should(Say(`--process\s+App process to update \(Default: web\)`))
    42  
    43  				Eventually(session).Should(Exit(0))
    44  			})
    45  		})
    46  	})
    47  
    48  	Context("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("v3-set-health-check")
    51  
    52  			Eventually(session.Err).Should(Say("Incorrect Usage: the required arguments `APP_NAME` and `HEALTH_CHECK_TYPE` were not provided"))
    53  			Eventually(session).Should(Say("NAME:"))
    54  			Eventually(session).Should(Exit(1))
    55  		})
    56  	})
    57  
    58  	Context("when the health check type is not provided", func() {
    59  		It("tells the user that health check type is required, prints help text, and exits 1", func() {
    60  			session := helpers.CF("v3-set-health-check", appName)
    61  
    62  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `HEALTH_CHECK_TYPE` was not provided"))
    63  			Eventually(session).Should(Say("NAME:"))
    64  			Eventually(session).Should(Exit(1))
    65  		})
    66  	})
    67  
    68  	It("displays the experimental warning", func() {
    69  		session := helpers.CF("v3-set-health-check", appName, "port")
    70  		Eventually(session).Should(Say("This command is in EXPERIMENTAL stage and may change without notice"))
    71  		Eventually(session).Should(Exit())
    72  	})
    73  
    74  	Context("when the environment is not setup correctly", func() {
    75  		Context("when no API endpoint is set", func() {
    76  			BeforeEach(func() {
    77  				helpers.UnsetAPI()
    78  			})
    79  
    80  			It("fails with no API endpoint set message", func() {
    81  				session := helpers.CF("v3-set-health-check", appName, "port")
    82  				Eventually(session).Should(Say("FAILED"))
    83  				Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\."))
    84  				Eventually(session).Should(Exit(1))
    85  			})
    86  		})
    87  
    88  		Context("when the v3 api does not exist", func() {
    89  			var server *Server
    90  
    91  			BeforeEach(func() {
    92  				server = helpers.StartAndTargetServerWithoutV3API()
    93  			})
    94  
    95  			AfterEach(func() {
    96  				server.Close()
    97  			})
    98  
    99  			It("fails with error message that the minimum version is not met", func() {
   100  				session := helpers.CF("v3-set-health-check", appName, "port")
   101  				Eventually(session).Should(Say("FAILED"))
   102  				Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\."))
   103  				Eventually(session).Should(Exit(1))
   104  			})
   105  		})
   106  
   107  		Context("when the v3 api version is lower than the minimum version", func() {
   108  			var server *Server
   109  
   110  			BeforeEach(func() {
   111  				server = helpers.StartAndTargetServerWithV3Version("3.0.0")
   112  			})
   113  
   114  			AfterEach(func() {
   115  				server.Close()
   116  			})
   117  
   118  			It("fails with error message that the minimum version is not met", func() {
   119  				session := helpers.CF("v3-set-health-check", appName, "port")
   120  				Eventually(session).Should(Say("FAILED"))
   121  				Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\."))
   122  				Eventually(session).Should(Exit(1))
   123  			})
   124  		})
   125  
   126  		Context("when not logged in", func() {
   127  			BeforeEach(func() {
   128  				helpers.LogoutCF()
   129  			})
   130  
   131  			It("fails with not logged in message", func() {
   132  				session := helpers.CF("v3-set-health-check", appName, "port")
   133  				Eventually(session).Should(Say("FAILED"))
   134  				Eventually(session.Err).Should(Say("Not logged in\\. Use 'cf login' to log in\\."))
   135  				Eventually(session).Should(Exit(1))
   136  			})
   137  		})
   138  
   139  		Context("when there is no org set", func() {
   140  			BeforeEach(func() {
   141  				helpers.LogoutCF()
   142  				helpers.LoginCF()
   143  			})
   144  
   145  			It("fails with no org targeted error message", func() {
   146  				session := helpers.CF("v3-set-health-check", appName, "port")
   147  				Eventually(session).Should(Say("FAILED"))
   148  				Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org\\."))
   149  				Eventually(session).Should(Exit(1))
   150  			})
   151  		})
   152  
   153  		Context("when there is no space set", func() {
   154  			BeforeEach(func() {
   155  				helpers.LogoutCF()
   156  				helpers.LoginCF()
   157  				helpers.TargetOrg(ReadOnlyOrg)
   158  			})
   159  
   160  			It("fails with no space targeted error message", func() {
   161  				session := helpers.CF("v3-set-health-check", appName, "port")
   162  				Eventually(session).Should(Say("FAILED"))
   163  				Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space\\."))
   164  				Eventually(session).Should(Exit(1))
   165  			})
   166  		})
   167  	})
   168  
   169  	Context("when the environment is set up correctly", func() {
   170  		var userName string
   171  
   172  		BeforeEach(func() {
   173  			setupCF(orgName, spaceName)
   174  			userName, _ = helpers.GetCredentials()
   175  		})
   176  
   177  		AfterEach(func() {
   178  			helpers.QuickDeleteOrg(orgName)
   179  		})
   180  
   181  		Context("when the app exists", func() {
   182  			BeforeEach(func() {
   183  				helpers.WithProcfileApp(func(appDir string) {
   184  					Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName)).Should(Exit(0))
   185  				})
   186  			})
   187  
   188  			It("displays the health check types for each process", func() {
   189  				session := helpers.CF("v3-set-health-check", appName, "http", "--endpoint", "/healthcheck", "--process", "console")
   190  				Eventually(session).Should(Say("Updating health check type for app %s process console in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName))
   191  				Eventually(session).Should(Say("TIP: An app restart is required for the change to take effect\\."))
   192  				Eventually(session).Should(Exit(0))
   193  
   194  				session = helpers.CF("v3-get-health-check", appName)
   195  				Eventually(session).Should(Say("Getting process health check types for app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName))
   196  				Eventually(session).Should(Say(`process\s+health check\s+endpoint \(for http\)\n`))
   197  				Eventually(session).Should(Say(`web\s+port\s+\n`))
   198  				Eventually(session).Should(Say(`console\s+http\s+/healthcheck`))
   199  
   200  				Eventually(session).Should(Exit(0))
   201  			})
   202  
   203  			Context("when the process type does not exist", func() {
   204  				BeforeEach(func() {
   205  					helpers.WithProcfileApp(func(appDir string) {
   206  						Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName)).Should(Exit(0))
   207  					})
   208  				})
   209  
   210  				It("returns a process not found error", func() {
   211  					session := helpers.CF("v3-set-health-check", appName, "http", "--endpoint", "/healthcheck", "--process", "nonexistant-type")
   212  					Eventually(session).Should(Say("Updating health check type for app %s process nonexistant-type in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName))
   213  					Eventually(session.Err).Should(Say("Process nonexistant-type not found"))
   214  					Eventually(session).Should(Say("FAILED"))
   215  					Eventually(session).Should(Exit(1))
   216  				})
   217  			})
   218  		})
   219  
   220  		Context("when the app does not exist", func() {
   221  			It("displays app not found and exits 1", func() {
   222  				invalidAppName := "invalid-app-name"
   223  				session := helpers.CF("v3-set-health-check", invalidAppName, "port")
   224  
   225  				Eventually(session).Should(Say("Updating health check type for app %s process web in org %s / space %s as %s\\.\\.\\.", invalidAppName, orgName, spaceName, userName))
   226  				Eventually(session.Err).Should(Say("App %s not found", invalidAppName))
   227  				Eventually(session).Should(Say("FAILED"))
   228  
   229  				Eventually(session).Should(Exit(1))
   230  			})
   231  		})
   232  	})
   233  })