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

Stream manager tests #2036

Merged
merged 5 commits into from
Sep 3, 2024
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
24 changes: 12 additions & 12 deletions common/stream_services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"testing"

"github.com/dominant-strategies/go-quai/common/mocks"
"github.com/golang/mock/gomock"
mock_p2p "github.com/dominant-strategies/go-quai/p2p/mocks"
"github.com/stretchr/testify/assert"
gomock "go.uber.org/mock/gomock"
)

const (
Expand All @@ -24,13 +24,13 @@ func TestWriteMessageToStream(t *testing.T) {
name string
message []byte
wantErr bool
setupMock func(*mocks.MockStream)
setupMock func(*mock_p2p.MockStream)
}{
{
name: "successful write with short message",
message: []byte(shortMessage),
wantErr: false,
setupMock: func(m *mocks.MockStream) {
setupMock: func(m *mock_p2p.MockStream) {
m.EXPECT().SetWriteDeadline(gomock.Any()).Return(nil)
gomock.InOrder(
// first expect the length of the message to be written
Expand All @@ -50,7 +50,7 @@ func TestWriteMessageToStream(t *testing.T) {
name: "successful write with long message",
message: []byte(longMessage),
wantErr: false,
setupMock: func(m *mocks.MockStream) {
setupMock: func(m *mock_p2p.MockStream) {
m.EXPECT().SetWriteDeadline(gomock.Any()).Return(nil)
gomock.InOrder(
// first expect the length of the message to be written
Expand All @@ -70,7 +70,7 @@ func TestWriteMessageToStream(t *testing.T) {
name: "error on write deadline",
message: []byte(shortMessage),
wantErr: true,
setupMock: func(m *mocks.MockStream) {
setupMock: func(m *mock_p2p.MockStream) {
m.EXPECT().SetWriteDeadline(gomock.Any()).Return(fmt.Errorf("error"))
},
},
Expand All @@ -81,7 +81,7 @@ func TestWriteMessageToStream(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

mockStream := mocks.NewMockStream(ctrl)
mockStream := mock_p2p.NewMockStream(ctrl)
tt.setupMock(mockStream)

err := WriteMessageToStream(mockStream, tt.message, "testproto", nil)
Expand All @@ -98,13 +98,13 @@ func TestReadMessageFromStream(t *testing.T) {
t.Skip("Todo: fix failing test")
tests := []struct {
name string
setupMock func(*mocks.MockStream)
setupMock func(*mock_p2p.MockStream)
want []byte
wantErr bool
}{
{
name: "successful read with short message",
setupMock: func(m *mocks.MockStream) {
setupMock: func(m *mock_p2p.MockStream) {
m.EXPECT().SetReadDeadline(gomock.Any()).Return(nil)
gomock.InOrder(
// assert that the length of the message is read first
Expand All @@ -127,7 +127,7 @@ func TestReadMessageFromStream(t *testing.T) {
},
{
name: "successful read with long message",
setupMock: func(m *mocks.MockStream) {
setupMock: func(m *mock_p2p.MockStream) {
m.EXPECT().SetReadDeadline(gomock.Any()).Return(nil)
gomock.InOrder(
// assert that the length of the message is read first
Expand All @@ -149,7 +149,7 @@ func TestReadMessageFromStream(t *testing.T) {
},
{
name: "error on read deadline",
setupMock: func(m *mocks.MockStream) {
setupMock: func(m *mock_p2p.MockStream) {
m.EXPECT().SetReadDeadline(gomock.Any()).Return(fmt.Errorf("error"))
},
wantErr: true,
Expand All @@ -161,7 +161,7 @@ func TestReadMessageFromStream(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

mockStream := mocks.NewMockStream(ctrl)
mockStream := mock_p2p.NewMockStream(ctrl)
tt.setupMock(mockStream)

got, err := ReadMessageFromStream(mockStream, "testproto", nil)
Expand Down
Loading
Loading