github.com/liamawhite/cli-with-i18n@v6.32.1-0.20171122084555-dede0a5c3448+incompatible/integration/experimental/v3_create_package_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-create-package 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 and files ignored by default", 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  					Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-create-app", appName)).Should(Exit(0))
    78  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-create-package", appName)
    79  
    80  					Eventually(session).Should(Exit(0))
    81  					helpers.VerifyAppPackageContents(appName, "file1", "file2", "Staticfile", "index.html")
    82  				})
    83  			})
    84  		})
    85  
    86  		Context("when the .cfignore file excludes some files", func() {
    87  			Context("when pushing from the current directory", func() {
    88  				It("does not push those files", func() {
    89  					helpers.WithHelloWorldApp(func(appDir string) {
    90  						file1 := filepath.Join(appDir, "file1")
    91  						err := ioutil.WriteFile(file1, nil, 0666)
    92  						Expect(err).ToNot(HaveOccurred())
    93  
    94  						file2 := filepath.Join(appDir, "file2")
    95  						err = ioutil.WriteFile(file2, nil, 0666)
    96  						Expect(err).ToNot(HaveOccurred())
    97  
    98  						cfIgnoreFilePath := filepath.Join(appDir, ".cfignore")
    99  						err = ioutil.WriteFile(cfIgnoreFilePath, []byte("file*"), 0666)
   100  						Expect(err).ToNot(HaveOccurred())
   101  
   102  						Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-create-app", appName)).Should(Exit(0))
   103  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-create-package", appName)
   104  
   105  						Eventually(session).Should(Exit(0))
   106  						helpers.VerifyAppPackageContents(appName, "Staticfile", "index.html")
   107  					})
   108  				})
   109  			})
   110  		})
   111  
   112  		Context("when the CF_TRACE file is in the app source directory", func() {
   113  			var previousEnv string
   114  
   115  			AfterEach(func() {
   116  				err := os.Setenv("CF_TRACE", previousEnv)
   117  				Expect(err).ToNot(HaveOccurred())
   118  			})
   119  
   120  			It("does not push it", func() {
   121  				helpers.WithHelloWorldApp(func(appDir string) {
   122  					traceFilePath := filepath.Join(appDir, "i-am-trace.txt")
   123  					err := ioutil.WriteFile(traceFilePath, nil, 0666)
   124  					Expect(err).ToNot(HaveOccurred())
   125  
   126  					previousEnv = os.Getenv("CF_TRACE")
   127  					err = os.Setenv("CF_TRACE", traceFilePath)
   128  					Expect(err).ToNot(HaveOccurred())
   129  
   130  					Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-create-app", appName)).Should(Exit(0))
   131  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-create-package", appName)
   132  					Eventually(session).Should(Exit(0))
   133  					helpers.VerifyAppPackageContents(appName, "Staticfile", "index.html")
   134  				})
   135  			})
   136  		})
   137  	})
   138  
   139  	Context("when .cfignore file does not exist", func() {
   140  		It("pushes all the files except for the files ignored by default", func() {
   141  			helpers.WithHelloWorldApp(func(appDir string) {
   142  				file1 := filepath.Join(appDir, "file1")
   143  				err := ioutil.WriteFile(file1, nil, 0666)
   144  				Expect(err).ToNot(HaveOccurred())
   145  
   146  				file2 := filepath.Join(appDir, "file2")
   147  				err = ioutil.WriteFile(file2, nil, 0666)
   148  				Expect(err).ToNot(HaveOccurred())
   149  
   150  				darcsFile := filepath.Join(appDir, "_darcs")
   151  				err = ioutil.WriteFile(darcsFile, nil, 0666)
   152  				Expect(err).ToNot(HaveOccurred())
   153  
   154  				dsFile := filepath.Join(appDir, ".DS_Store")
   155  				err = ioutil.WriteFile(dsFile, nil, 0666)
   156  				Expect(err).ToNot(HaveOccurred())
   157  
   158  				gitFile := filepath.Join(appDir, ".git")
   159  				err = ioutil.WriteFile(gitFile, nil, 0666)
   160  				Expect(err).ToNot(HaveOccurred())
   161  
   162  				gitIgnoreFile := filepath.Join(appDir, ".gitignore")
   163  				err = ioutil.WriteFile(gitIgnoreFile, nil, 0666)
   164  				Expect(err).ToNot(HaveOccurred())
   165  
   166  				hgFile := filepath.Join(appDir, ".hg")
   167  				err = ioutil.WriteFile(hgFile, nil, 0666)
   168  				Expect(err).ToNot(HaveOccurred())
   169  
   170  				manifestFile := filepath.Join(appDir, "manifest.yml")
   171  				err = ioutil.WriteFile(manifestFile, nil, 0666)
   172  				Expect(err).ToNot(HaveOccurred())
   173  
   174  				svnFile := filepath.Join(appDir, ".svn")
   175  				err = ioutil.WriteFile(svnFile, nil, 0666)
   176  				Expect(err).ToNot(HaveOccurred())
   177  
   178  				Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-create-app", appName)).Should(Exit(0))
   179  				session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-create-package", appName)
   180  
   181  				Eventually(session).Should(Exit(0))
   182  				helpers.VerifyAppPackageContents(appName, "file1", "file2", "Staticfile", "index.html")
   183  			})
   184  		})
   185  	})
   186  })