Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude modules with init() in tests from includes lists #12650

Merged
merged 1 commit into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions dev-tools/cmd/module_include_list/module_include_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,18 @@ func main() {
// Build import paths.
var imports []string
for _, dir := range dirs {
// Skip dirs that have no .go files.
goFiles, err := filepath.Glob(filepath.Join(dir, "*.go"))
if err != nil {
log.Fatal("Failed checking for .go files in package dir: %v", err)
}
if len(goFiles) == 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was used as a sanity check with the assumption that anything using this code should find at least one thing to import. Maybe we should add this check after the for loop completes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this check because at the end if there are no go files then foundInitMethod is never going to be true.

continue
}

// Skip packages without an init() function because that cannot register
// anything as a side-effect of being imported (e.g. filebeat/input/file).
var foundInitMethod bool
goFiles, err := filepath.Glob(filepath.Join(dir, "*.go"))
if err != nil {
log.Fatalf("Failed checking for .go files in package dir: %v", err)
}
for _, f := range goFiles {
// Skip test files
if strings.HasSuffix(f, "_test.go") {
continue
}
if hasInitMethod(f) {
foundInitMethod = true
break
Expand Down
1 change: 0 additions & 1 deletion packetbeat/include/list.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.