github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/integration/isolated/create_app_manifest_command_test.go (about) 1 package isolated 2 3 import ( 4 "io/ioutil" 5 "os" 6 "path/filepath" 7 8 yaml "gopkg.in/yaml.v2" 9 10 "code.cloudfoundry.org/cli/integration/helpers" 11 . "github.com/onsi/ginkgo" 12 . "github.com/onsi/gomega" 13 . "github.com/onsi/gomega/gexec" 14 ) 15 16 type Manifest struct { 17 Applications []struct { 18 HealthCheckType string `yaml:"health-check-type"` 19 HealthCheckHTTPEndpoint string `yaml:"health-check-http-endpoint"` 20 Routes []struct { 21 Route string `yaml:"route"` 22 } `yaml:"routes"` 23 } `yaml:"applications"` 24 } 25 26 func createManifest(appName string) (*Manifest, error) { 27 tmpDir, err := ioutil.TempDir("", "") 28 defer os.RemoveAll(tmpDir) 29 if err != nil { 30 return nil, err 31 } 32 33 manifestPath := filepath.Join(tmpDir, "manifest.yml") 34 Eventually(helpers.CF("create-app-manifest", appName, "-p", manifestPath)).Should(Exit(0)) 35 36 manifestContents, err := ioutil.ReadFile(manifestPath) 37 if err != nil { 38 return nil, err 39 } 40 41 manifest := new(Manifest) 42 err = yaml.Unmarshal(manifestContents, manifest) 43 if err != nil { 44 return nil, err 45 } 46 47 return manifest, nil 48 } 49 50 var _ = Describe("create-app-manifest command", func() { 51 var ( 52 orgName string 53 spaceName string 54 appName string 55 ) 56 57 BeforeEach(func() { 58 orgName = helpers.NewOrgName() 59 spaceName = helpers.PrefixedRandomName("SPACE") 60 61 appName = helpers.PrefixedRandomName("app") 62 63 setupCF(orgName, spaceName) 64 }) 65 66 Context("when app has no hostname", func() { 67 var domain helpers.Domain 68 69 BeforeEach(func() { 70 domain = helpers.NewDomain(orgName, helpers.DomainName("")) 71 domain.Create() 72 73 helpers.WithHelloWorldApp(func(appDir string) { 74 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "--no-hostname", "-d", domain.Name)).Should(Exit(0)) 75 }) 76 }) 77 78 It("contains routes without hostnames", func() { 79 manifest, err := createManifest(appName) 80 Expect(err).ToNot(HaveOccurred()) 81 82 Expect(manifest.Applications).To(HaveLen(1)) 83 Expect(manifest.Applications[0].Routes).To(HaveLen(1)) 84 Expect(manifest.Applications[0].Routes[0].Route).To(Equal(domain.Name)) 85 }) 86 }) 87 88 Context("health check type", func() { 89 Context("when the health check type is port", func() { 90 BeforeEach(func() { 91 helpers.WithHelloWorldApp(func(appDir string) { 92 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "-u", "port")).Should(Exit(0)) 93 }) 94 }) 95 96 It("does not write the type or endpoint to the manifest", func() { 97 manifest, err := createManifest(appName) 98 Expect(err).ToNot(HaveOccurred()) 99 100 Expect(manifest.Applications).To(HaveLen(1)) 101 Expect(manifest.Applications[0].HealthCheckType).To(BeEmpty()) 102 Expect(manifest.Applications[0].HealthCheckHTTPEndpoint).To(BeEmpty()) 103 }) 104 105 Context("when the health check http endpoint is not /", func() { 106 BeforeEach(func() { 107 Eventually(helpers.CF("set-health-check", appName, "http", "--endpoint", "/some-endpoint")).Should(Exit(0)) 108 Eventually(helpers.CF("set-health-check", appName, "port")).Should(Exit(0)) 109 }) 110 111 It("still does not write the endpoint to the manifest", func() { 112 manifest, err := createManifest(appName) 113 Expect(err).ToNot(HaveOccurred()) 114 115 Expect(manifest.Applications).To(HaveLen(1)) 116 Expect(manifest.Applications[0].HealthCheckHTTPEndpoint).To(BeEmpty()) 117 }) 118 }) 119 }) 120 121 Context("when the health check type is not port", func() { 122 BeforeEach(func() { 123 helpers.WithHelloWorldApp(func(appDir string) { 124 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "-u", "http")).Should(Exit(0)) 125 }) 126 }) 127 128 It("writes it to the manifest", func() { 129 manifest, err := createManifest(appName) 130 Expect(err).ToNot(HaveOccurred()) 131 132 Expect(manifest.Applications).To(HaveLen(1)) 133 Expect(manifest.Applications[0].HealthCheckType).To(Equal("http")) 134 }) 135 }) 136 }) 137 138 Context("health check http endpoint", func() { 139 BeforeEach(func() { 140 helpers.WithHelloWorldApp(func(appDir string) { 141 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack", "-u", "http")).Should(Exit(0)) 142 }) 143 }) 144 145 Context("when the health check http endpoint is /", func() { 146 It("does not write it to the manifest", func() { 147 manifest, err := createManifest(appName) 148 Expect(err).ToNot(HaveOccurred()) 149 150 Expect(manifest.Applications).To(HaveLen(1)) 151 Expect(manifest.Applications[0].HealthCheckHTTPEndpoint).To(BeEmpty()) 152 }) 153 }) 154 155 Context("when the health check endpoint is not /", func() { 156 BeforeEach(func() { 157 Eventually(helpers.CF("set-health-check", appName, "http", "--endpoint", "/some-endpoint")).Should(Exit(0)) 158 }) 159 160 It("writes it to the manifest", func() { 161 manifest, err := createManifest(appName) 162 Expect(err).ToNot(HaveOccurred()) 163 164 Expect(manifest.Applications).To(HaveLen(1)) 165 Expect(manifest.Applications[0].HealthCheckHTTPEndpoint).To(Equal("/some-endpoint")) 166 }) 167 }) 168 }) 169 })