good morning!!!!

Skip to content
Snippets Groups Projects
ws_js_test.go 622 B
Newer Older
Anmol Sethi's avatar
Anmol Sethi committed
package websocket
Anmol Sethi's avatar
Anmol Sethi committed
import (
	"context"
	"net/http"
	"os"
	"testing"
	"time"
)

func TestEcho(t *testing.T) {
	t.Parallel()

	ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
	defer cancel()

Anmol Sethi's avatar
Anmol Sethi committed
	c, resp, err := Dial(ctx, os.Getenv("WS_ECHO_SERVER_URL"), &DialOptions{
		Subprotocols: []string{"echo"},
	})
	assert.Success(t, err)
Anmol Sethi's avatar
Anmol Sethi committed
	defer c.Close(StatusInternalError, "")

	assertSubprotocol(t, c, "echo")
	assert.Equalf(t, &http.Response{}, resp, "http.Response")
	echoJSON(t, ctx, c, 1024)
Anmol Sethi's avatar
Anmol Sethi committed
	assertEcho(t, ctx, c, MessageBinary, 1024)
Anmol Sethi's avatar
Anmol Sethi committed
	err = c.Close(StatusNormalClosure, "")
	assert.Success(t, err)
}