github.com/liamawhite/cli-with-i18n@v6.32.1-0.20171122084555-dede0a5c3448+incompatible/integration/experimental/v3_push_cfignore_test.go (about)

     1  package experimental
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"path/filepath"
     7  
     8  	"github.com/liamawhite/cli-with-i18n/integration/helpers"
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  	. "github.com/onsi/gomega/gexec"
    12  )
    13  
    14  var _ = Describe("v3-push with .cfignore", func() {
    15  	var (
    16  		orgName   string
    17  		spaceName string
    18  		appName   string
    19  	)
    20  
    21  	BeforeEach(func() {
    22  		orgName = helpers.NewOrgName()
    23  		spaceName = helpers.NewSpaceName()
    24  		appName = helpers.PrefixedRandomName("app")
    25  		setupCF(orgName, spaceName)
    26  
    27  	})
    28  
    29  	AfterEach(func() {
    30  		helpers.QuickDeleteOrg(orgName)
    31  	})
    32  
    33  	Context("when .cfignore file exists", func() {
    34  		Context("when the .cfignore file doesn't exclude any files", func() {
    35  			It("pushes all the files except .cfignore", func() {
    36  				helpers.WithHelloWorldApp(func(appDir string) {
    37  					file1 := filepath.Join(appDir, "file1")
    38  					err := ioutil.WriteFile(file1, nil, 0666)
    39  					Expect(err).ToNot(HaveOccurred())
    40  
    41  					file2 := filepath.Join(appDir, "file2")
    42  					err = ioutil.WriteFile(file2, nil, 0666)
    43  					Expect(err).ToNot(HaveOccurred())
    44  
    45  					cfIgnoreFilePath := filepath.Join(appDir, ".cfignore")
    46  					err = ioutil.WriteFile(cfIgnoreFilePath, nil, 0666)
    47  					Expect(err).ToNot(HaveOccurred())
    48  
    49  					darcsFile := filepath.Join(appDir, "_darcs")
    50  					err = ioutil.WriteFile(darcsFile, nil, 0666)
    51  					Expect(err).ToNot(HaveOccurred())
    52  
    53  					dsFile := filepath.Join(appDir, ".DS_Store")
    54  					err = ioutil.WriteFile(dsFile, nil, 0666)
    55  					Expect(err).ToNot(HaveOccurred())
    56  
    57  					gitFile := filepath.Join(appDir, ".git")
    58  					err = ioutil.WriteFile(gitFile, nil, 0666)
    59  					Expect(err).ToNot(HaveOccurred())
    60  
    61  					gitIgnoreFile := filepath.Join(appDir, ".gitignore")
    62  					err = ioutil.WriteFile(gitIgnoreFile, nil, 0666)
    63  					Expect(err).ToNot(HaveOccurred())
    64  
    65  					hgFile := filepath.Join(appDir, ".hg")
    66  					err = ioutil.WriteFile(hgFile, nil, 0666)
    67  					Expect(err).ToNot(HaveOccurred())
    68  
    69  					manifestFile := filepath.Join(appDir, "manifest.yml")
    70  					err = ioutil.WriteFile(manifestFile, nil, 0666)
    71  					Expect(err).ToNot(HaveOccurred())
    72  
    73  					svnFile := filepath.Join(appDir, ".svn")
    74  					err = ioutil.WriteFile(svnFile, nil, 0666)
    75  					Expect(err).ToNot(HaveOccurred())
    76  
    77  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName)
    78  
    79  					Eventually(session).Should(Exit(0))
    80  					helpers.VerifyAppPackageContents(appName, "file1", "file2", "Staticfile", "index.html")
    81  				})
    82  			})
    83  		})
    84  
    85  		Context("when the .cfignore file excludes some files", func() {
    86  			Context("when pushing from the current directory", func() {
    87  				It("does not push those files", func() {
    88  					helpers.WithHelloWorldApp(func(appDir string) {
    89  						file1 := filepath.Join(appDir, "file1")
    90  						err := ioutil.WriteFile(file1, nil, 0666)
    91  						Expect(err).ToNot(HaveOccurred())
    92  
    93  						file2 := filepath.Join(appDir, "file2")
    94  						err = ioutil.WriteFile(file2, nil, 0666)
    95  						Expect(err).ToNot(HaveOccurred())
    96  
    97  						cfIgnoreFilePath := filepath.Join(appDir, ".cfignore")
    98  						err = ioutil.WriteFile(cfIgnoreFilePath, []byte("file*"), 0666)
    99  						Expect(err).ToNot(HaveOccurred())
   100  
   101  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName)
   102  
   103  						Eventually(session).Should(Exit(0))
   104  						helpers.VerifyAppPackageContents(appName, "Staticfile", "index.html")
   105  					})
   106  				})
   107  			})
   108  
   109  			Context("when pushing from a different directory", func() {
   110  				It("does not push those files", func() {
   111  					helpers.WithHelloWorldApp(func(appDir string) {
   112  						file1 := filepath.Join(appDir, "file1")
   113  						err := ioutil.WriteFile(file1, nil, 0666)
   114  						Expect(err).ToNot(HaveOccurred())
   115  
   116  						file2 := filepath.Join(appDir, "file2")
   117  						err = ioutil.WriteFile(file2, nil, 0666)
   118  						Expect(err).ToNot(HaveOccurred())
   119  
   120  						cfIgnoreFilePath := filepath.Join(appDir, ".cfignore")
   121  						err = ioutil.WriteFile(cfIgnoreFilePath, []byte("file*"), 0666)
   122  						Expect(err).ToNot(HaveOccurred())
   123  
   124  						session := helpers.CF("v3-push", appName, "-p", appDir)
   125  
   126  						Eventually(session).Should(Exit(0))
   127  						helpers.VerifyAppPackageContents(appName, "Staticfile", "index.html")
   128  					})
   129  				})
   130  			})
   131  
   132  			Context("when pushing a zip file", func() {
   133  				var archive string
   134  				BeforeEach(func() {
   135  					helpers.WithHelloWorldApp(func(appDir string) {
   136  						file1 := filepath.Join(appDir, "file1")
   137  						err := ioutil.WriteFile(file1, nil, 0666)
   138  						Expect(err).ToNot(HaveOccurred())
   139  
   140  						file2 := filepath.Join(appDir, "file2")
   141  						err = ioutil.WriteFile(file2, nil, 0666)
   142  						Expect(err).ToNot(HaveOccurred())
   143  
   144  						cfIgnoreFilePath := filepath.Join(appDir, ".cfignore")
   145  						err = ioutil.WriteFile(cfIgnoreFilePath, []byte("file*"), 0666)
   146  						Expect(err).ToNot(HaveOccurred())
   147  
   148  						tmpfile, err := ioutil.TempFile("", "push-archive-integration")
   149  						Expect(err).ToNot(HaveOccurred())
   150  						archive = tmpfile.Name()
   151  						Expect(tmpfile.Close())
   152  
   153  						err = helpers.Zipit(appDir, archive, "")
   154  						Expect(err).ToNot(HaveOccurred())
   155  					})
   156  				})
   157  
   158  				AfterEach(func() {
   159  					Expect(os.RemoveAll(archive)).ToNot(HaveOccurred())
   160  				})
   161  
   162  				It("does not push those files", func() {
   163  					session := helpers.CF("v3-push", appName, "-p", archive)
   164  
   165  					Eventually(session).Should(Exit(0))
   166  					helpers.VerifyAppPackageContents(appName, "Staticfile", "index.html")
   167  				})
   168  			})
   169  		})
   170  
   171  		Context("when the CF_TRACE file is in the app source directory", func() {
   172  			var previousEnv string
   173  
   174  			AfterEach(func() {
   175  				err := os.Setenv("CF_TRACE", previousEnv)
   176  				Expect(err).ToNot(HaveOccurred())
   177  			})
   178  
   179  			It("does not push it", func() {
   180  				helpers.WithHelloWorldApp(func(appDir string) {
   181  					traceFilePath := filepath.Join(appDir, "i-am-trace.txt")
   182  					err := ioutil.WriteFile(traceFilePath, nil, 0666)
   183  					Expect(err).ToNot(HaveOccurred())
   184  
   185  					previousEnv = os.Getenv("CF_TRACE")
   186  					err = os.Setenv("CF_TRACE", traceFilePath)
   187  					Expect(err).ToNot(HaveOccurred())
   188  
   189  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName)
   190  					Eventually(session).Should(Exit(0))
   191  					helpers.VerifyAppPackageContents(appName, "Staticfile", "index.html")
   192  				})
   193  			})
   194  		})
   195  	})
   196  
   197  	Context("when .cfignore file does not exists", func() {
   198  		It("pushes all the files except for the files ignored by default", func() {
   199  			helpers.WithHelloWorldApp(func(appDir string) {
   200  				file1 := filepath.Join(appDir, "file1")
   201  				err := ioutil.WriteFile(file1, nil, 0666)
   202  				Expect(err).ToNot(HaveOccurred())
   203  
   204  				file2 := filepath.Join(appDir, "file2")
   205  				err = ioutil.WriteFile(file2, nil, 0666)
   206  				Expect(err).ToNot(HaveOccurred())
   207  
   208  				darcsFile := filepath.Join(appDir, "_darcs")
   209  				err = ioutil.WriteFile(darcsFile, nil, 0666)
   210  				Expect(err).ToNot(HaveOccurred())
   211  
   212  				dsFile := filepath.Join(appDir, ".DS_Store")
   213  				err = ioutil.WriteFile(dsFile, nil, 0666)
   214  				Expect(err).ToNot(HaveOccurred())
   215  
   216  				gitFile := filepath.Join(appDir, ".git")
   217  				err = ioutil.WriteFile(gitFile, nil, 0666)
   218  				Expect(err).ToNot(HaveOccurred())
   219  
   220  				gitIgnoreFile := filepath.Join(appDir, ".gitignore")
   221  				err = ioutil.WriteFile(gitIgnoreFile, nil, 0666)
   222  				Expect(err).ToNot(HaveOccurred())
   223  
   224  				hgFile := filepath.Join(appDir, ".hg")
   225  				err = ioutil.WriteFile(hgFile, nil, 0666)
   226  				Expect(err).ToNot(HaveOccurred())
   227  
   228  				manifestFile := filepath.Join(appDir, "manifest.yml")
   229  				err = ioutil.WriteFile(manifestFile, nil, 0666)
   230  				Expect(err).ToNot(HaveOccurred())
   231  
   232  				svnFile := filepath.Join(appDir, ".svn")
   233  				err = ioutil.WriteFile(svnFile, nil, 0666)
   234  				Expect(err).ToNot(HaveOccurred())
   235  
   236  				session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName)
   237  
   238  				Eventually(session).Should(Exit(0))
   239  				helpers.VerifyAppPackageContents(appName, "file1", "file2", "Staticfile", "index.html")
   240  			})
   241  		})
   242  	})
   243  })