github.com/cloudfoundry-attic/cli-with-i18n@v6.32.1-0.20171002233121-7401370d3b85+incompatible/integration/push/files_push_ignores_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  	Context("when the .cfignore file is in the app source directory", func() {
    26  		Context("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.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, firstApp)
    42  
    43  					Eventually(session).Should(Say("50[0-9] B / 50[0-9] B"))
    44  					Eventually(session).Should(Exit(0))
    45  				})
    46  			})
    47  		})
    48  
    49  		Context("when the .cfignore file excludes some files", func() {
    50  			It("does not push those files", func() {
    51  				helpers.WithHelloWorldApp(func(dir string) {
    52  					file1 := filepath.Join(dir, "file1")
    53  					err := ioutil.WriteFile(file1, nil, 0666)
    54  					Expect(err).ToNot(HaveOccurred())
    55  
    56  					file2 := filepath.Join(dir, "file2")
    57  					err = ioutil.WriteFile(file2, nil, 0666)
    58  					Expect(err).ToNot(HaveOccurred())
    59  
    60  					cfIgnoreFilePath := filepath.Join(dir, ".cfignore")
    61  					err = ioutil.WriteFile(cfIgnoreFilePath, []byte("file*"), 0666)
    62  					Expect(err).ToNot(HaveOccurred())
    63  
    64  					session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, firstApp)
    65  
    66  					Eventually(session).Should(Say("28[0-9] B / 28[0-9] B"))
    67  					Eventually(session).Should(Exit(0))
    68  				})
    69  			})
    70  		})
    71  	})
    72  
    73  	Context("when the CF_TRACE file is in the app source directory", func() {
    74  		var previousEnv string
    75  
    76  		AfterEach(func() {
    77  			err := os.Setenv("CF_TRACE", previousEnv)
    78  			Expect(err).ToNot(HaveOccurred())
    79  		})
    80  
    81  		It("does not push it", func() {
    82  			helpers.WithHelloWorldApp(func(dir string) {
    83  				traceFilePath := filepath.Join(dir, "i-am-trace.txt")
    84  				err := ioutil.WriteFile(traceFilePath, nil, 0666)
    85  				Expect(err).ToNot(HaveOccurred())
    86  
    87  				previousEnv = os.Getenv("CF_TRACE")
    88  				err = os.Setenv("CF_TRACE", traceFilePath)
    89  				Expect(err).ToNot(HaveOccurred())
    90  
    91  				session := helpers.CustomCF(helpers.CFEnv{WorkingDirectory: dir}, PushCommandName, firstApp)
    92  
    93  				Eventually(session).Should(Say("28[0-9] B / 28[0-9] B"))
    94  				Eventually(session).Should(Exit(0))
    95  			})
    96  		})
    97  	})
    98  })