github.com/liamawhite/cli-with-i18n@v6.32.1-0.20171122084555-dede0a5c3448+incompatible/integration/experimental/v3_set_health_check_command_test.go (about)

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