Skip to content

Commit

Permalink
Merge pull request #46 from TheSgrash/master
Browse files Browse the repository at this point in the history
Implement except for walk case
  • Loading branch information
herrjulz authored Mar 8, 2022
2 parents 13c33b0 + 84d760b commit 102d129
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions processor/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ func fillSliceWithFiles(files *[]string) filepath.WalkFunc {
}
}

func getFileName(path string) string {
chunked := strings.Split(path, "/")
return chunked[len(chunked)-1]
}

func concatFileNameWithPath(path string) (string, string) {
var fileName, parent string
chunked := strings.Split(path, "/")
Expand Down
4 changes: 4 additions & 0 deletions processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ func (p *Processor) walk(cfg aviator.Spruce, outer string) error {
regex := getRegexp(cfg.ForEach.Regexp)
for _, f := range sl {
filename, parent := concatFileNameWithPath(f)
if except(cfg.ForEach.Except, getFileName(f)) {
p.warnings = append(p.warnings, "SKIPPED: "+getFileName(f))
continue
}
match := enableMatching(cfg.ForEach, parent)
matched, _ := regexp.MatchString(regex, filename)
if strings.Contains(outer, match) && matched {
Expand Down
23 changes: 23 additions & 0 deletions processor/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,29 @@ var _ = Describe("Processor", func() {
Expect(len(mergeOpts.Files)).To(Equal(5))
})
})

Context("'In' in combination with 'subdirs' and 'except'", func() {
It("should run a merge for each file in the directory specified in 'for_each.in' and its subdirs, except those specified in 'except'.. its even more complicated", func() {
cfg.Merge[0].With.Files = []string{"fake1", "fake2"}
cfg.ForEach.In = "integration/yamls/addons/"
cfg.ForEach.SubDirs = true
cfg.ForEach.Except = "fake2"
cfg.ForEach.ForAll = "integration/yamls/"

spruceConfig = []aviator.Spruce{cfg}
spruceClient = new(fakes.FakeSpruceClient)
processor = NewTestProcessor(spruceClient, store, modifier)

err := processor.ProcessSilent(spruceConfig)
Expect(err).ToNot(HaveOccurred())

cc := spruceClient.MergeWithOptsCallCount()
Expect(cc).To(Equal(8))

mergeOpts := spruceClient.MergeWithOptsArgsForCall(0)
Expect(len(mergeOpts.Files)).To(Equal(4))
})
})
})
})
})
Expand Down

0 comments on commit 102d129

Please sign in to comment.