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

mocks: update list, fix unexported interfaces in bfd #3878

Merged
merged 1 commit into from
Sep 18, 2020

Conversation

matzf
Copy link
Contributor

@matzf matzf commented Sep 16, 2020

During various refactors (e.g. #3862), some of the mocks were updated without updating the list of mock targets in tools/gomocks. Fixed by semi-manually syncing the mock target list with the actually existing mocks.

The interfaces in go/pkg/router/bfd/ were not directly exported and gomock refused to generate the mock code.


This change is Reviewable

Copy link
Contributor

@oncilla oncilla left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 3 files reviewed, 1 unresolved discussion (waiting on @matzf)


go/pkg/router/bfd/export_test.go, line 48 at r1 (raw file):

	State                    = state
	Event                    = event
	Source                   = source

Why are these changes needed?

Copy link
Contributor Author

@matzf matzf left a comment

Choose a reason for hiding this comment

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

Reviewable status: 0 of 3 files reviewed, 1 unresolved discussion (waiting on @oncilla)


go/pkg/router/bfd/export_test.go, line 48 at r1 (raw file):

Previously, Oncilla (Dominik Roos) wrote…

Why are these changes needed?

mockgen does not see the Source and IntervalGenerator types, as they are only exported in this _test.go file.
It also refuses to create mocks for the unexported interfaces. I don't think there is a way to make these interfaces visible to mockgen and at the same time keep them private -- at least not in the "reflect" mode of mockgen.
Not sure how creating the checked in mocks was accomplished, maybe just manually export interface, run mockgen and then change it back to private?

Copy link
Contributor

@oncilla oncilla left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 3 of 3 files at r1.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved


go/pkg/router/bfd/export_test.go, line 48 at r1 (raw file):

Previously, matzf (Matthias Frei) wrote…

mockgen does not see the Source and IntervalGenerator types, as they are only exported in this _test.go file.
It also refuses to create mocks for the unexported interfaces. I don't think there is a way to make these interfaces visible to mockgen and at the same time keep them private -- at least not in the "reflect" mode of mockgen.
Not sure how creating the checked in mocks was accomplished, maybe just manually export interface, run mockgen and then change it back to private?

Hm, yeah this looks a bit awkward. It's a bit unfortunate that gomock does not see the _test.go files. But I guess it makes sense.

Conceptually, I think it is cleaner to hide these interfaces, since they solely exist for testing.

You could actually do it with a second definition of the same interface in go/pkg/router/bfd/internal/
and then apply mockgen on that. But IMO I don't think that is worth the effort.


go/pkg/router/bfd/jitter.go, line 67 at r1 (raw file):

}

// IntervalGenerator generates integers in [x, y). It panics if x < 0 or if y <= x.

Interesting, it looks like this was public once, and then hidden. 🕵️
Same for source.

@oncilla
Copy link
Contributor

oncilla commented Sep 18, 2020

/rebase

@oncilla oncilla merged commit b5c427e into scionproto:master Sep 18, 2020
@matzf matzf deleted the fix-mocks branch November 12, 2020 13:39
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.

2 participants