github.com/sleungcy-sap/cli@v7.1.0+incompatible/integration/v7/isolated/create_package_cfignore_test.go (about)

     1  package isolated
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"path/filepath"
     7  
     8  	"code.cloudfoundry.org/cli/integration/helpers"
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  	. "github.com/onsi/gomega/gexec"
    12  )
    13  
    14  var _ = Describe("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  		helpers.SetupCF(orgName, spaceName)
    26  
    27  	})
    28  
    29  	AfterEach(func() {
    30  		helpers.QuickDeleteOrg(orgName)
    31  	})
    32  
    33  	When(".cfignore file exists", func() {
    34  		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}, "create-app", appName)).Should(Exit(0))
    78  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "create-package", appName)
    79  
    80  					Eventually(session).Should(Exit(0))
    81  					helpers.VerifyAppPackageContentsV3(appName, "file1", "file2", "Staticfile", "index.html")
    82  				})
    83  			})
    84  		})
    85  
    86  		When("the .cfignore file excludes some files", func() {
    87  			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}, "create-app", appName)).Should(Exit(0))
   103  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "create-package", appName)
   104  
   105  						Eventually(session).Should(Exit(0))
   106  						helpers.VerifyAppPackageContentsV3(appName, "Staticfile", "index.html")
   107  					})
   108  				})
   109  			})
   110  
   111  			When("pushing from a different directory", func() {
   112  				It("does not push those files", func() {
   113  					helpers.WithHelloWorldApp(func(appDir string) {
   114  						file1 := filepath.Join(appDir, "file1")
   115  						err := ioutil.WriteFile(file1, nil, 0666)
   116  						Expect(err).ToNot(HaveOccurred())
   117  
   118  						file2 := filepath.Join(appDir, "file2")
   119  						err = ioutil.WriteFile(file2, nil, 0666)
   120  						Expect(err).ToNot(HaveOccurred())
   121  
   122  						cfIgnoreFilePath := filepath.Join(appDir, ".cfignore")
   123  						err = ioutil.WriteFile(cfIgnoreFilePath, []byte("file*"), 0666)
   124  						Expect(err).ToNot(HaveOccurred())
   125  
   126  						Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "create-app", appName)).Should(Exit(0))
   127  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "create-package", appName, "-p", appDir)
   128  
   129  						Eventually(session).Should(Exit(0))
   130  						helpers.VerifyAppPackageContentsV3(appName, "Staticfile", "index.html")
   131  					})
   132  				})
   133  			})
   134  
   135  			When("pushing a zip file", func() {
   136  				var archive string
   137  				BeforeEach(func() {
   138  					helpers.WithHelloWorldApp(func(appDir string) {
   139  						file1 := filepath.Join(appDir, "file1")
   140  						err := ioutil.WriteFile(file1, nil, 0666)
   141  						Expect(err).ToNot(HaveOccurred())
   142  
   143  						file2 := filepath.Join(appDir, "file2")
   144  						err = ioutil.WriteFile(file2, nil, 0666)
   145  						Expect(err).ToNot(HaveOccurred())
   146  
   147  						cfIgnoreFilePath := filepath.Join(appDir, ".cfignore")
   148  						err = ioutil.WriteFile(cfIgnoreFilePath, []byte("file*"), 0666)
   149  						Expect(err).ToNot(HaveOccurred())
   150  
   151  						tmpfile, err := ioutil.TempFile("", "push-archive-integration")
   152  						Expect(err).ToNot(HaveOccurred())
   153  						archive = tmpfile.Name()
   154  						Expect(tmpfile.Close())
   155  
   156  						err = helpers.Zipit(appDir, archive, "")
   157  						Expect(err).ToNot(HaveOccurred())
   158  					})
   159  				})
   160  
   161  				AfterEach(func() {
   162  					Expect(os.RemoveAll(archive)).ToNot(HaveOccurred())
   163  				})
   164  
   165  				It("does not push those files", func() {
   166  					Eventually(helpers.CF("create-app", appName)).Should(Exit(0))
   167  					session := helpers.CF("create-package", appName, "-p", archive)
   168  
   169  					Eventually(session).Should(Exit(0))
   170  					helpers.VerifyAppPackageContentsV3(appName, "Staticfile", "index.html")
   171  				})
   172  			})
   173  		})
   174  
   175  		When("the CF_TRACE file is in the app source directory", func() {
   176  			var previousEnv string
   177  
   178  			AfterEach(func() {
   179  				err := os.Setenv("CF_TRACE", previousEnv)
   180  				Expect(err).ToNot(HaveOccurred())
   181  			})
   182  
   183  			It("does not push it", func() {
   184  				helpers.WithHelloWorldApp(func(appDir string) {
   185  					traceFilePath := filepath.Join(appDir, "i-am-trace.txt")
   186  					err := ioutil.WriteFile(traceFilePath, nil, 0666)
   187  					Expect(err).ToNot(HaveOccurred())
   188  
   189  					previousEnv = os.Getenv("CF_TRACE")
   190  					err = os.Setenv("CF_TRACE", traceFilePath)
   191  					Expect(err).ToNot(HaveOccurred())
   192  
   193  					Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "create-app", appName)).Should(Exit(0))
   194  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "create-package", appName)
   195  					Eventually(session).Should(Exit(0))
   196  					helpers.VerifyAppPackageContentsV3(appName, "Staticfile", "index.html")
   197  				})
   198  			})
   199  		})
   200  	})
   201  
   202  	When(".cfignore file does not exist", func() {
   203  		It("pushes all the files except for the files ignored by default", func() {
   204  			helpers.WithHelloWorldApp(func(appDir string) {
   205  				file1 := filepath.Join(appDir, "file1")
   206  				err := ioutil.WriteFile(file1, nil, 0666)
   207  				Expect(err).ToNot(HaveOccurred())
   208  
   209  				file2 := filepath.Join(appDir, "file2")
   210  				err = ioutil.WriteFile(file2, nil, 0666)
   211  				Expect(err).ToNot(HaveOccurred())
   212  
   213  				darcsFile := filepath.Join(appDir, "_darcs")
   214  				err = ioutil.WriteFile(darcsFile, nil, 0666)
   215  				Expect(err).ToNot(HaveOccurred())
   216  
   217  				dsFile := filepath.Join(appDir, ".DS_Store")
   218  				err = ioutil.WriteFile(dsFile, nil, 0666)
   219  				Expect(err).ToNot(HaveOccurred())
   220  
   221  				gitFile := filepath.Join(appDir, ".git")
   222  				err = ioutil.WriteFile(gitFile, nil, 0666)
   223  				Expect(err).ToNot(HaveOccurred())
   224  
   225  				gitIgnoreFile := filepath.Join(appDir, ".gitignore")
   226  				err = ioutil.WriteFile(gitIgnoreFile, nil, 0666)
   227  				Expect(err).ToNot(HaveOccurred())
   228  
   229  				hgFile := filepath.Join(appDir, ".hg")
   230  				err = ioutil.WriteFile(hgFile, nil, 0666)
   231  				Expect(err).ToNot(HaveOccurred())
   232  
   233  				manifestFile := filepath.Join(appDir, "manifest.yml")
   234  				err = ioutil.WriteFile(manifestFile, nil, 0666)
   235  				Expect(err).ToNot(HaveOccurred())
   236  
   237  				svnFile := filepath.Join(appDir, ".svn")
   238  				err = ioutil.WriteFile(svnFile, nil, 0666)
   239  				Expect(err).ToNot(HaveOccurred())
   240  
   241  				Eventually(helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "create-app", appName)).Should(Exit(0))
   242  				session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "create-package", appName)
   243  
   244  				Eventually(session).Should(Exit(0))
   245  				helpers.VerifyAppPackageContentsV3(appName, "file1", "file2", "Staticfile", "index.html")
   246  			})
   247  		})
   248  	})
   249  })