github.com/sleungcy-sap/cli@v7.1.0+incompatible/cf/appfiles/cf_ignore_test.go (about)

     1  package appfiles_test
     2  
     3  import (
     4  	. "code.cloudfoundry.org/cli/cf/appfiles"
     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 the directories based on relative path matches", func() {
    22  		ignore := NewCfIgnore(`dir1`)
    23  		Expect(ignore.FileShouldBeIgnored("dir1")).To(BeTrue())
    24  		Expect(ignore.FileShouldBeIgnored("dir2/dir1")).To(BeTrue())
    25  		Expect(ignore.FileShouldBeIgnored("dir3/dir2/dir1")).To(BeTrue())
    26  		Expect(ignore.FileShouldBeIgnored("dir3/dir1/dir2")).To(BeTrue())
    27  	})
    28  
    29  	It("excludes files based on star patterns", func() {
    30  		ignore := NewCfIgnore(`dir1/*.so`)
    31  		Expect(ignore.FileShouldBeIgnored("dir1/file1.so")).To(BeTrue())
    32  		Expect(ignore.FileShouldBeIgnored("dir1/file2.cc")).To(BeFalse())
    33  	})
    34  
    35  	It("excludes files based on double-star patterns", func() {
    36  		ignore := NewCfIgnore(`dir1/**/*.so`)
    37  		Expect(ignore.FileShouldBeIgnored("dir1/dir2/dir3/file1.so")).To(BeTrue())
    38  		Expect(ignore.FileShouldBeIgnored("different-dir/dir2/file.so")).To(BeFalse())
    39  	})
    40  
    41  	It("allows files to be explicitly included", func() {
    42  		ignore := NewCfIgnore(`
    43  node_modules/*
    44  !node_modules/common
    45  `)
    46  
    47  		Expect(ignore.FileShouldBeIgnored("node_modules/something-else")).To(BeTrue())
    48  		Expect(ignore.FileShouldBeIgnored("node_modules/common")).To(BeFalse())
    49  	})
    50  
    51  	It("applies the patterns in order from top to bottom", func() {
    52  		ignore := NewCfIgnore(`
    53  stuff/*
    54  !stuff/*.c
    55  stuff/exclude.c`)
    56  
    57  		Expect(ignore.FileShouldBeIgnored("stuff/something.txt")).To(BeTrue())
    58  		Expect(ignore.FileShouldBeIgnored("stuff/exclude.c")).To(BeTrue())
    59  		Expect(ignore.FileShouldBeIgnored("stuff/include.c")).To(BeFalse())
    60  	})
    61  
    62  	It("ignores certain commonly ingored files by default", func() {
    63  		ignore := NewCfIgnore(``)
    64  		Expect(ignore.FileShouldBeIgnored(".git/objects")).To(BeTrue())
    65  
    66  		ignore = NewCfIgnore(`!.git`)
    67  		Expect(ignore.FileShouldBeIgnored(".git/objects")).To(BeFalse())
    68  	})
    69  
    70  	Describe("files named manifest.yml", func() {
    71  		var (
    72  			ignore CfIgnore
    73  		)
    74  
    75  		BeforeEach(func() {
    76  			ignore = NewCfIgnore("")
    77  		})
    78  
    79  		It("ignores manifest.yml at the top level", func() {
    80  			Expect(ignore.FileShouldBeIgnored("manifest.yml")).To(BeTrue())
    81  		})
    82  
    83  		It("does not ignore nested manifest.yml files", func() {
    84  			Expect(ignore.FileShouldBeIgnored("public/assets/manifest.yml")).To(BeFalse())
    85  		})
    86  	})
    87  })