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

[mdatagen] generate goleak package test #9959

Merged
merged 5 commits into from
Apr 17, 2024

Conversation

codeboten
Copy link
Contributor

@codeboten codeboten commented Apr 12, 2024

This automates the generation of package_test.go for any component that uses mdatagen.

The following configuration can be used to skip or ignore certain funcs:

tests:
  goleak:
    skip: true

tests:
  goleak:
    ignore:
      top:
        - "go.opencensus.io/stats/view.(*worker).start"

@codeboten codeboten requested review from a team and songy23 April 12, 2024 19:33
@crobert-1
Copy link
Member

There's an open issue in the contrib repository for this with some discussion. Might be good to add a reference in the PR description, or copy/move it to core?

Copy link
Member

@crobert-1 crobert-1 left a comment

Choose a reason for hiding this comment

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

Thanks for doing this, automatically generating the tests will be really helpful 👍

cmd/mdatagen/loader.go Outdated Show resolved Hide resolved
@@ -66,6 +66,10 @@ func run(ymlPath string) error {
filepath.Join(ymlDir, "generated_component_test.go"), md, packageName); err != nil {
return err
}
if err = generateFile(filepath.Join(tmplDir, "package_test.go.tmpl"),
Copy link
Member

@crobert-1 crobert-1 Apr 12, 2024

Choose a reason for hiding this comment

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

I'm not very familiar with the inner-workings of mdatagen, but would it be very hard to modify so that sub-packages also have goleak generated?

For example:

.//consumer/consumertest/package_test.go
.//consumer/consumererror/package_test.go
.//consumer/package_test.go

One of the potential challenges of this is that each subdir/package would need its own goleak options, as it may need skipped, or have its own ignores that we don't want in other packages.

It's likely out of the scope of this PR, just raising as something that could be done here, or will need to be done later.

Copy link

codecov bot commented Apr 12, 2024

Codecov Report

Attention: Patch coverage is 33.33333% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 91.69%. Comparing base (29240d9) to head (ac03a83).

❗ Current head ac03a83 differs from pull request most recent head f4eb76f. Consider uploading reports for the commit f4eb76f to get more accurate results

Files Patch % Lines
cmd/mdatagen/main.go 33.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9959      +/-   ##
==========================================
- Coverage   91.70%   91.69%   -0.02%     
==========================================
  Files         358      358              
  Lines       16543    16546       +3     
==========================================
+ Hits        15171    15172       +1     
- Misses       1045     1046       +1     
- Partials      327      328       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@songy23 songy23 added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Apr 12, 2024
@songy23
Copy link
Member

songy23 commented Apr 12, 2024

Need a rebase

This automates the generation of package_test.go for any component that uses mdatagen.

Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
@codeboten codeboten merged commit f3305aa into open-telemetry:main Apr 17, 2024
46 checks passed
@codeboten codeboten deleted the codeboten/mdatagen-goleak branch April 17, 2024 20:10
@github-actions github-actions bot added this to the next release milestone Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants