github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/integration/isolated/get_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/gomega"
     8  	. "github.com/onsi/gomega/gbytes"
     9  	. "github.com/onsi/gomega/gexec"
    10  )
    11  
    12  var _ = Describe("get-health-check command", func() {
    13  	Describe("help", func() {
    14  		Context("when --help flag is set", func() {
    15  			It("Displays command usage to output", func() {
    16  				session := helpers.CF("get-health-check", "--help")
    17  
    18  				Eventually(session.Out).Should(Say("NAME:"))
    19  				Eventually(session.Out).Should(Say("   get-health-check - Show the type of health check performed on an app"))
    20  				Eventually(session.Out).Should(Say("USAGE:"))
    21  				Eventually(session.Out).Should(Say("   cf get-health-check APP_NAME"))
    22  				Eventually(session).Should(Exit(0))
    23  			})
    24  		})
    25  	})
    26  
    27  	Context("when the environment is not setup correctly", func() {
    28  		Context("when no API endpoint is set", func() {
    29  			BeforeEach(func() {
    30  				helpers.UnsetAPI()
    31  			})
    32  
    33  			It("fails with no API endpoint set message", func() {
    34  				session := helpers.CF("get-health-check", "some-app")
    35  
    36  				Eventually(session.Out).Should(Say("FAILED"))
    37  				Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\."))
    38  				Eventually(session).Should(Exit(1))
    39  			})
    40  		})
    41  
    42  		Context("when not logged in", func() {
    43  			BeforeEach(func() {
    44  				helpers.LogoutCF()
    45  			})
    46  
    47  			It("fails with not logged in message", func() {
    48  				session := helpers.CF("get-health-check", "some-app")
    49  
    50  				Eventually(session.Out).Should(Say("FAILED"))
    51  				Eventually(session.Err).Should(Say("Not logged in\\. Use 'cf login' to log in\\."))
    52  				Eventually(session).Should(Exit(1))
    53  			})
    54  		})
    55  
    56  		Context("when there is no org and space set", func() {
    57  			BeforeEach(func() {
    58  				helpers.LogoutCF()
    59  				helpers.LoginCF()
    60  			})
    61  
    62  			It("fails with no targeted org error message", func() {
    63  				session := helpers.CF("get-health-check", "some-app")
    64  
    65  				Eventually(session.Out).Should(Say("FAILED"))
    66  				Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org"))
    67  				Eventually(session).Should(Exit(1))
    68  			})
    69  		})
    70  
    71  		Context("when there is no space set", func() {
    72  			BeforeEach(func() {
    73  				helpers.LogoutCF()
    74  				helpers.LoginCF()
    75  				helpers.TargetOrg(ReadOnlyOrg)
    76  			})
    77  
    78  			It("fails with no targeted space error message", func() {
    79  				session := helpers.CF("get-health-check", "some-app")
    80  
    81  				Eventually(session.Out).Should(Say("FAILED"))
    82  				Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space\\."))
    83  				Eventually(session).Should(Exit(1))
    84  			})
    85  		})
    86  	})
    87  
    88  	Context("when the environment is set up correctly", func() {
    89  		var (
    90  			orgName   string
    91  			spaceName string
    92  		)
    93  
    94  		BeforeEach(func() {
    95  			orgName = helpers.NewOrgName()
    96  			spaceName = helpers.NewSpaceName()
    97  
    98  			setupCF(orgName, spaceName)
    99  		})
   100  
   101  		AfterEach(func() {
   102  			helpers.QuickDeleteOrg(orgName)
   103  		})
   104  
   105  		Context("when the input is invalid", func() {
   106  			Context("when there are not enough arguments", func() {
   107  				It("outputs the usage and exits 1", func() {
   108  					session := helpers.CF("get-health-check")
   109  
   110  					Eventually(session.Err).Should(Say("Incorrect Usage:"))
   111  					Eventually(session.Out).Should(Say("NAME:"))
   112  					Eventually(session).Should(Exit(1))
   113  				})
   114  			})
   115  
   116  			Context("when there too many arguments", func() {
   117  				It("ignores the extra arguments", func() {
   118  					appName := helpers.PrefixedRandomName("app")
   119  					session := helpers.CF("get-health-check", appName, "extra")
   120  					username, _ := helpers.GetCredentials()
   121  
   122  					Eventually(session.Out).Should(Say("Getting health check type for app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, username))
   123  					Eventually(session.Err).Should(Say("App %s not found", appName))
   124  					Eventually(session.Out).Should(Say("FAILED"))
   125  					Eventually(session).Should(Exit(1))
   126  				})
   127  			})
   128  		})
   129  
   130  		Context("when the app does not exist", func() {
   131  			It("tells the user that the app is not found and exits 1", func() {
   132  				appName := helpers.PrefixedRandomName("app")
   133  				session := helpers.CF("get-health-check", appName)
   134  				username, _ := helpers.GetCredentials()
   135  
   136  				Eventually(session.Out).Should(Say("Getting health check type for app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, username))
   137  				Eventually(session.Err).Should(Say("App %s not found", appName))
   138  				Eventually(session.Out).Should(Say("FAILED"))
   139  				Eventually(session).Should(Exit(1))
   140  			})
   141  		})
   142  
   143  		Context("when the app exists", func() {
   144  			var (
   145  				appName  string
   146  				username string
   147  			)
   148  
   149  			BeforeEach(func() {
   150  				appName = helpers.PrefixedRandomName("app")
   151  				helpers.WithHelloWorldApp(func(appDir string) {
   152  					Eventually(helpers.CF("push", appName, "-p", appDir, "-b", "staticfile_buildpack", "--no-start")).Should(Exit(0))
   153  				})
   154  				username, _ = helpers.GetCredentials()
   155  			})
   156  
   157  			Context("when the health check type is http", func() {
   158  				BeforeEach(func() {
   159  					Eventually(helpers.CF("set-health-check", appName, "http")).Should(Exit(0))
   160  				})
   161  
   162  				It("shows an endpoint", func() {
   163  					session := helpers.CF("get-health-check", appName)
   164  
   165  					Eventually(session.Out).Should(Say("Getting health check type for app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, username))
   166  					Eventually(session.Out).Should(Say("\n\n"))
   167  					Eventually(session.Out).Should(Say("health check type:          http"))
   168  					Eventually(session.Out).Should(Say("endpoint \\(for http type\\):   /"))
   169  					Eventually(session).Should(Exit(0))
   170  				})
   171  			})
   172  
   173  			Context("when the health check type is http with a custom endpoint", func() {
   174  				BeforeEach(func() {
   175  					Eventually(helpers.CF("set-health-check", appName, "http", "--endpoint", "/some-endpoint")).Should(Exit(0))
   176  				})
   177  
   178  				It("show the custom endpoint", func() {
   179  					session := helpers.CF("get-health-check", appName)
   180  
   181  					Eventually(session.Out).Should(Say("Getting health check type for app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, username))
   182  					Eventually(session.Out).Should(Say("\n\n"))
   183  					Eventually(session.Out).Should(Say("health check type:          http"))
   184  					Eventually(session.Out).Should(Say("endpoint \\(for http type\\):   /some-endpoint"))
   185  					Eventually(session).Should(Exit(0))
   186  				})
   187  			})
   188  
   189  			Context("when the health check type is none", func() {
   190  				BeforeEach(func() {
   191  					Eventually(helpers.CF("set-health-check", appName, "none")).Should(Exit(0))
   192  				})
   193  
   194  				It("does not show an endpoint", func() {
   195  					session := helpers.CF("get-health-check", appName)
   196  
   197  					Eventually(session.Out).Should(Say("Getting health check type for app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, username))
   198  					Eventually(session.Out).Should(Say("\n\n"))
   199  					Eventually(session.Out).Should(Say("health check type:          none"))
   200  					Eventually(session.Out).Should(Say("(?m)endpoint \\(for http type\\):   $"))
   201  					Eventually(session).Should(Exit(0))
   202  				})
   203  			})
   204  
   205  			Context("when the health check type is port", func() {
   206  				BeforeEach(func() {
   207  					Eventually(helpers.CF("set-health-check", appName, "port")).Should(Exit(0))
   208  				})
   209  
   210  				It("does not show an endpoint", func() {
   211  					session := helpers.CF("get-health-check", appName)
   212  
   213  					Eventually(session.Out).Should(Say("Getting health check type for app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, username))
   214  					Eventually(session.Out).Should(Say("\n\n"))
   215  					Eventually(session.Out).Should(Say("health check type:          port"))
   216  					Eventually(session.Out).Should(Say("(?m)endpoint \\(for http type\\):   $"))
   217  					Eventually(session).Should(Exit(0))
   218  				})
   219  			})
   220  
   221  			Context("when the health check type is process", func() {
   222  				BeforeEach(func() {
   223  					Eventually(helpers.CF("set-health-check", appName, "process")).Should(Exit(0))
   224  				})
   225  
   226  				It("does not show an endpoint", func() {
   227  					session := helpers.CF("get-health-check", appName)
   228  
   229  					Eventually(session.Out).Should(Say("Getting health check type for app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, username))
   230  					Eventually(session.Out).Should(Say("\n\n"))
   231  					Eventually(session.Out).Should(Say("health check type:          process"))
   232  					Eventually(session.Out).Should(Say("(?m)endpoint \\(for http type\\):   $"))
   233  					Eventually(session).Should(Exit(0))
   234  				})
   235  			})
   236  
   237  			Context("when the health check type changes from http to another type", func() {
   238  				BeforeEach(func() {
   239  					Eventually(helpers.CF("set-health-check", appName, "http", "--endpoint", "/some-endpoint")).Should(Exit(0))
   240  					Eventually(helpers.CF("set-health-check", appName, "process")).Should(Exit(0))
   241  				})
   242  
   243  				It("does not show an endpoint", func() {
   244  					session := helpers.CF("get-health-check", appName)
   245  
   246  					Eventually(session.Out).Should(Say("Getting health check type for app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, username))
   247  					Eventually(session.Out).Should(Say("\n\n"))
   248  					Eventually(session.Out).Should(Say("health check type:          process"))
   249  					Eventually(session.Out).Should(Say("(?m)endpoint \\(for http type\\):   $"))
   250  					Eventually(session).Should(Exit(0))
   251  				})
   252  			})
   253  		})
   254  	})
   255  })