Skip to content

Use t.Run for /pkg/cri tests#7001

Merged
kzys merged 1 commit intocontainerd:mainfrom
dcantah:cri-trun
May 31, 2022
Merged

Use t.Run for /pkg/cri tests#7001
kzys merged 1 commit intocontainerd:mainfrom
dcantah:cri-trun

Conversation

@dcantah
Copy link
Copy Markdown
Member

@dcantah dcantah commented May 30, 2022

A majority of the tests in /pkg/cri are testing/validating multiple things per test (generally spec or options validations). This flow lends itself well to using *testing.T's Run method to run each thing as a subtest so go test output can actually display which subtest failed/passed.

Some of the tests in the packages in pkg/cri already did this, but a bunch simply logged what testcase was currently running without invoking t.Run().

Thanks to @samuelkarp for suggesting this on another PR #6996 (comment). I'm not married to the "TestCase" prefix for the subtest names, but it was already used for the log and a couple other t.Run() uses so mostly following how things already were.

@samuelkarp
Copy link
Copy Markdown
Member

samuelkarp commented May 30, 2022

I'd probably drop the "TestCase " prefix; I don't think it adds much value. (There could be people parsing the existing t.Log-based output, but...that seems reasonably unlikely as test output and test names can change as we develop them; they're not an interface or a contract.)

Also, thanks for doing this!

@dcantah
Copy link
Copy Markdown
Member Author

dcantah commented May 30, 2022

I'd probably drop the "TestCase " prefix; I don't think it adds much value. (There could be people parsing the existing t.Log-based output, but...that seems reasonably unlikely as test output and test names can change as we develop them; they're not an interface or a contract.)

I'll drop 'em then as I'm in agreeance

Also, thanks for doing this!

Of course!

@dcantah
Copy link
Copy Markdown
Member Author

dcantah commented May 30, 2022

@samuelkarp Removed the TestCase prefix, thanks!

Comment thread pkg/cri/server/container_stats_list_linux_test.go Outdated
Comment thread pkg/cri/server/container_update_resources_linux_test.go Outdated
Comment thread pkg/cri/server/helpers_linux_test.go Outdated
Comment thread pkg/cri/server/helpers_selinux_linux_test.go Outdated
Comment thread pkg/cri/server/sandbox_run_linux_test.go Outdated
@dcantah
Copy link
Copy Markdown
Member Author

dcantah commented May 30, 2022

@samuelkarp Seems my editor didn't feel like removing unused imports today. Fixing shortly

A majority of the tests in /pkg/cri are testing/validating multiple
things per test (generally spec or options validations). This flow
lends itself well to using *testing.T's Run method to run each thing
as a subtest so `go test` output can actually display which subtest
failed/passed.

Some of the tests in the packages in pkg/cri already did this, but
a bunch simply logged what sub-testcase was currently running without
invoking t.Run.

Signed-off-by: Daniel Canter <[email protected]>
Copy link
Copy Markdown
Member

@samuelkarp samuelkarp 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! LGTM.

Copy link
Copy Markdown
Member

@mikebrow mikebrow left a comment

Choose a reason for hiding this comment

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

LGTM

@kzys kzys merged commit 78cd9d3 into containerd:main May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants