github.com/randomtask1155/cli@v6.41.1-0.20181227003417-a98eed78cbde+incompatible/integration/shared/experimental/v3_push_cfignore_test.go (about)

     1  package experimental
     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("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  		helpers.SetupCF(orgName, spaceName)
    26  		helpers.TurnOffExperimental()
    27  	})
    28  
    29  	AfterEach(func() {
    30  		helpers.TurnOnExperimental()
    31  		helpers.QuickDeleteOrg(orgName)
    32  	})
    33  
    34  	When(".cfignore file exists", func() {
    35  		When("the .cfignore file doesn't exclude any files", func() {
    36  			It("pushes all the files except .cfignore", func() {
    37  				helpers.WithHelloWorldApp(func(appDir string) {
    38  					file1 := filepath.Join(appDir, "file1")
    39  					err := ioutil.WriteFile(file1, nil, 0666)
    40  					Expect(err).ToNot(HaveOccurred())
    41  
    42  					file2 := filepath.Join(appDir, "file2")
    43  					err = ioutil.WriteFile(file2, nil, 0666)
    44  					Expect(err).ToNot(HaveOccurred())
    45  
    46  					cfIgnoreFilePath := filepath.Join(appDir, ".cfignore")
    47  					err = ioutil.WriteFile(cfIgnoreFilePath, nil, 0666)
    48  					Expect(err).ToNot(HaveOccurred())
    49  
    50  					darcsFile := filepath.Join(appDir, "_darcs")
    51  					err = ioutil.WriteFile(darcsFile, nil, 0666)
    52  					Expect(err).ToNot(HaveOccurred())
    53  
    54  					dsFile := filepath.Join(appDir, ".DS_Store")
    55  					err = ioutil.WriteFile(dsFile, nil, 0666)
    56  					Expect(err).ToNot(HaveOccurred())
    57  
    58  					gitFile := filepath.Join(appDir, ".git")
    59  					err = ioutil.WriteFile(gitFile, nil, 0666)
    60  					Expect(err).ToNot(HaveOccurred())
    61  
    62  					gitIgnoreFile := filepath.Join(appDir, ".gitignore")
    63  					err = ioutil.WriteFile(gitIgnoreFile, nil, 0666)
    64  					Expect(err).ToNot(HaveOccurred())
    65  
    66  					hgFile := filepath.Join(appDir, ".hg")
    67  					err = ioutil.WriteFile(hgFile, nil, 0666)
    68  					Expect(err).ToNot(HaveOccurred())
    69  
    70  					manifestFile := filepath.Join(appDir, "manifest.yml")
    71  					err = ioutil.WriteFile(manifestFile, nil, 0666)
    72  					Expect(err).ToNot(HaveOccurred())
    73  
    74  					svnFile := filepath.Join(appDir, ".svn")
    75  					err = ioutil.WriteFile(svnFile, nil, 0666)
    76  					Expect(err).ToNot(HaveOccurred())
    77  
    78  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", 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  						session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName)
   103  
   104  						Eventually(session).Should(Exit(0))
   105  						helpers.VerifyAppPackageContentsV3(appName, "Staticfile", "index.html")
   106  					})
   107  				})
   108  			})
   109  
   110  			When("pushing from a different directory", func() {
   111  				It("does not push those files", func() {
   112  					helpers.WithHelloWorldApp(func(appDir string) {
   113  						file1 := filepath.Join(appDir, "file1")
   114  						err := ioutil.WriteFile(file1, nil, 0666)
   115  						Expect(err).ToNot(HaveOccurred())
   116  
   117  						file2 := filepath.Join(appDir, "file2")
   118  						err = ioutil.WriteFile(file2, nil, 0666)
   119  						Expect(err).ToNot(HaveOccurred())
   120  
   121  						cfIgnoreFilePath := filepath.Join(appDir, ".cfignore")
   122  						err = ioutil.WriteFile(cfIgnoreFilePath, []byte("file*"), 0666)
   123  						Expect(err).ToNot(HaveOccurred())
   124  
   125  						session := helpers.CF("v3-push", appName, "-p", appDir)
   126  
   127  						Eventually(session).Should(Exit(0))
   128  						helpers.VerifyAppPackageContentsV3(appName, "Staticfile", "index.html")
   129  					})
   130  				})
   131  			})
   132  
   133  			When("pushing a zip file", func() {
   134  				var archive string
   135  				BeforeEach(func() {
   136  					helpers.WithHelloWorldApp(func(appDir string) {
   137  						file1 := filepath.Join(appDir, "file1")
   138  						err := ioutil.WriteFile(file1, nil, 0666)
   139  						Expect(err).ToNot(HaveOccurred())
   140  
   141  						file2 := filepath.Join(appDir, "file2")
   142  						err = ioutil.WriteFile(file2, nil, 0666)
   143  						Expect(err).ToNot(HaveOccurred())
   144  
   145  						cfIgnoreFilePath := filepath.Join(appDir, ".cfignore")
   146  						err = ioutil.WriteFile(cfIgnoreFilePath, []byte("file*"), 0666)
   147  						Expect(err).ToNot(HaveOccurred())
   148  
   149  						tmpfile, err := ioutil.TempFile("", "push-archive-integration")
   150  						Expect(err).ToNot(HaveOccurred())
   151  						archive = tmpfile.Name()
   152  						Expect(tmpfile.Close())
   153  
   154  						err = helpers.Zipit(appDir, archive, "")
   155  						Expect(err).ToNot(HaveOccurred())
   156  					})
   157  				})
   158  
   159  				AfterEach(func() {
   160  					Expect(os.RemoveAll(archive)).ToNot(HaveOccurred())
   161  				})
   162  
   163  				It("does not push those files", func() {
   164  					session := helpers.CF("v3-push", appName, "-p", archive)
   165  
   166  					Eventually(session).Should(Exit(0))
   167  					helpers.VerifyAppPackageContentsV3(appName, "Staticfile", "index.html")
   168  				})
   169  			})
   170  		})
   171  
   172  		When("the CF_TRACE file is in the app source directory", func() {
   173  			var previousEnv string
   174  
   175  			AfterEach(func() {
   176  				err := os.Setenv("CF_TRACE", previousEnv)
   177  				Expect(err).ToNot(HaveOccurred())
   178  			})
   179  
   180  			It("does not push it", func() {
   181  				helpers.WithHelloWorldApp(func(appDir string) {
   182  					traceFilePath := filepath.Join(appDir, "i-am-trace.txt")
   183  					err := ioutil.WriteFile(traceFilePath, nil, 0666)
   184  					Expect(err).ToNot(HaveOccurred())
   185  
   186  					previousEnv = os.Getenv("CF_TRACE")
   187  					err = os.Setenv("CF_TRACE", traceFilePath)
   188  					Expect(err).ToNot(HaveOccurred())
   189  
   190  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName)
   191  					Eventually(session).Should(Exit(0))
   192  					helpers.VerifyAppPackageContentsV3(appName, "Staticfile", "index.html")
   193  				})
   194  			})
   195  		})
   196  	})
   197  
   198  	When(".cfignore file does not exists", func() {
   199  		It("pushes all the files except for the files ignored by default", func() {
   200  			helpers.WithHelloWorldApp(func(appDir string) {
   201  				file1 := filepath.Join(appDir, "file1")
   202  				err := ioutil.WriteFile(file1, nil, 0666)
   203  				Expect(err).ToNot(HaveOccurred())
   204  
   205  				file2 := filepath.Join(appDir, "file2")
   206  				err = ioutil.WriteFile(file2, nil, 0666)
   207  				Expect(err).ToNot(HaveOccurred())
   208  
   209  				darcsFile := filepath.Join(appDir, "_darcs")
   210  				err = ioutil.WriteFile(darcsFile, nil, 0666)
   211  				Expect(err).ToNot(HaveOccurred())
   212  
   213  				dsFile := filepath.Join(appDir, ".DS_Store")
   214  				err = ioutil.WriteFile(dsFile, nil, 0666)
   215  				Expect(err).ToNot(HaveOccurred())
   216  
   217  				gitFile := filepath.Join(appDir, ".git")
   218  				err = ioutil.WriteFile(gitFile, nil, 0666)
   219  				Expect(err).ToNot(HaveOccurred())
   220  
   221  				gitIgnoreFile := filepath.Join(appDir, ".gitignore")
   222  				err = ioutil.WriteFile(gitIgnoreFile, nil, 0666)
   223  				Expect(err).ToNot(HaveOccurred())
   224  
   225  				hgFile := filepath.Join(appDir, ".hg")
   226  				err = ioutil.WriteFile(hgFile, nil, 0666)
   227  				Expect(err).ToNot(HaveOccurred())
   228  
   229  				manifestFile := filepath.Join(appDir, "manifest.yml")
   230  				err = ioutil.WriteFile(manifestFile, nil, 0666)
   231  				Expect(err).ToNot(HaveOccurred())
   232  
   233  				svnFile := filepath.Join(appDir, ".svn")
   234  				err = ioutil.WriteFile(svnFile, nil, 0666)
   235  				Expect(err).ToNot(HaveOccurred())
   236  
   237  				session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "v3-push", appName)
   238  
   239  				Eventually(session).Should(Exit(0))
   240  				helpers.VerifyAppPackageContentsV3(appName, "file1", "file2", "Staticfile", "index.html")
   241  			})
   242  		})
   243  	})
   244  })