Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
fix(stapel/imports): processing of includePaths/excludePaths with glo…
…bs in file/directory name includePaths/excludePaths were mishandled if their file or directory name contained a glob. E.g.: "directory/pathprefix-*". Signed-off-by: Aleksei Igrychev <aleksei.igrychev@palark.com>
- Loading branch information
1 parent
2f98135
commit 7046ca7
Showing
4 changed files
with
83 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package util | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestSafeTrimGlobsAndSlashes(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
path string | ||
want string | ||
}{ | ||
{ | ||
name: "globs", | ||
path: "**/*", | ||
want: "", | ||
}, | ||
{ | ||
name: "empty path", | ||
path: "", | ||
want: "", | ||
}, | ||
{ | ||
name: "path", | ||
path: "path", | ||
want: "path", | ||
}, | ||
{ | ||
name: "path with trailing slash", | ||
path: "path/", | ||
want: "path", | ||
}, | ||
{ | ||
name: "path with globs and slashes", | ||
path: "path/**/*", | ||
want: "path", | ||
}, | ||
{ | ||
name: "path with glob as part of a directory or file name 1", | ||
path: "path/name-*", | ||
want: "path/name-*", | ||
}, | ||
{ | ||
name: "path with glob as part of a directory or file name 2", | ||
path: "path/*.tmp", | ||
want: "path/*.tmp", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := SafeTrimGlobsAndSlashesFromPath(tt.path); got != tt.want { | ||
t.Errorf("SafeTrimGlobsAndSlashesFromPath() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |