github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/app_files/cf_ignore_test.go (about)

     1  package app_files_test
     2  
     3  import (
     4  	. "github.com/cloudfoundry/cli/cf/app_files"
     5  	. "github.com/onsi/ginkgo"
     6  	. "github.com/onsi/gomega"
     7  )
     8  
     9  var _ = Describe("CF Ignore", func() {
    10  	It("excludes files based on exact path matches", func() {
    11  		ignore := NewCfIgnore(`the-dir/the-path`)
    12  		Expect(ignore.FileShouldBeIgnored("the-dir/the-path")).To(BeTrue())
    13  	})
    14  
    15  	It("excludes the contents of directories based on exact path matches", func() {
    16  		ignore := NewCfIgnore(`dir1/dir2`)
    17  		Expect(ignore.FileShouldBeIgnored("dir1/dir2/the-file")).To(BeTrue())
    18  		Expect(ignore.FileShouldBeIgnored("dir1/dir2/dir3/the-file")).To(BeTrue())
    19  	})
    20  
    21  	It("excludes files based on star patterns", func() {
    22  		ignore := NewCfIgnore(`dir1/*.so`)
    23  		Expect(ignore.FileShouldBeIgnored("dir1/file1.so")).To(BeTrue())
    24  		Expect(ignore.FileShouldBeIgnored("dir1/file2.cc")).To(BeFalse())
    25  	})
    26  
    27  	It("excludes files based on double-star patterns", func() {
    28  		ignore := NewCfIgnore(`dir1/**/*.so`)
    29  		Expect(ignore.FileShouldBeIgnored("dir1/dir2/dir3/file1.so")).To(BeTrue())
    30  		Expect(ignore.FileShouldBeIgnored("different-dir/dir2/file.so")).To(BeFalse())
    31  	})
    32  
    33  	It("allows files to be explicitly included", func() {
    34  		ignore := NewCfIgnore(`
    35  node_modules/*
    36  !node_modules/common
    37  `)
    38  
    39  		Expect(ignore.FileShouldBeIgnored("node_modules/something-else")).To(BeTrue())
    40  		Expect(ignore.FileShouldBeIgnored("node_modules/common")).To(BeFalse())
    41  	})
    42  
    43  	It("applies the patterns in order from top to bottom", func() {
    44  		ignore := NewCfIgnore(`
    45  stuff/*
    46  !stuff/*.c
    47  stuff/exclude.c`)
    48  
    49  		Expect(ignore.FileShouldBeIgnored("stuff/something.txt")).To(BeTrue())
    50  		Expect(ignore.FileShouldBeIgnored("stuff/exclude.c")).To(BeTrue())
    51  		Expect(ignore.FileShouldBeIgnored("stuff/include.c")).To(BeFalse())
    52  	})
    53  
    54  	It("ignores certain commonly ingored files by default", func() {
    55  		ignore := NewCfIgnore(``)
    56  		Expect(ignore.FileShouldBeIgnored(".git/objects")).To(BeTrue())
    57  
    58  		ignore = NewCfIgnore(`!.git`)
    59  		Expect(ignore.FileShouldBeIgnored(".git/objects")).To(BeFalse())
    60  	})
    61  
    62  	Describe("files named manifest.yml", func() {
    63  		var (
    64  			ignore CfIgnore
    65  		)
    66  
    67  		BeforeEach(func() {
    68  			ignore = NewCfIgnore("")
    69  		})
    70  
    71  		It("ignores manifest.yml at the top level", func() {
    72  			Expect(ignore.FileShouldBeIgnored("manifest.yml")).To(BeTrue())
    73  		})
    74  
    75  		It("does not ignore nested manifest.yml files", func() {
    76  			Expect(ignore.FileShouldBeIgnored("public/assets/manifest.yml")).To(BeFalse())
    77  		})
    78  	})
    79  })