Skip to content
This repository was archived by the owner on Sep 29, 2025. It is now read-only.

feat: Add nil pointer faking#5

Merged
hermanschaaf merged 4 commits intocloudquery:masterfrom
hermanschaaf:add-nil-pointer-faking
Jul 14, 2022
Merged

feat: Add nil pointer faking#5
hermanschaaf merged 4 commits intocloudquery:masterfrom
hermanschaaf:add-nil-pointer-faking

Conversation

@hermanschaaf
Copy link
Copy Markdown

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
@hermanschaaf hermanschaaf requested a review from yevgenypats July 14, 2022 09:37
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
Copy Markdown
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
Copy Markdown
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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants