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

feat: Add nil pointer faking #5

Merged
merged 4 commits into from
Jul 14, 2022

Conversation

hermanschaaf
Copy link
Member

Adds FakeDataWithNilPointerGenerator, a function that returns a generator. On successive calls, the generator returns a filled out interface with exactly one pointer field set to nil. This can be used in tests to detect nil pointer dereference errors.

@hermanschaaf hermanschaaf changed the title Add nil pointer faking feat: Add nil pointer faking Jul 14, 2022
faker.go Outdated
// FakeDataWithNilPointerGenerator returns a generator that can be used to create successive fakes with
// a single pointer set to nil. This can be used to iterate through fakes with all possible pointer fields
// set to nil, to catch nil pointer-dereference errors.
func FakeDataWithNilPointerGenerator() *generator {
Copy link
Member

Choose a reason for hiding this comment

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

Exported method returning an unexported struct looks weird

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. It's technically valid but can prevent manipulation by packages using the function. We actually only need the Next() method, so I've changed it to return a public interface that exposes only that method instead.

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.

3 participants