Skip to content

Commit

Permalink
tests: covers skip dir.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcchavezs committed Oct 1, 2023
1 parent b037e56 commit 081ee6f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
6 changes: 5 additions & 1 deletion import.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ func findAndAddVanityImportForModuleDir(workingDir, absDir string, moduleName st

gc := 0
for _, f := range files {
if isDir, dirName := f.IsDir(), f.Name(); isDir && !matchesAny(opts.SkipDirsRegexes, dirName) {
if isDir, dirName := f.IsDir(), f.Name(); isDir {
if matchesAny(opts.SkipDirsRegexes, dirName) {
continue
}

var (
c int
err error
Expand Down
23 changes: 21 additions & 2 deletions import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,33 @@ func TestFindFilesWithVanityImport(t *testing.T) {
assert.Equal(t, 1, c)
})

t.Run("include file", func(t *testing.T) {
t.Run("skip dir", func(t *testing.T) {
c, err := findAndAddVanityImportForModuleDir(
cwd,
cwd+"/testdata",
"github.com/jcchavezs/porto/integration",
Options{
ListDiffFiles: true,
SkipDirsRegexes: []*regexp.Regexp{
regexp.MustCompile(`^codegen$`),
regexp.MustCompile(`^leftpad$`),
regexp.MustCompile(`^rightpad$`),
},
},
)

require.NoError(t, err)
assert.Equal(t, 1, c)
})

t.Run("restrict to files", func(t *testing.T) {
c, err := findAndAddVanityImportForModuleDir(
cwd,
cwd+"/testdata/leftpad",
"github.com/jcchavezs/porto-integration-leftpad",
Options{
ListDiffFiles: true,
RestrictToFilesRegexes: []*regexp.Regexp{regexp.MustCompile(`other\.go`)},
RestrictToFilesRegexes: []*regexp.Regexp{regexp.MustCompile(`^other\.go$`)},
},
)

Expand Down

0 comments on commit 081ee6f

Please sign in to comment.