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

Commit 1fe605d

Browse files
sort methods on the mock implementation alphabetically (#500)
Sorting the methods by name will make sure that their order is consistent in source and reflect mode.
1 parent 99aa927 commit 1fe605d

File tree

5 files changed

+59
-52
lines changed

5 files changed

+59
-52
lines changed

mockgen/internal/tests/aux_imports_embedded_interface/bugreport_mock.go

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mockgen/internal/tests/import_embedded_interface/bugreport_mock.go

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mockgen/internal/tests/mock_in_test_package/mock_test.go

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mockgen/internal/tests/test_package/mock_test.go

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mockgen/mockgen.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,14 @@ func (g *generator) GenerateMockInterface(intf *model.Interface, outputPackagePa
424424
return nil
425425
}
426426

427+
type byMethodName []*model.Method
428+
429+
func (b byMethodName) Len() int { return len(b) }
430+
func (b byMethodName) Swap(i, j int) { b[i], b[j] = b[j], b[i] }
431+
func (b byMethodName) Less(i, j int) bool { return b[i].Name < b[j].Name }
432+
427433
func (g *generator) GenerateMockMethods(mockType string, intf *model.Interface, pkgOverride string) {
434+
sort.Sort(byMethodName(intf.Methods))
428435
for _, m := range intf.Methods {
429436
g.p("")
430437
_ = g.GenerateMockMethod(mockType, m, pkgOverride)

0 commit comments

Comments
 (0)