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

Add ability to create a clio.Application that runs test assertions instead of cmd.RunE #37

Merged
merged 8 commits into from
Jan 31, 2024

Conversation

willmurphyscode
Copy link
Contributor

@willmurphyscode willmurphyscode commented Jan 26, 2024

Pull request adding a method to write unit tests that assert on the result of setting up the config in fangs/clio.

wagoodman and others added 4 commits January 25, 2024 11:05
Signed-off-by: Alex Goodman <[email protected]>
Signed-off-by: Will Murphy <[email protected]>
Signed-off-by: Will Murphy <[email protected]>
testutils/application.go Outdated Show resolved Hide resolved
testutils/application.go Outdated Show resolved Hide resolved
testutils/application.go Outdated Show resolved Hide resolved
wagoodman

This comment was marked as outdated.

The initializers may not be safe to run twice.

Signed-off-by: Will Murphy <[email protected]>
There are testutils packages everywhere. Rename clio's testutils package
to cliotestutils so that it's more obvious what's being imported.

Signed-off-by: Will Murphy <[email protected]>
This will be more readable when called as cliotestutils.NewApplication.

Signed-off-by: Will Murphy <[email protected]>
@willmurphyscode willmurphyscode changed the title With testing utils Add ability to create a clio.Application that runs test assertions instead of cmd.RunE Jan 29, 2024
// env vars, and config files. Useful for testing that expected configuration options are wired up.
// Note that initializers will be cleared from the clio setup config, since the initialization may happen
// more than once and affect global state. For necessary global state, a workaround is to set it in a TestingMain.
func NewApplication(t *testing.T, cfg *clio.SetupConfig, assertions ...AssertionFunc) clio.Application {
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the composition approach here - it might get tough to debug this, since the assertions can happen so far away from the thing they are asserting against, but I think that's a second order concern.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@willmurphyscode willmurphyscode marked this pull request as ready for review January 29, 2024 21:17
Copy link
Contributor

@kzantow kzantow left a comment

Choose a reason for hiding this comment

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

As a first pass, this looks good for what it is supposed to do; we can always expand on it later if need be

cliotestutils/application.go Show resolved Hide resolved
@willmurphyscode willmurphyscode merged commit 9eba612 into main Jan 31, 2024
4 checks passed
@willmurphyscode willmurphyscode deleted the with-testing-utils branch January 31, 2024 20:22
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