github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/integration/isolated/push_command_test.go (about) 1 package isolated 2 3 import ( 4 "crypto/rand" 5 "fmt" 6 "io/ioutil" 7 "os" 8 "path/filepath" 9 "runtime" 10 11 "code.cloudfoundry.org/cli/integration/helpers" 12 13 . "github.com/onsi/ginkgo" 14 . "github.com/onsi/gomega" 15 . "github.com/onsi/gomega/gbytes" 16 . "github.com/onsi/gomega/gexec" 17 ) 18 19 var _ = Describe("Push", func() { 20 Context("when the environment is set up correctly", func() { 21 var ( 22 orgName string 23 spaceName string 24 ) 25 26 BeforeEach(func() { 27 orgName = helpers.NewOrgName() 28 spaceName = helpers.PrefixedRandomName("SPACE") 29 30 setupCF(orgName, spaceName) 31 }) 32 33 Context("when manifest contains non-string env values", func() { 34 var appName string 35 36 BeforeEach(func() { 37 appName = helpers.PrefixedRandomName("app") 38 helpers.WithHelloWorldApp(func(appDir string) { 39 manifestContents := []byte(fmt.Sprintf(` 40 --- 41 applications: 42 - name: %s 43 memory: 128M 44 env: 45 big_float: 123456789.12345678 46 big_int: 123412341234 47 bool: true 48 small_int: 7 49 string: "some-string" 50 `, appName)) 51 manifestPath := filepath.Join(appDir, "manifest.yml") 52 err := ioutil.WriteFile(manifestPath, manifestContents, 0666) 53 Expect(err).ToNot(HaveOccurred()) 54 55 // Create manifest and add big numbers 56 Eventually(helpers.CF("push", appName, "--no-start", "-p", appDir, "-f", manifestPath, "-b", "staticfile_buildpack")).Should(Exit(0)) 57 }) 58 }) 59 60 It("converts all env values to string", func() { 61 session := helpers.CF("env", appName) 62 Eventually(session.Out).Should(Say("OK")) 63 Eventually(session.Out).Should(Say("big_float: 123456789.12345678")) 64 Eventually(session.Out).Should(Say("big_int: 123412341234")) 65 Eventually(session.Out).Should(Say("bool: true")) 66 Eventually(session.Out).Should(Say("small_int: 7")) 67 Eventually(session.Out).Should(Say("string: some-string")) 68 Eventually(session).Should(Exit(0)) 69 }) 70 }) 71 72 Context("when the app has over 260 character paths", func() { 73 var tmpDir string 74 75 BeforeEach(func() { 76 Skip("Unskip when #134888875 is complete") 77 var err error 78 tmpDir, err = ioutil.TempDir("", "") 79 Expect(err).ToNot(HaveOccurred()) 80 81 dirName := "dir_name" 82 dirNames := []string{} 83 for i := 0; i < 32; i++ { // minimum 300 chars, including separators 84 dirNames = append(dirNames, dirName) 85 } 86 87 fullPath := filepath.Join(tmpDir, filepath.Join(dirNames...)) 88 if runtime.GOOS == "windows" { 89 // `\\?\` is used to skip Windows' file name processor, which imposes 90 // length limits. Search MSDN for 'Maximum Path Length Limitation' for 91 // more. 92 fullPath = `\\?\` + fullPath 93 } 94 err = os.MkdirAll(fullPath, os.ModeDir|os.ModePerm) 95 Expect(err).NotTo(HaveOccurred()) 96 97 err = ioutil.WriteFile(filepath.Join(fullPath, "index.html"), []byte("hello world"), 0666) 98 Expect(err).ToNot(HaveOccurred()) 99 }) 100 101 It("successfully pushes the app", func() { 102 defer os.RemoveAll(tmpDir) 103 appName := helpers.PrefixedRandomName("APP") 104 session := helpers.CF("push", appName, "-p", tmpDir, "-b", "staticfile_buildpack") 105 Eventually(session).Should(Say("1 of 1 instances running")) 106 Eventually(session).Should(Say("App %s was started using this command", appName)) 107 Eventually(session).Should(Exit(0)) 108 }) 109 }) 110 111 Context("when pushing with manifest routes and specifying the -n flag", func() { 112 var ( 113 quotaName string 114 appDir string 115 manifestPath string 116 privateDomain helpers.Domain 117 sharedDomain helpers.Domain 118 tcpDomain helpers.Domain 119 ) 120 121 BeforeEach(func() { 122 quotaName = helpers.PrefixedRandomName("INTEGRATION-QUOTA") 123 124 session := helpers.CF("create-quota", quotaName, "-m", "10G", "-r", "10", "--reserved-route-ports", "4") 125 Eventually(session).Should(Exit(0)) 126 session = helpers.CF("set-quota", orgName, quotaName) 127 Eventually(session).Should(Exit(0)) 128 129 privateDomain = helpers.NewDomain(orgName, helpers.DomainName("private")) 130 privateDomain.Create() 131 sharedDomain = helpers.NewDomain(orgName, helpers.DomainName("shared")) 132 sharedDomain.CreateShared() 133 tcpDomain = helpers.NewDomain(orgName, helpers.DomainName("tcp")) 134 tcpDomain.CreateWithRouterGroup("default-tcp") 135 136 var err error 137 appDir, err = ioutil.TempDir("", "simple-app") 138 Expect(err).ToNot(HaveOccurred()) 139 manifestContents := []byte(fmt.Sprintf(` 140 --- 141 applications: 142 - name: app-with-routes 143 memory: 100M 144 instances: 1 145 path: . 146 routes: 147 - route: %s 148 - route: %s 149 - route: manifest-host.%s/path 150 - route: %s:1100 151 `, privateDomain.Name, sharedDomain.Name, sharedDomain.Name, tcpDomain.Name)) 152 manifestPath = filepath.Join(appDir, "manifest.yml") 153 err = ioutil.WriteFile(manifestPath, manifestContents, 0666) 154 Expect(err).ToNot(HaveOccurred()) 155 156 err = ioutil.WriteFile(filepath.Join(appDir, "index.html"), []byte("hello world"), 0666) 157 Expect(err).ToNot(HaveOccurred()) 158 }) 159 160 It("should set or replace the route's hostname with the flag value", func() { 161 defer os.RemoveAll(appDir) 162 var session *Session 163 session = helpers.CF("push", helpers.PrefixedRandomName("APP"), "-p", appDir, "-n", "flag-hostname", "-b", "staticfile_buildpack", "-f", manifestPath) 164 165 Eventually(session).Should(Say("Creating route flag-hostname.%s...\nOK", privateDomain.Name)) 166 Eventually(session).Should(Say("Creating route flag-hostname.%s...\nOK", sharedDomain.Name)) 167 Eventually(session).Should(Say("Creating route flag-hostname.%s/path...\nOK", sharedDomain.Name)) 168 Eventually(session).Should(Say("Creating route %s:1100...\nOK", tcpDomain.Name)) 169 Eventually(session).Should(Exit(0)) 170 }) 171 }) 172 173 Context("pushing an app that already exists", func() { 174 It("uses resource matching", func() { 175 randomBytes := make([]byte, 65537) 176 _, err := rand.Read(randomBytes) 177 Expect(err).ToNot(HaveOccurred()) 178 179 appName := helpers.PrefixedRandomName("app") 180 181 helpers.WithHelloWorldApp(func(appDir string) { 182 path := filepath.Join(appDir, "large.txt") 183 err = ioutil.WriteFile(path, randomBytes, 0666) 184 Expect(err).ToNot(HaveOccurred()) 185 186 session := helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack") 187 Eventually(session.Out).Should(Say("Uploading .+, 2 files")) 188 Eventually(session).Should(Exit(0)) 189 190 session = helpers.CF("push", appName, "--no-start", "-p", appDir, "-b", "staticfile_buildpack") 191 Eventually(session.Out).Should(Say("Uploading .+, 1 files")) 192 Eventually(session).Should(Exit(0)) 193 }) 194 }) 195 }) 196 }) 197 })