github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/v6/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  )
    10  
    11  var _ = Describe("v3-set-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("v3-set-health-check", "--help")
    28  
    29  				Eventually(session).Should(Say("NAME:"))
    30  				Eventually(session).Should(Say("v3-set-health-check - Change type of health check performed on an app's process"))
    31  				Eventually(session).Should(Say("USAGE:"))
    32  				Eventually(session).Should(Say(`cf v3-set-health-check APP_NAME \(process \| port \| http \[--endpoint PATH\]\) \[--process PROCESS\] \[--invocation-timeout INVOCATION_TIMEOUT\]`))
    33  
    34  				Eventually(session).Should(Say("EXAMPLES:"))
    35  				Eventually(session).Should(Say("cf v3-set-health-check worker-app process --process worker"))
    36  				Eventually(session).Should(Say("cf v3-set-health-check my-web-app http --endpoint /foo"))
    37  				Eventually(session).Should(Say("cf v3-set-health-check my-web-app http --invocation-timeout 10"))
    38  
    39  				Eventually(session).Should(Say("OPTIONS:"))
    40  				Eventually(session).Should(Say(`--endpoint\s+Path on the app \(Default: /\)`))
    41  				Eventually(session).Should(Say(`--invocation-timeout\s+Time \(in seconds\) that controls individual health check invocations`))
    42  				Eventually(session).Should(Say(`--process\s+App process to update \(Default: web\)`))
    43  
    44  				Eventually(session).Should(Exit(0))
    45  			})
    46  		})
    47  	})
    48  
    49  	When("the app name is not provided", func() {
    50  		It("tells the user that the app name is required, prints help text, and exits 1", func() {
    51  			session := helpers.CF("v3-set-health-check")
    52  
    53  			Eventually(session.Err).Should(Say("Incorrect Usage: the required arguments `APP_NAME` and `HEALTH_CHECK_TYPE` were not provided"))
    54  			Eventually(session).Should(Say("NAME:"))
    55  			Eventually(session).Should(Exit(1))
    56  		})
    57  	})
    58  
    59  	When("the health check type is not provided", func() {
    60  		It("tells the user that health check type is required, prints help text, and exits 1", func() {
    61  			session := helpers.CF("v3-set-health-check", appName)
    62  
    63  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `HEALTH_CHECK_TYPE` was not provided"))
    64  			Eventually(session).Should(Say("NAME:"))
    65  			Eventually(session).Should(Exit(1))
    66  		})
    67  	})
    68  
    69  	It("displays the experimental warning", func() {
    70  		session := helpers.CF("v3-set-health-check", appName, "port")
    71  		Eventually(session.Err).Should(Say("This command is in EXPERIMENTAL stage and may change without notice"))
    72  		Eventually(session).Should(Exit())
    73  	})
    74  
    75  	When("the environment is not setup correctly", func() {
    76  		When("no API endpoint is set", func() {
    77  			BeforeEach(func() {
    78  				helpers.UnsetAPI()
    79  			})
    80  
    81  			It("fails with no API endpoint set message", func() {
    82  				session := helpers.CF("v3-set-health-check", appName, "port")
    83  				Eventually(session).Should(Say("FAILED"))
    84  				Eventually(session.Err).Should(Say(`No API endpoint set\. Use 'cf login' or 'cf api' to target an endpoint\.`))
    85  				Eventually(session).Should(Exit(1))
    86  			})
    87  		})
    88  
    89  		When("not logged in", func() {
    90  			BeforeEach(func() {
    91  				helpers.LogoutCF()
    92  			})
    93  
    94  			It("fails with not logged in message", func() {
    95  				session := helpers.CF("v3-set-health-check", appName, "port")
    96  				Eventually(session).Should(Say("FAILED"))
    97  				Eventually(session.Err).Should(Say(`Not logged in\. Use 'cf login' or 'cf login --sso' to log in\.`))
    98  				Eventually(session).Should(Exit(1))
    99  			})
   100  		})
   101  
   102  		When("there is no org set", func() {
   103  			BeforeEach(func() {
   104  				helpers.LogoutCF()
   105  				helpers.LoginCF()
   106  			})
   107  
   108  			It("fails with no org targeted error message", func() {
   109  				session := helpers.CF("v3-set-health-check", appName, "port")
   110  				Eventually(session).Should(Say("FAILED"))
   111  				Eventually(session.Err).Should(Say(`No org targeted, use 'cf target -o ORG' to target an org\.`))
   112  				Eventually(session).Should(Exit(1))
   113  			})
   114  		})
   115  
   116  		When("there is no space set", func() {
   117  			BeforeEach(func() {
   118  				helpers.LogoutCF()
   119  				helpers.LoginCF()
   120  				helpers.TargetOrg(ReadOnlyOrg)
   121  			})
   122  
   123  			It("fails with no space targeted error message", func() {
   124  				session := helpers.CF("v3-set-health-check", appName, "port")
   125  				Eventually(session).Should(Say("FAILED"))
   126  				Eventually(session.Err).Should(Say(`No space targeted, use 'cf target -s SPACE' to target a space\.`))
   127  				Eventually(session).Should(Exit(1))
   128  			})
   129  		})
   130  	})
   131  
   132  	When("the environment is set up correctly", func() {
   133  		var userName string
   134  
   135  		BeforeEach(func() {
   136  			helpers.SetupCF(orgName, spaceName)
   137  			userName, _ = helpers.GetCredentials()
   138  		})
   139  
   140  		AfterEach(func() {
   141  			helpers.QuickDeleteOrg(orgName)
   142  		})
   143  
   144  		When("the app exists", func() {
   145  			BeforeEach(func() {
   146  				helpers.WithProcfileApp(func(appDir string) {
   147  					Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName)).Should(Exit(0))
   148  				})
   149  			})
   150  
   151  			When("the process type is set", func() {
   152  				It("displays the health check types for each process", func() {
   153  					session := helpers.CF("v3-set-health-check", appName, "http", "--endpoint", "/healthcheck", "--process", "console")
   154  					Eventually(session).Should(Say(`Updating health check type for app %s process console in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
   155  					Eventually(session).Should(Say(`TIP: An app restart is required for the change to take effect\.`))
   156  					Eventually(session).Should(Exit(0))
   157  
   158  					session = helpers.CF("v3-get-health-check", appName)
   159  					Eventually(session).Should(Say(`Getting process health check types for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
   160  					Eventually(session).Should(Say(`process\s+health check\s+endpoint \(for http\)\s+invocation timeout`))
   161  					Eventually(session).Should(Say(`web\s+port\s+1`))
   162  					Eventually(session).Should(Say(`console\s+http\s+/healthcheck\s+1`))
   163  
   164  					Eventually(session).Should(Exit(0))
   165  				})
   166  			})
   167  
   168  			When("the invocation timeout is set", func() {
   169  				It("displays the health check types for each process", func() {
   170  					session := helpers.CF("v3-set-health-check", appName, "http", "--endpoint", "/healthcheck", "--invocation-timeout", "2")
   171  					Eventually(session).Should(Say(`Updating health check type for app %s process web in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
   172  					Eventually(session).Should(Say(`TIP: An app restart is required for the change to take effect\.`))
   173  					Eventually(session).Should(Exit(0))
   174  
   175  					session = helpers.CF("v3-get-health-check", appName)
   176  					Eventually(session).Should(Say(`Getting process health check types for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
   177  					Eventually(session).Should(Say(`process\s+health check\s+endpoint \(for http\)\s+invocation timeout`))
   178  					Eventually(session).Should(Say(`web\s+http\s+/healthcheck\s+2`))
   179  
   180  					Eventually(session).Should(Exit(0))
   181  				})
   182  
   183  			})
   184  
   185  			When("process type and invocation timeout are not set", func() {
   186  				It("displays the health check types for each process", func() {
   187  					session := helpers.CF("v3-set-health-check", appName, "http", "--endpoint", "/healthcheck")
   188  					Eventually(session).Should(Say(`Updating health check type for app %s process web in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
   189  					Eventually(session).Should(Say(`TIP: An app restart is required for the change to take effect\.`))
   190  					Eventually(session).Should(Exit(0))
   191  
   192  					session = helpers.CF("v3-get-health-check", appName)
   193  					Eventually(session).Should(Say(`Getting process health check types for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
   194  					Eventually(session).Should(Say(`process\s+health check\s+endpoint \(for http\)\s+invocation timeout`))
   195  					Eventually(session).Should(Say(`web\s+http\s+/healthcheck\s+1`))
   196  					Eventually(session).Should(Say(`console\s+process\s+1`))
   197  
   198  					Eventually(session).Should(Exit(0))
   199  				})
   200  			})
   201  
   202  			When("the process type does not exist", func() {
   203  				BeforeEach(func() {
   204  					helpers.WithProcfileApp(func(appDir string) {
   205  						Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName)).Should(Exit(0))
   206  					})
   207  				})
   208  
   209  				It("returns a process not found error", func() {
   210  					session := helpers.CF("v3-set-health-check", appName, "http", "--endpoint", "/healthcheck", "--process", "nonexistent-type")
   211  					Eventually(session).Should(Say(`Updating health check type for app %s process nonexistent-type in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
   212  					Eventually(session.Err).Should(Say("Process nonexistent-type not found"))
   213  					Eventually(session).Should(Say("FAILED"))
   214  					Eventually(session).Should(Exit(1))
   215  				})
   216  			})
   217  
   218  			When("health check type is not 'http' and endpoint is set", func() {
   219  				It("returns an error", func() {
   220  					session := helpers.CF("v3-set-health-check", appName, "port", "--endpoint", "oh-no", "--process", "console")
   221  					Eventually(session.Out).Should(Say(`Updating health check type for app %s process console in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
   222  					Eventually(session.Err).Should(Say("Health check type must be 'http' to set a health check HTTP endpoint."))
   223  					Eventually(session.Out).Should(Say("FAILED"))
   224  					Eventually(session).Should(Exit(1))
   225  				})
   226  			})
   227  
   228  			When("the invocation timeout is less than one", func() {
   229  				It("returns an error", func() {
   230  					session := helpers.CF("v3-set-health-check", appName, "port", "--invocation-timeout", "0", "--process", "console")
   231  					Eventually(session.Err).Should(Say("Value must be greater than or equal to 1."))
   232  					Eventually(session).Should(Exit(1))
   233  				})
   234  			})
   235  		})
   236  
   237  		When("the app does not exist", func() {
   238  			It("displays app not found and exits 1", func() {
   239  				invalidAppName := "invalid-app-name"
   240  				session := helpers.CF("v3-set-health-check", invalidAppName, "port")
   241  
   242  				Eventually(session.Out).Should(Say(`Updating health check type for app %s process web in org %s / space %s as %s\.\.\.`, invalidAppName, orgName, spaceName, userName))
   243  				Eventually(session.Err).Should(Say("App '%s' not found", invalidAppName))
   244  				Eventually(session.Out).Should(Say("FAILED"))
   245  
   246  				Eventually(session).Should(Exit(1))
   247  			})
   248  		})
   249  	})
   250  })