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

[BE1] Add publish test #1929

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions be1-go/internal/handler/method/publish/hpublish/mocks/hub.go

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

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

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

57 changes: 57 additions & 0 deletions be1-go/internal/handler/method/publish/hpublish/publish_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package hpublish

import (
"github.com/stretchr/testify/require"
"popstellar/internal/handler/method/publish/hpublish/mocks"
"popstellar/internal/logger"
mocks2 "popstellar/internal/network/socket/mocks"
"popstellar/internal/test/generator"
"testing"
)

func Test_Handle(t *testing.T) {
log := logger.Logger.With().Str("test", "Handle").Logger()

hub := mocks.NewHub(t)
messageHandler := mocks.NewMessageHandler(t)
db := mocks.NewRepository(t)

publishHandler := New(hub, db, messageHandler, log)

socket := mocks2.NewFakeSocket("0")

queryID := 0
channelPath := "/root"
msg := generator.NewNothingMsg(t, "sender", nil)
publishBuf := generator.NewPublishQuery(t, queryID, channelPath, msg)

// succeed handling the publish + notify new rumor

messageHandler.On("Handle", channelPath, msg, false).Return(nil).Once()
db.On("AddMessageToMyRumor", msg.MessageID).Return(thresholdMessagesByRumor, nil).Once()
hub.On("NotifyResetRumorSender").Return(nil).Once()

id, err := publishHandler.Handle(socket, publishBuf)
require.Nil(t, id)
require.NoError(t, err)

// succeed handling the publish but no notify rumor

messageHandler.On("Handle", channelPath, msg, false).Return(nil).Once()
db.On("AddMessageToMyRumor", msg.MessageID).Return(thresholdMessagesByRumor-1, nil).Once()
Copy link
Contributor

Choose a reason for hiding this comment

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

By default, doesn't Mockery expect only one call?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I got some problem using mockery without the .Once() so now I'm always using it


id, err = publishHandler.Handle(socket, publishBuf)
require.Nil(t, id)
require.NoError(t, err)

// succeed handling the publish but no rumor because federation channel

channelPath = "/root/laoID/federation"
publishBuf = generator.NewPublishQuery(t, queryID, channelPath, msg)

messageHandler.On("Handle", channelPath, msg, false).Return(nil).Once()

id, err = publishHandler.Handle(socket, publishBuf)
require.Nil(t, id)
require.NoError(t, err)
}
Loading