github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/integration/v7/push/cfignore_test.go (about) 1 package push 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("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 helpers.WriteManifest(manifestFile, map[string]interface{}{ 72 "applications": []map[string]interface{}{ 73 { 74 "name": appName, 75 }, 76 }, 77 }, 78 ) 79 80 svnFile := filepath.Join(appDir, ".svn") 81 err = ioutil.WriteFile(svnFile, nil, 0666) 82 Expect(err).ToNot(HaveOccurred()) 83 84 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "push", appName) 85 86 Eventually(session).Should(Exit(0)) 87 helpers.VerifyAppPackageContentsV3(appName, "file1", "file2", "Staticfile", "index.html") 88 }) 89 }) 90 }) 91 92 When("the .cfignore file excludes some files", func() { 93 When("pushing from the current directory", func() { 94 It("does not push those files", func() { 95 helpers.WithHelloWorldApp(func(appDir string) { 96 file1 := filepath.Join(appDir, "file1") 97 err := ioutil.WriteFile(file1, nil, 0666) 98 Expect(err).ToNot(HaveOccurred()) 99 100 file2 := filepath.Join(appDir, "file2") 101 err = ioutil.WriteFile(file2, nil, 0666) 102 Expect(err).ToNot(HaveOccurred()) 103 104 cfIgnoreFilePath := filepath.Join(appDir, ".cfignore") 105 err = ioutil.WriteFile(cfIgnoreFilePath, []byte("file*"), 0666) 106 Expect(err).ToNot(HaveOccurred()) 107 108 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "push", appName) 109 110 Eventually(session).Should(Exit(0)) 111 helpers.VerifyAppPackageContentsV3(appName, "Staticfile", "index.html") 112 }) 113 }) 114 }) 115 116 When("pushing from a different directory", func() { 117 It("does not push those files", func() { 118 helpers.WithHelloWorldApp(func(appDir string) { 119 file1 := filepath.Join(appDir, "file1") 120 err := ioutil.WriteFile(file1, nil, 0666) 121 Expect(err).ToNot(HaveOccurred()) 122 123 file2 := filepath.Join(appDir, "file2") 124 err = ioutil.WriteFile(file2, nil, 0666) 125 Expect(err).ToNot(HaveOccurred()) 126 127 cfIgnoreFilePath := filepath.Join(appDir, ".cfignore") 128 err = ioutil.WriteFile(cfIgnoreFilePath, []byte("file*"), 0666) 129 Expect(err).ToNot(HaveOccurred()) 130 131 session := helpers.CF("push", appName, "-p", appDir) 132 133 Eventually(session).Should(Exit(0)) 134 helpers.VerifyAppPackageContentsV3(appName, "Staticfile", "index.html") 135 }) 136 }) 137 }) 138 139 When("pushing a zip file", func() { 140 var archive string 141 BeforeEach(func() { 142 helpers.WithHelloWorldApp(func(appDir string) { 143 file1 := filepath.Join(appDir, "file1") 144 err := ioutil.WriteFile(file1, nil, 0666) 145 Expect(err).ToNot(HaveOccurred()) 146 147 file2 := filepath.Join(appDir, "file2") 148 err = ioutil.WriteFile(file2, nil, 0666) 149 Expect(err).ToNot(HaveOccurred()) 150 151 cfIgnoreFilePath := filepath.Join(appDir, ".cfignore") 152 err = ioutil.WriteFile(cfIgnoreFilePath, []byte("file*"), 0666) 153 Expect(err).ToNot(HaveOccurred()) 154 155 tmpfile, err := ioutil.TempFile("", "push-archive-integration") 156 Expect(err).ToNot(HaveOccurred()) 157 archive = tmpfile.Name() 158 Expect(tmpfile.Close()) 159 160 err = helpers.Zipit(appDir, archive, "") 161 Expect(err).ToNot(HaveOccurred()) 162 }) 163 }) 164 165 AfterEach(func() { 166 Expect(os.RemoveAll(archive)).ToNot(HaveOccurred()) 167 }) 168 169 It("does not push those files", func() { 170 session := helpers.CF("push", appName, "-p", archive) 171 172 Eventually(session).Should(Exit(0)) 173 helpers.VerifyAppPackageContentsV3(appName, "Staticfile", "index.html") 174 }) 175 }) 176 }) 177 178 When("the CF_TRACE file is in the app source directory", func() { 179 var previousEnv string 180 181 AfterEach(func() { 182 err := os.Setenv("CF_TRACE", previousEnv) 183 Expect(err).ToNot(HaveOccurred()) 184 }) 185 186 It("does not push it", func() { 187 helpers.WithHelloWorldApp(func(appDir string) { 188 traceFilePath := filepath.Join(appDir, "i-am-trace.txt") 189 err := ioutil.WriteFile(traceFilePath, nil, 0666) 190 Expect(err).ToNot(HaveOccurred()) 191 192 previousEnv = os.Getenv("CF_TRACE") 193 err = os.Setenv("CF_TRACE", traceFilePath) 194 Expect(err).ToNot(HaveOccurred()) 195 196 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "push", appName) 197 Eventually(session).Should(Exit(0)) 198 helpers.VerifyAppPackageContentsV3(appName, "Staticfile", "index.html") 199 }) 200 }) 201 }) 202 }) 203 204 When(".cfignore file does not exists", func() { 205 It("pushes all the files except for the files ignored by default", func() { 206 helpers.WithHelloWorldApp(func(appDir string) { 207 file1 := filepath.Join(appDir, "file1") 208 err := ioutil.WriteFile(file1, nil, 0666) 209 Expect(err).ToNot(HaveOccurred()) 210 211 file2 := filepath.Join(appDir, "file2") 212 err = ioutil.WriteFile(file2, nil, 0666) 213 Expect(err).ToNot(HaveOccurred()) 214 215 darcsFile := filepath.Join(appDir, "_darcs") 216 err = ioutil.WriteFile(darcsFile, nil, 0666) 217 Expect(err).ToNot(HaveOccurred()) 218 219 dsFile := filepath.Join(appDir, ".DS_Store") 220 err = ioutil.WriteFile(dsFile, nil, 0666) 221 Expect(err).ToNot(HaveOccurred()) 222 223 gitFile := filepath.Join(appDir, ".git") 224 err = ioutil.WriteFile(gitFile, nil, 0666) 225 Expect(err).ToNot(HaveOccurred()) 226 227 gitIgnoreFile := filepath.Join(appDir, ".gitignore") 228 err = ioutil.WriteFile(gitIgnoreFile, nil, 0666) 229 Expect(err).ToNot(HaveOccurred()) 230 231 hgFile := filepath.Join(appDir, ".hg") 232 err = ioutil.WriteFile(hgFile, nil, 0666) 233 Expect(err).ToNot(HaveOccurred()) 234 235 manifestFile := filepath.Join(appDir, "manifest.yml") 236 helpers.WriteManifest(manifestFile, map[string]interface{}{ 237 "applications": []map[string]interface{}{ 238 { 239 "name": appName, 240 }, 241 }, 242 }, 243 ) 244 245 svnFile := filepath.Join(appDir, ".svn") 246 err = ioutil.WriteFile(svnFile, nil, 0666) 247 Expect(err).ToNot(HaveOccurred()) 248 249 session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: appDir}, "push", appName) 250 251 Eventually(session).Should(Exit(0)) 252 helpers.VerifyAppPackageContentsV3(appName, "file1", "file2", "Staticfile", "index.html") 253 }) 254 }) 255 }) 256 })