From 3c34db4c5ef03d4c27f3f2d188ef18d0396d3d2a Mon Sep 17 00:00:00 2001 From: Anmol Sethi <hi@nhooyr.io> Date: Sun, 1 Sep 2019 01:06:07 -0500 Subject: [PATCH] Small fixes --- websocket_autobahn_python_test.go | 3 +++ websocket_test.go | 15 +++++---------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/websocket_autobahn_python_test.go b/websocket_autobahn_python_test.go index 32ee1f5..0512c85 100644 --- a/websocket_autobahn_python_test.go +++ b/websocket_autobahn_python_test.go @@ -1,3 +1,6 @@ +// This file contains the old autobahn test suite tests that use the +// python binary. The approach is very clunky and slow so new tests +// have been written in pure Go in websocket_test.go. // +build autobahn-python package websocket_test diff --git a/websocket_test.go b/websocket_test.go index 979b092..ef6ae92 100644 --- a/websocket_test.go +++ b/websocket_test.go @@ -47,10 +47,7 @@ func TestHandshake(t *testing.T) { c.Close(websocket.StatusInternalError, "") return xerrors.New("expected error regarding bad origin") } - if !strings.Contains(err.Error(), "not authorized") { - return xerrors.Errorf("expected error regarding bad origin: %+v", err) - } - return nil + return assertErrorContains(err, "not authorized") }, client: func(ctx context.Context, u string) error { h := http.Header{} @@ -62,10 +59,7 @@ func TestHandshake(t *testing.T) { c.Close(websocket.StatusInternalError, "") return xerrors.New("expected handshake failure") } - if !strings.Contains(err.Error(), "403") { - return xerrors.Errorf("expected handshake failure: %+v", err) - } - return nil + return assertErrorContains(err, "403") }, }, { @@ -123,8 +117,9 @@ func TestHandshake(t *testing.T) { if err != nil { return xerrors.Errorf("request is missing mycookie: %w", err) } - if cookie.Value != "myvalue" { - return xerrors.Errorf("expected %q but got %q", "myvalue", cookie.Value) + err = assertEqualf("myvalue", cookie.Value, "unexpected cookie value") + if err != nil { + return err } c, err := websocket.Accept(w, r, nil) if err != nil { -- GitLab