github.com/wanddynosios/cli@v7.1.0+incompatible/integration/v6/push/health_check_test.go (about)

     1  package push
     2  
     3  import (
     4  	"fmt"
     5  	"path/filepath"
     6  
     7  	"code.cloudfoundry.org/cli/integration/helpers"
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  	. "github.com/onsi/gomega/gbytes"
    11  	. "github.com/onsi/gomega/gexec"
    12  )
    13  
    14  var _ = Describe("push/update an app using health check type", func() {
    15  	var (
    16  		appName  string
    17  		username string
    18  	)
    19  
    20  	BeforeEach(func() {
    21  		appName = helpers.NewAppName()
    22  		username, _ = helpers.GetCredentials()
    23  	})
    24  
    25  	Context("updating the application", func() {
    26  		BeforeEach(func() {
    27  			helpers.WithHelloWorldApp(func(dir string) {
    28  				session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "-u", "http", "--no-start")
    29  				Eventually(session).Should(Say(`Pushing app %s to org %s / space %s as %s\.\.\.`, appName, organization, space, username))
    30  				Eventually(session).Should(Exit(0))
    31  
    32  				Eventually(helpers.CF("set-health-check", appName, "http", "--endpoint", "/some-endpoint")).Should(Exit(0))
    33  			})
    34  		})
    35  
    36  		When("setting the app to http health check type", func() {
    37  			It("should keep the health check http endpoint", func() {
    38  				helpers.WithHelloWorldApp(func(dir string) {
    39  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "-u", "http", "--no-start")
    40  					Eventually(session).Should(Say(`Pushing app %s to org %s / space %s as %s\.\.\.`, appName, organization, space, username))
    41  					Eventually(session).ShouldNot(Say(`\-\s+health check http endpoint:\s+/some-endpoint`))
    42  					Eventually(session).ShouldNot(Say(`\+\s+health check http endpoint:\s+/`))
    43  					Eventually(session).Should(Exit(0))
    44  				})
    45  
    46  				session := helpers.CF("curl", fmt.Sprintf("/v2/apps/%s", helpers.AppGUID(appName)))
    47  				Eventually(session).Should(Say(`"health_check_type":\s+"http"`))
    48  				Eventually(session).Should(Say(`"health_check_http_endpoint":\s+"/"`))
    49  			})
    50  		})
    51  
    52  		When("setting the app to port health check type", func() {
    53  			It("should reset the health check http endpoint", func() {
    54  				helpers.WithHelloWorldApp(func(dir string) {
    55  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "-u", "port", "--no-start")
    56  					Eventually(session).Should(Say(`Pushing app %s to org %s / space %s as %s\.\.\.`, appName, organization, space, username))
    57  					Eventually(session).Should(Say(`\-\s+health check http endpoint:\s+/some-endpoint`))
    58  					Eventually(session).Should(Say(`\-\s+health check type:\s+http`))
    59  					Eventually(session).Should(Say(`\+\s+health check type:\s+port`))
    60  					Eventually(session).Should(Exit(0))
    61  				})
    62  
    63  				session := helpers.CF("curl", fmt.Sprintf("/v2/apps/%s", helpers.AppGUID(appName)))
    64  				Eventually(session).Should(Say(`"health_check_type":\s+"port"`))
    65  				Eventually(session).Should(Say(`"health_check_http_endpoint":\s+""`))
    66  			})
    67  		})
    68  
    69  		When("setting the app to process health check type", func() {
    70  			It("should reset the health check http endpoint", func() {
    71  				helpers.WithHelloWorldApp(func(dir string) {
    72  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "-u", "process", "--no-start")
    73  					Eventually(session).Should(Say(`Pushing app %s to org %s / space %s as %s\.\.\.`, appName, organization, space, username))
    74  					Eventually(session).Should(Say(`\-\s+health check http endpoint:\s+/some-endpoint`))
    75  					Eventually(session).Should(Say(`\-\s+health check type:\s+http`))
    76  					Eventually(session).Should(Say(`\+\s+health check type:\s+process`))
    77  					Eventually(session).Should(Exit(0))
    78  				})
    79  
    80  				session := helpers.CF("curl", fmt.Sprintf("/v2/apps/%s", helpers.AppGUID(appName)))
    81  				Eventually(session).Should(Say(`"health_check_type":\s+"process"`))
    82  				Eventually(session).Should(Say(`"health_check_http_endpoint":\s+""`))
    83  			})
    84  		})
    85  	})
    86  
    87  	Context("creating the application", func() {
    88  		When("setting a http health check type", func() {
    89  			It("should set the health check type to http and use the default health check endpoint", func() {
    90  				helpers.WithHelloWorldApp(func(dir string) {
    91  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "-u", "http", "--no-start")
    92  
    93  					Eventually(session).Should(Say(`Pushing app %s to org %s / space %s as %s\.\.\.`, appName, organization, space, username))
    94  					Eventually(session).Should(Say(`\+\s+health check http endpoint:\s+/`))
    95  					Eventually(session).Should(Say(`\+\s+health check type:\s+http`))
    96  					Eventually(session).Should(Exit(0))
    97  				})
    98  
    99  				session := helpers.CF("curl", fmt.Sprintf("/v2/apps/%s", helpers.AppGUID(appName)))
   100  				Eventually(session).Should(Say(`"health_check_type":\s+"http"`))
   101  				Eventually(session).Should(Say(`"health_check_http_endpoint":\s+"/"`))
   102  			})
   103  
   104  			When("setting a health check endpoint", func() {
   105  				It("should use the provided endpoint", func() {
   106  					helpers.WithHelloWorldApp(func(dir string) {
   107  						helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   108  							"applications": []map[string]interface{}{
   109  								{
   110  									"name":                       appName,
   111  									"health-check-type":          "http",
   112  									"health-check-http-endpoint": "/some-endpoint",
   113  								},
   114  							},
   115  						})
   116  
   117  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start")
   118  						Eventually(session).Should(Say(`Pushing from manifest to org %s / space %s as %s\.\.\.`, organization, space, username))
   119  						Eventually(session).Should(Say(`\s+health check http endpoint:\s+/some-endpoint`))
   120  						Eventually(session).Should(Say(`\s+health check type:\s+http`))
   121  						Eventually(session).Should(Exit(0))
   122  					})
   123  
   124  					session := helpers.CF("curl", fmt.Sprintf("/v2/apps/%s", helpers.AppGUID(appName)))
   125  					Eventually(session).Should(Say(`"health_check_type":\s+"http"`))
   126  					Eventually(session).Should(Say(`"health_check_http_endpoint":\s+"/some-endpoint"`))
   127  				})
   128  			})
   129  		})
   130  
   131  		When("setting a port health check type", func() {
   132  			It("it should set the health check type to port", func() {
   133  				helpers.WithHelloWorldApp(func(dir string) {
   134  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "-u", "port", "--no-start")
   135  
   136  					Eventually(session).Should(Say(`Pushing app %s to org %s / space %s as %s\.\.\.`, appName, organization, space, username))
   137  					Eventually(session).Should(Say(`\+\s+health check type:\s+port`))
   138  					Eventually(session).Should(Exit(0))
   139  				})
   140  
   141  				session := helpers.CF("curl", fmt.Sprintf("/v2/apps/%s", helpers.AppGUID(appName)))
   142  				Eventually(session).Should(Say(`"health_check_type":\s+"port"`))
   143  				Eventually(session).Should(Say(`"health_check_http_endpoint":\s+""`))
   144  			})
   145  
   146  			When("setting an health check endpoint", func() {
   147  				It("should return an error", func() {
   148  					helpers.WithHelloWorldApp(func(dir string) {
   149  						helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   150  							"applications": []map[string]interface{}{
   151  								{
   152  									"name":                       appName,
   153  									"health-check-type":          "port",
   154  									"health-check-http-endpoint": "/some-endpoint",
   155  								},
   156  							},
   157  						})
   158  
   159  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start")
   160  						Eventually(session).Should(Say(`Pushing from manifest to org %s / space %s as %s\.\.\.`, organization, space, username))
   161  						Eventually(session.Err).Should(Say("Health check type must be 'http' to set a health check HTTP endpoint."))
   162  
   163  						Eventually(session).Should(Exit(1))
   164  					})
   165  				})
   166  			})
   167  		})
   168  
   169  		When("setting a process health check type", func() {
   170  			It("it should set the health check type to process", func() {
   171  				helpers.WithHelloWorldApp(func(dir string) {
   172  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, appName, "-u", "process", "--no-start")
   173  
   174  					Eventually(session).Should(Say(`Pushing app %s to org %s / space %s as %s\.\.\.`, appName, organization, space, username))
   175  					Eventually(session).Should(Say(`\+\s+health check type:\s+process`))
   176  					Eventually(session).Should(Exit(0))
   177  				})
   178  
   179  				session := helpers.CF("curl", fmt.Sprintf("/v2/apps/%s", helpers.AppGUID(appName)))
   180  				Eventually(session).Should(Say(`"health_check_type":\s+"process"`))
   181  				Eventually(session).Should(Say(`"health_check_http_endpoint":\s+""`))
   182  			})
   183  
   184  			When("setting a health check endpoint", func() {
   185  				It("should return an error", func() {
   186  					helpers.WithHelloWorldApp(func(dir string) {
   187  						helpers.WriteManifest(filepath.Join(dir, "manifest.yml"), map[string]interface{}{
   188  							"applications": []map[string]interface{}{
   189  								{
   190  									"name":                       appName,
   191  									"health-check-type":          "process",
   192  									"health-check-http-endpoint": "/some-endpoint",
   193  								},
   194  							},
   195  						})
   196  
   197  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, "--no-start")
   198  						Eventually(session).Should(Say(`Pushing from manifest to org %s / space %s as %s\.\.\.`, organization, space, username))
   199  						Eventually(session.Err).Should(Say("Health check type must be 'http' to set a health check HTTP endpoint."))
   200  
   201  						Eventually(session).Should(Exit(1))
   202  					})
   203  				})
   204  			})
   205  		})
   206  	})
   207  })