github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/v6/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  )
    10  
    11  var _ = Describe("v3-get-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-get-health-check", "--help")
    28  
    29  				Eventually(session).Should(Say("NAME:"))
    30  				Eventually(session).Should(Say("v3-get-health-check - Show the type of health check performed on an app"))
    31  				Eventually(session).Should(Say("USAGE:"))
    32  				Eventually(session).Should(Say("cf v3-get-health-check APP_NAME"))
    33  
    34  				Eventually(session).Should(Exit(0))
    35  			})
    36  		})
    37  	})
    38  
    39  	When("the app name is not provided", func() {
    40  		It("tells the user that the app name is required, prints help text, and exits 1", func() {
    41  			session := helpers.CF("v3-get-health-check")
    42  
    43  			Eventually(session.Err).Should(Say("Incorrect Usage: the required argument `APP_NAME` was not provided"))
    44  			Eventually(session).Should(Say("NAME:"))
    45  			Eventually(session).Should(Exit(1))
    46  		})
    47  	})
    48  
    49  	It("displays the experimental warning", func() {
    50  		session := helpers.CF("v3-get-health-check", appName)
    51  		Eventually(session.Err).Should(Say("This command is in EXPERIMENTAL stage and may change without notice"))
    52  		Eventually(session).Should(Exit())
    53  	})
    54  
    55  	When("the environment is not setup correctly", func() {
    56  		When("no API endpoint is set", func() {
    57  			BeforeEach(func() {
    58  				helpers.UnsetAPI()
    59  			})
    60  
    61  			It("fails with no API endpoint set message", func() {
    62  				session := helpers.CF("v3-get-health-check", appName)
    63  				Eventually(session).Should(Say("FAILED"))
    64  				Eventually(session.Err).Should(Say(`No API endpoint set\. Use 'cf login' or 'cf api' to target an endpoint\.`))
    65  				Eventually(session).Should(Exit(1))
    66  			})
    67  		})
    68  
    69  		When("not logged in", func() {
    70  			BeforeEach(func() {
    71  				helpers.LogoutCF()
    72  			})
    73  
    74  			It("fails with not logged in message", func() {
    75  				session := helpers.CF("v3-get-health-check", appName)
    76  				Eventually(session).Should(Say("FAILED"))
    77  				Eventually(session.Err).Should(Say(`Not logged in\. Use 'cf login' or 'cf login --sso' to log in\.`))
    78  				Eventually(session).Should(Exit(1))
    79  			})
    80  		})
    81  
    82  		When("there is no org set", func() {
    83  			BeforeEach(func() {
    84  				helpers.LogoutCF()
    85  				helpers.LoginCF()
    86  			})
    87  
    88  			It("fails with no org targeted error message", func() {
    89  				session := helpers.CF("v3-get-health-check", appName)
    90  				Eventually(session).Should(Say("FAILED"))
    91  				Eventually(session.Err).Should(Say(`No org targeted, use 'cf target -o ORG' to target an org\.`))
    92  				Eventually(session).Should(Exit(1))
    93  			})
    94  		})
    95  
    96  		When("there is no space set", func() {
    97  			BeforeEach(func() {
    98  				helpers.LogoutCF()
    99  				helpers.LoginCF()
   100  				helpers.TargetOrg(ReadOnlyOrg)
   101  			})
   102  
   103  			It("fails with no space targeted error message", func() {
   104  				session := helpers.CF("v3-get-health-check", appName)
   105  				Eventually(session).Should(Say("FAILED"))
   106  				Eventually(session.Err).Should(Say(`No space targeted, use 'cf target -s SPACE' to target a space\.`))
   107  				Eventually(session).Should(Exit(1))
   108  			})
   109  		})
   110  	})
   111  
   112  	When("the environment is set up correctly", func() {
   113  		var userName string
   114  
   115  		BeforeEach(func() {
   116  			helpers.SetupCF(orgName, spaceName)
   117  			userName, _ = helpers.GetCredentials()
   118  		})
   119  
   120  		AfterEach(func() {
   121  			helpers.QuickDeleteOrg(orgName)
   122  		})
   123  
   124  		When("the app exists", func() {
   125  			BeforeEach(func() {
   126  				helpers.WithProcfileApp(func(appDir string) {
   127  					Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName)).Should(Exit(0))
   128  				})
   129  			})
   130  
   131  			It("displays the health check types for each process", func() {
   132  				userName, _ = helpers.GetCredentials()
   133  
   134  				session := helpers.CF("v3-get-health-check", appName)
   135  				Eventually(session).Should(Say(`Getting process health check types for app %s in org %s / space %s as %s\.\.\.`, appName, orgName, spaceName, userName))
   136  				Eventually(session).Should(Say(`process\s+health check\s+endpoint \(for http\)\s+invocation timeout\n`))
   137  				Eventually(session).Should(Say(`web\s+port\s+1\n`))
   138  				Eventually(session).Should(Say(`console\s+process\s+1\n`))
   139  
   140  				Eventually(session).Should(Exit(0))
   141  			})
   142  		})
   143  
   144  		When("the app does not exist", func() {
   145  			It("displays app not found and exits 1", func() {
   146  				invalidAppName := "invalid-app-name"
   147  				session := helpers.CF("v3-get-health-check", invalidAppName)
   148  
   149  				Eventually(session).Should(Say(`Getting process health check types for app %s in org %s / space %s as %s\.\.\.`, invalidAppName, orgName, spaceName, userName))
   150  				Eventually(session.Err).Should(Say("App '%s' not found", invalidAppName))
   151  				Eventually(session).Should(Say("FAILED"))
   152  
   153  				Eventually(session).Should(Exit(1))
   154  			})
   155  		})
   156  	})
   157  })