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