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

test: add missing unit test #51

Merged
merged 1 commit into from
May 27, 2024
Merged

Conversation

ConorC117
Copy link
Collaborator

Add table-driven unit test for removeOldestSample function

@ConorC117 ConorC117 requested review from F-X64 and miyunari May 22, 2024 23:56
@ConorC117 ConorC117 marked this pull request as ready for review May 23, 2024 08:11
Copy link
Collaborator

@F-X64 F-X64 left a comment

Choose a reason for hiding this comment

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

Nice work, your coding style is clean and I like that you've used table driven testing.

}{
{
name: "Remove 3 oldest samples",
log: &MetricsLog{path: "/tmp/test_log"},
Copy link
Collaborator

Choose a reason for hiding this comment

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

As all of these tests are executed in sequence this will work just fine.
If you want to ensure that the same tmp file isn't used in other tests that might lead to flanky test results you can use ioutils.tempFile

Copy link
Member

Choose a reason for hiding this comment

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

For this usecase it might be good to use t.TempDir https://pkg.go.dev/testing#B.TempDir as it is used e.g. in function createMetricsPath - or use this function.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the feedback. I think that's a good suggestion for this usecase tried updating the code, it's a little cleaner now too!

@ConorC117 ConorC117 force-pushed the tests branch 2 times, most recently from b03c4cc to af4802e Compare May 23, 2024 15:51
Add table-driven unit test for removeOldestSample function

Signed-off-by: ccowman <[email protected]>
@ConorC117 ConorC117 merged commit 473336c into RedHatInsights:main May 27, 2024
7 checks passed
Copy link

🎉 This PR is included in version 1.3.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants