All Projects → posener → Wstest

posener / Wstest

Licence: apache-2.0
go websocket client for unit testing of a websocket handler

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Wstest

Gowebsocket
Gorilla websockets based simplified websocket-client implementation in GO.
Stars: ✭ 77 (-7.23%)
Mutual labels:  gorilla, websocket
Websocket
A fast, well-tested and widely used WebSocket implementation for Go.
Stars: ✭ 16,070 (+19261.45%)
Mutual labels:  gorilla, websocket
Websocket
Gorilla WebSocket implementation for fasthttp.
Stars: ✭ 193 (+132.53%)
Mutual labels:  gorilla, websocket
Gowog
Gowog, Golang based Web multiplayer Online Game
Stars: ✭ 75 (-9.64%)
Mutual labels:  websocket
Wscelery
Real time celery monitoring using websockets
Stars: ✭ 76 (-8.43%)
Mutual labels:  websocket
Ptt Client
A Node.js/Browser client for fetching data from ptt.cc
Stars: ✭ 78 (-6.02%)
Mutual labels:  websocket
Laplace
Laplace is an open-source project to enable screen sharing directly via browser. Based on WebRTC for low latency peer-to-peer connections, and WebSocket implemented in golang for signaling.
Stars: ✭ 81 (-2.41%)
Mutual labels:  websocket
Voten
The code that powers voten.co
Stars: ✭ 1,215 (+1363.86%)
Mutual labels:  websocket
Pystdf
Python module for working with STDF files
Stars: ✭ 74 (-10.84%)
Mutual labels:  test
Httpmock
HTTP mocking library for Rust.
Stars: ✭ 76 (-8.43%)
Mutual labels:  test
Deepspeech Websocket Server
Server & client for DeepSpeech using WebSockets for real-time speech recognition in separate environments
Stars: ✭ 79 (-4.82%)
Mutual labels:  websocket
Huobi golang
Go SDK for Huobi Spot API
Stars: ✭ 76 (-8.43%)
Mutual labels:  websocket
Noduino
JavaScript and Node.js Framework for controlling Arduino with HTML and WebSockets
Stars: ✭ 1,202 (+1348.19%)
Mutual labels:  websocket
Bilibili Live Ws
Bilibili live WebSocket/tcp API
Stars: ✭ 79 (-4.82%)
Mutual labels:  websocket
Just An Email
App to share files & texts between your devices without installing anything
Stars: ✭ 75 (-9.64%)
Mutual labels:  websocket
Angular Websocket
↖️ The missing Angular WebSocket module for connecting client applications to servers by @AngularClass
Stars: ✭ 1,242 (+1396.39%)
Mutual labels:  websocket
Websocketstream Explainer
Explainer for the WebSocketStream JavaScript API
Stars: ✭ 75 (-9.64%)
Mutual labels:  websocket
Bilibili danmuji
(Bilibili)B站直播礼物答谢、定时广告、关注感谢,自动回复工具,房管工具,自动打卡,Bilibili直播弹幕姬(使用websocket协议),java版B站弹幕姬,基于springboot。
Stars: ✭ 76 (-8.43%)
Mutual labels:  websocket
Protractor
E2E test framework for Angular apps
Stars: ✭ 8,792 (+10492.77%)
Mutual labels:  test
Testcafe
A Node.js tool to automate end-to-end web testing.
Stars: ✭ 9,176 (+10955.42%)
Mutual labels:  test

wstest

Build Status codecov GoDoc Go Report Card

A websocket client for unit-testing a websocket server

The gorilla organization provides full featured websocket implementation that the standard library lacks.

The standard library provides a httptest.ResponseRecorder struct that test an http.Handler without ListenAndServe, but is helpless when the connection is being hijacked by an http upgrader. As for testing websockets, it has the httptest.NewServer that actually listens on a socket on an arbitrary port.

This package provides a NewDialer function to test just the http.Handler that upgrades the connection to a websocket session. It runs the handler function in a goroutine without listening on any port. The returned websocket.Dialer then can be used to dial and communicate with the given handler.

Get

go get -u github.com/posener/wstest

Examples

See the example test.

An example how to modify a test function from using httptest.Server to use wstest.NewDialer function.

func TestHandler(t *testing.T) {
	var err error

	h := &myHandler{}
-	s := httptest.NewServer(h)
-	defer s.Close()
-	d := websocket.Dialer{}
+	d := wstest.NewDialer(h)

-	c, resp, err := d.Dial("ws://" + s.Listener.Addr().String() + "/ws", nil)
+	c, resp, err := d.Dial("ws://" + "whatever" + "/ws", nil)
	if err != nil {
		t.Fatal(err)
	}
	
	if got, want := resp.StatusCode, http.StatusSwitchingProtocols; got != want {
		t.Errorf("resp.StatusCode = %q, want %q", got, want)
	}
	
	err = c.WriteJSON("test")
	if err != nil {
		t.Fatal(err)
	}
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].