github.com/wanddynosios/cli@v7.1.0+incompatible/integration/v6/push/ignore_app_files_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  
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  	. "github.com/onsi/gomega/gbytes"
    13  	. "github.com/onsi/gomega/gexec"
    14  )
    15  
    16  var _ = Describe("ignoring files while gathering resources", func() {
    17  	var (
    18  		firstApp string
    19  	)
    20  
    21  	BeforeEach(func() {
    22  		firstApp = helpers.NewAppName()
    23  	})
    24  
    25  	When("the .cfignore file is in the app source directory", func() {
    26  		When("the .cfignore file doesn't exclude any files", func() {
    27  			It("pushes all the files", func() {
    28  				helpers.WithHelloWorldApp(func(dir string) {
    29  					file1 := filepath.Join(dir, "file1")
    30  					err := ioutil.WriteFile(file1, nil, 0666)
    31  					Expect(err).ToNot(HaveOccurred())
    32  
    33  					file2 := filepath.Join(dir, "file2")
    34  					err = ioutil.WriteFile(file2, nil, 0666)
    35  					Expect(err).ToNot(HaveOccurred())
    36  
    37  					cfIgnoreFilePath := filepath.Join(dir, ".cfignore")
    38  					err = ioutil.WriteFile(cfIgnoreFilePath, nil, 0666)
    39  					Expect(err).ToNot(HaveOccurred())
    40  
    41  					session := helpers.DebugCustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, firstApp, "--no-start")
    42  
    43  					Eventually(session.Err).Should(Say("zipped_file_count=4"))
    44  					Eventually(session).Should(Exit(0))
    45  				})
    46  			})
    47  		})
    48  
    49  		When("the .cfignore file excludes some files", func() {
    50  			Context("ignored files are relative paths", func() {
    51  				It("does not push those files", func() {
    52  					helpers.WithHelloWorldApp(func(dir string) {
    53  						file1 := filepath.Join(dir, "file1")
    54  						err := ioutil.WriteFile(file1, nil, 0666)
    55  						Expect(err).ToNot(HaveOccurred())
    56  
    57  						file2 := filepath.Join(dir, "file2")
    58  						err = ioutil.WriteFile(file2, nil, 0666)
    59  						Expect(err).ToNot(HaveOccurred())
    60  
    61  						cfIgnoreFilePath := filepath.Join(dir, ".cfignore")
    62  						err = ioutil.WriteFile(cfIgnoreFilePath, []byte("file*"), 0666)
    63  						Expect(err).ToNot(HaveOccurred())
    64  
    65  						session := helpers.DebugCustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, firstApp, "--no-start")
    66  
    67  						Eventually(session.Err).Should(Say("zipped_file_count=2"))
    68  						Eventually(session).Should(Exit(0))
    69  					})
    70  				})
    71  			})
    72  
    73  			Context("with absolute paths - where '/' == appDir", func() {
    74  				It("does not push those files", func() {
    75  					helpers.WithHelloWorldApp(func(dir string) {
    76  						file1 := filepath.Join(dir, "file1")
    77  						err := ioutil.WriteFile(file1, nil, 0666)
    78  						Expect(err).ToNot(HaveOccurred())
    79  
    80  						file2 := filepath.Join(dir, "file2")
    81  						err = ioutil.WriteFile(file2, nil, 0666)
    82  						Expect(err).ToNot(HaveOccurred())
    83  
    84  						cfIgnoreFilePath := filepath.Join(dir, ".cfignore")
    85  						err = ioutil.WriteFile(cfIgnoreFilePath, []byte("/file*"), 0666)
    86  						Expect(err).ToNot(HaveOccurred())
    87  
    88  						session := helpers.DebugCustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, firstApp, "--no-start")
    89  
    90  						Eventually(session.Err).Should(Say("zipped_file_count=2"))
    91  						Eventually(session).Should(Exit(0))
    92  					})
    93  				})
    94  			})
    95  		})
    96  	})
    97  
    98  	When("the CF_TRACE file is in the app source directory", func() {
    99  		var previousEnv string
   100  
   101  		AfterEach(func() {
   102  			err := os.Setenv("CF_TRACE", previousEnv)
   103  			Expect(err).ToNot(HaveOccurred())
   104  		})
   105  
   106  		It("does not push it", func() {
   107  			helpers.WithHelloWorldApp(func(dir string) {
   108  				traceFilePath := filepath.Join(dir, "i-am-trace.txt")
   109  				err := ioutil.WriteFile(traceFilePath, nil, 0666)
   110  				Expect(err).ToNot(HaveOccurred())
   111  
   112  				previousEnv = os.Getenv("CF_TRACE")
   113  				err = os.Setenv("CF_TRACE", traceFilePath)
   114  				Expect(err).ToNot(HaveOccurred())
   115  
   116  				session := helpers.DebugCustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, firstApp, "--no-start")
   117  
   118  				Eventually(session.Err).Should(Say("zipped_file_count=2"))
   119  				Eventually(session).Should(Exit(0))
   120  			})
   121  		})
   122  	})
   123  })