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

Use generics to stub a single value with auto-reset #21

Merged
merged 1 commit into from
Oct 21, 2024

Conversation

prashantv
Copy link
Owner

No description provided.

// Value replaces the value at varPtr with stubVal.
// The original value is reset at the end of the test via t.Cleanup
// or can be reset using the returned function.
func Value[T any](t TestingT, varPtr *T, stubVal T) (reset func()) {
Copy link
Owner Author

Choose a reason for hiding this comment

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

Should there only be a single function that always takes TestingT, or should there be 2 versions -- Value that doesn't take TestingT and doesn't auto-reset, and ValueT which takes TestingT and auto-resets

Copy link
Owner Author

Choose a reason for hiding this comment

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

Going with Value for now, since auto-reset is a better default for callers, so it should have less noise.

@prashantv prashantv marked this pull request as ready for review October 21, 2024 01:56
@prashantv prashantv merged commit c8bd471 into master Oct 21, 2024
2 checks passed
@prashantv prashantv deleted the prashant/generics branch October 21, 2024 01:57
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.

1 participant