- Install the github.com/gorilla/websocket and github.com/stretchr/testify/assert packages using the go get command, as follows:
$ go get github.com/gorilla/websocket$ go get github.com/stretchr/testify/assert
- Create websocket-server_test.go where we will create a test server, connect to it using the Gorilla client, and eventually read and write messages to test the connection, as follows:
package mainimport ( "net/http" "net/http/httptest" "strings" "testing" "github.com/gorilla/websocket" "github.com/stretchr/testify/assert")func TestWebSocketServer(t *testing.T) { server := httptest.NewServer(http.HandlerFunc (HandleClients)) defer server.Close() u := "ws" + strings.TrimPrefix(server.URL, "http") socket, _, err := websocket.DefaultDialer.Dial(u, ...