Skip to content

Commit

Permalink
chore(ci): workflow to check mocks are kept updated (ChainSafe#2062)
Browse files Browse the repository at this point in the history
* workflow to check mocks are updated

* Install mockery and mockgen

* Update outdated mocks

* Fix outdated test code
  • Loading branch information
qdm12 authored and timwu20 committed Dec 6, 2021
1 parent b21ae90 commit 0ff26be
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 24 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/mocks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Mocks check
on:
pull_request:
branches:
- development
paths:
- .github/workflows/mocks.yml
- "**/*.go"

jobs:
mocks-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: actions/setup-go@v2
with:
go-version: "^1.17"

- run: go install github.com/vektra/mockery/v2@v2.9.4

- run: go install github.com/golang/mock/mockgen@v1.6.0

- run: go generate -run "mockery" ./...

- run: go generate -run "mockgen" ./...

- name: mocks updated check
run: git diff --exit-code
16 changes: 8 additions & 8 deletions dot/network/mock_transaction_handler.go

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

5 changes: 4 additions & 1 deletion dot/network/notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,10 @@ func Test_HandshakeTimeout(t *testing.T) {
func TestCreateNotificationsMessageHandler_HandleTransaction(t *testing.T) {
basePath := utils.NewTestBasePath(t, "nodeA")
mockhandler := &MockTransactionHandler{}
mockhandler.On("HandleTransactionMessage", mock.AnythingOfType("*network.TransactionMessage")).Return(true, nil)
mockhandler.On("HandleTransactionMessage",
mock.AnythingOfType("peer.ID"),
mock.AnythingOfType("*network.TransactionMessage")).
Return(true, nil)
mockhandler.On("TransactionsCount").Return(0)
config := &Config{
BasePath: basePath,
Expand Down
5 changes: 4 additions & 1 deletion dot/network/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ func createTestService(t *testing.T, cfg *Config) (srvc *Service) {

if cfg.TransactionHandler == nil {
mocktxhandler := &MockTransactionHandler{}
mocktxhandler.On("HandleTransactionMessage", mock.AnythingOfType("*TransactionMessage")).Return(nil)
mocktxhandler.On("HandleTransactionMessage",
mock.AnythingOfType("peer.ID"),
mock.AnythingOfType("*TransactionMessage")).
Return(nil)
mocktxhandler.On("TransactionsCount").Return(0)
cfg.TransactionHandler = mocktxhandler
}
Expand Down
5 changes: 4 additions & 1 deletion dot/network/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ func NewMockSyncer() *MockSyncer {
// NewMockTransactionHandler create and return a network TransactionHandler interface
func NewMockTransactionHandler() *MockTransactionHandler {
mocktxhandler := new(MockTransactionHandler)
mocktxhandler.On("HandleTransactionMessage", mock.AnythingOfType("*network.TransactionMessage")).Return(nil)
mocktxhandler.On("HandleTransactionMessage",
mock.AnythingOfType("peer.ID"),
mock.AnythingOfType("*network.TransactionMessage")).
Return(nil)
mocktxhandler.On("TransactionsCount").Return(0)
return mocktxhandler
}
Expand Down
8 changes: 6 additions & 2 deletions dot/network/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ func TestDecodeTransactionHandshake(t *testing.T) {
func TestHandleTransactionMessage(t *testing.T) {
basePath := utils.NewTestBasePath(t, "nodeA")
mockhandler := &MockTransactionHandler{}
mockhandler.On("HandleTransactionMessage", mock.AnythingOfType("*network.TransactionMessage")).Return(true, nil)
mockhandler.On("HandleTransactionMessage",
mock.AnythingOfType("peer.ID"),
mock.AnythingOfType("*network.TransactionMessage")).
Return(true, nil)
mockhandler.On("TransactionsCount").Return(0)

config := &Config{
Expand All @@ -46,5 +49,6 @@ func TestHandleTransactionMessage(t *testing.T) {
}

s.handleTransactionMessage(peer.ID(""), msg)
mockhandler.AssertCalled(t, "HandleTransactionMessage", msg)
mockhandler.AssertCalled(t, "HandleTransactionMessage",
mock.AnythingOfType("peer.ID"), msg)
}
11 changes: 0 additions & 11 deletions dot/rpc/modules/mocks/network_api.go

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

0 comments on commit 0ff26be

Please sign in to comment.