Skip to content
This repository has been archived by the owner on Jun 27, 2023. It is now read-only.

Commit

Permalink
sort methods on the mock implementation alphabetically (#500)
Browse files Browse the repository at this point in the history
Sorting the methods by name will make sure that their order is
consistent in source and reflect mode.
  • Loading branch information
marten-seemann authored Dec 10, 2020
1 parent 99aa927 commit 1fe605d
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 52 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions mockgen/internal/tests/import_embedded_interface/bugreport_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions mockgen/internal/tests/mock_in_test_package/mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions mockgen/internal/tests/test_package/mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions mockgen/mockgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,14 @@ func (g *generator) GenerateMockInterface(intf *model.Interface, outputPackagePa
return nil
}

type byMethodName []*model.Method

func (b byMethodName) Len() int { return len(b) }
func (b byMethodName) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
func (b byMethodName) Less(i, j int) bool { return b[i].Name < b[j].Name }

func (g *generator) GenerateMockMethods(mockType string, intf *model.Interface, pkgOverride string) {
sort.Sort(byMethodName(intf.Methods))
for _, m := range intf.Methods {
g.p("")
_ = g.GenerateMockMethod(mockType, m, pkgOverride)
Expand Down

0 comments on commit 1fe605d

Please sign in to comment.