github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/integration/experimental/v3_get_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-get-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-get-health-check", "--help")
    29  
    30  				Eventually(session).Should(Say("NAME:"))
    31  				Eventually(session).Should(Say("v3-get-health-check - Show the type of health check performed on an app"))
    32  				Eventually(session).Should(Say("USAGE:"))
    33  				Eventually(session).Should(Say("cf v3-get-health-check APP_NAME"))
    34  
    35  				Eventually(session).Should(Exit(0))
    36  			})
    37  		})
    38  	})
    39  
    40  	Context("when the app name is not provided", func() {
    41  		It("tells the user that the app name is required, prints help text, and exits 1", func() {
    42  			session := helpers.CF("v3-get-health-check")
    43  
    44  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided"))
    45  			Eventually(session).Should(Say("NAME:"))
    46  			Eventually(session).Should(Exit(1))
    47  		})
    48  	})
    49  
    50  	It("displays the experimental warning", func() {
    51  		session := helpers.CF("v3-get-health-check", appName)
    52  		Eventually(session).Should(Say("This command is in EXPERIMENTAL stage and may change without notice"))
    53  		Eventually(session).Should(Exit())
    54  	})
    55  
    56  	Context("when the environment is not setup correctly", func() {
    57  		Context("when no API endpoint is set", func() {
    58  			BeforeEach(func() {
    59  				helpers.UnsetAPI()
    60  			})
    61  
    62  			It("fails with no API endpoint set message", func() {
    63  				session := helpers.CF("v3-get-health-check", appName)
    64  				Eventually(session).Should(Say("FAILED"))
    65  				Eventually(session.Err).Should(Say("No API endpoint set\\. Use 'cf login' or 'cf api' to target an endpoint\\."))
    66  				Eventually(session).Should(Exit(1))
    67  			})
    68  		})
    69  
    70  		Context("when the v3 api does not exist", func() {
    71  			var server *Server
    72  
    73  			BeforeEach(func() {
    74  				server = helpers.StartAndTargetServerWithoutV3API()
    75  			})
    76  
    77  			AfterEach(func() {
    78  				server.Close()
    79  			})
    80  
    81  			It("fails with error message that the minimum version is not met", func() {
    82  				session := helpers.CF("v3-get-health-check", appName)
    83  				Eventually(session).Should(Say("FAILED"))
    84  				Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\."))
    85  				Eventually(session).Should(Exit(1))
    86  			})
    87  		})
    88  
    89  		Context("when the v3 api version is lower than the minimum version", func() {
    90  			var server *Server
    91  
    92  			BeforeEach(func() {
    93  				server = helpers.StartAndTargetServerWithV3Version("3.0.0")
    94  			})
    95  
    96  			AfterEach(func() {
    97  				server.Close()
    98  			})
    99  
   100  			It("fails with error message that the minimum version is not met", func() {
   101  				session := helpers.CF("v3-get-health-check", appName)
   102  				Eventually(session).Should(Say("FAILED"))
   103  				Eventually(session.Err).Should(Say("This command requires CF API version 3\\.27\\.0 or higher\\."))
   104  				Eventually(session).Should(Exit(1))
   105  			})
   106  		})
   107  
   108  		Context("when not logged in", func() {
   109  			BeforeEach(func() {
   110  				helpers.LogoutCF()
   111  			})
   112  
   113  			It("fails with not logged in message", func() {
   114  				session := helpers.CF("v3-get-health-check", appName)
   115  				Eventually(session).Should(Say("FAILED"))
   116  				Eventually(session.Err).Should(Say("Not logged in\\. Use 'cf login' to log in\\."))
   117  				Eventually(session).Should(Exit(1))
   118  			})
   119  		})
   120  
   121  		Context("when there is no org set", func() {
   122  			BeforeEach(func() {
   123  				helpers.LogoutCF()
   124  				helpers.LoginCF()
   125  			})
   126  
   127  			It("fails with no org targeted error message", func() {
   128  				session := helpers.CF("v3-get-health-check", appName)
   129  				Eventually(session).Should(Say("FAILED"))
   130  				Eventually(session.Err).Should(Say("No org targeted, use 'cf target -o ORG' to target an org\\."))
   131  				Eventually(session).Should(Exit(1))
   132  			})
   133  		})
   134  
   135  		Context("when there is no space set", func() {
   136  			BeforeEach(func() {
   137  				helpers.LogoutCF()
   138  				helpers.LoginCF()
   139  				helpers.TargetOrg(ReadOnlyOrg)
   140  			})
   141  
   142  			It("fails with no space targeted error message", func() {
   143  				session := helpers.CF("v3-get-health-check", appName)
   144  				Eventually(session).Should(Say("FAILED"))
   145  				Eventually(session.Err).Should(Say("No space targeted, use 'cf target -s SPACE' to target a space\\."))
   146  				Eventually(session).Should(Exit(1))
   147  			})
   148  		})
   149  	})
   150  
   151  	Context("when the environment is set up correctly", func() {
   152  		var userName string
   153  
   154  		BeforeEach(func() {
   155  			setupCF(orgName, spaceName)
   156  			userName, _ = helpers.GetCredentials()
   157  		})
   158  
   159  		AfterEach(func() {
   160  			helpers.QuickDeleteOrg(orgName)
   161  		})
   162  
   163  		Context("when the app exists", func() {
   164  			BeforeEach(func() {
   165  				helpers.WithProcfileApp(func(appDir string) {
   166  					Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName)).Should(Exit(0))
   167  				})
   168  			})
   169  
   170  			It("displays the health check types for each process", func() {
   171  				userName, _ = helpers.GetCredentials()
   172  
   173  				session := helpers.CF("v3-get-health-check", appName)
   174  				Eventually(session).Should(Say("Getting process health check types for app %s in org %s / space %s as %s\\.\\.\\.", appName, orgName, spaceName, userName))
   175  				Eventually(session).Should(Say(`process\s+health check\s+endpoint \(for http\)\n`))
   176  				Eventually(session).Should(Say(`web\s+port\s+\n`))
   177  				Eventually(session).Should(Say(`console\s+process\s+\n`))
   178  
   179  				Eventually(session).Should(Exit(0))
   180  			})
   181  		})
   182  
   183  		Context("when the app does not exist", func() {
   184  			It("displays app not found and exits 1", func() {
   185  				invalidAppName := "invalid-app-name"
   186  				session := helpers.CF("v3-get-health-check", invalidAppName)
   187  
   188  				Eventually(session).Should(Say("Getting process health check types for app %s in org %s / space %s as %s\\.\\.\\.", invalidAppName, orgName, spaceName, userName))
   189  				Eventually(session.Err).Should(Say("App %s not found", invalidAppName))
   190  				Eventually(session).Should(Say("FAILED"))
   191  
   192  				Eventually(session).Should(Exit(1))
   193  			})
   194  		})
   195  	})
   196  })