-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mockgen: Sanitize the "any" package name (#132)
When a package name is "any" mockgen will use that as a package name in the generated code which causes issues due to colliding with Go's "any" type. Update the sanitization logic to prevent this collision.
- Loading branch information
Showing
5 changed files
with
85 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package any | ||
|
||
// Any is a type of a package that tests the sanitization of imported packages | ||
// named any. | ||
type Any struct {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package sanitization | ||
|
||
import ( | ||
"go.uber.org/mock/mockgen/internal/tests/sanitization/any" | ||
) | ||
|
||
//go:generate mockgen -destination mockout/mock.go -package mockout . AnyMock | ||
|
||
type AnyMock interface { | ||
Do(a *any.Any, b int) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package sanitization | ||
|
||
import ( | ||
"testing" | ||
|
||
"go.uber.org/mock/gomock" | ||
any0 "go.uber.org/mock/mockgen/internal/tests/sanitization/any" | ||
"go.uber.org/mock/mockgen/internal/tests/sanitization/mockout" | ||
) | ||
|
||
func TestSanitization(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
m := mockout.NewMockAnyMock(ctrl) | ||
m.EXPECT().Do(gomock.Any(), 1) | ||
m.Do(&any0.Any{}, 1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters