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

testing: mock websocket for future tests #22

Merged
merged 1 commit into from
Jun 21, 2024
Merged

Conversation

HoppenR
Copy link
Contributor

@HoppenR HoppenR commented Jun 21, 2024

This allows using a mock websocket to stress test the trivia bot in the future. Intended to be used like this.

mockDialer := func(ctx context.Context, url string, opts *websocket.DialOptions) (WebsocketConn, *http.Response, error) {
	webMocket := new(MockWebSocketConn)
	// Add custom logic for what to return on different calls
	webMocket.On("Read", mock.Anything).Return(SOME_RETURN_VAL)
	return webMocket, nil, nil
}
bot, err := New(
	new(zap.SugaredLogger),
	mockDialer,
	"wss://chat2.strims.gg/ws", // or whatever...
	"placeholderToken",
	true,
	"leaderboardPage",
	"leaderboardIngress",
)
assert.Nil(t, err)
assert.NotNil(t, bot)

@jbpratt jbpratt merged commit 1376bdc into jbpratt:main Jun 21, 2024
2 checks passed
@HoppenR HoppenR deleted the testing branch June 21, 2024 12:58
@HoppenR
Copy link
Contributor Author

HoppenR commented Jun 21, 2024

Can set up different return values from Read() like this.

webMocket.On("Read", mock.Anything).Return(someRet).Once()
webMocket.On("Read", mock.Anything).Return(otherRet).Once()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants