Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lixizan committed Jan 11, 2023
1 parent 5d65be6 commit 7ad9792
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ run-testsuite-server:
go run github.com/lxzan/gws/examples/testsuite

coverage:
go test -v $(go list ./... |grep -v /cmd |grep -v /vendor) -coverprofile=bin/coverage.out
go test -mod=readonly -covermode=count -coverprofile=./bin/coverprofile.cov -run="^Test" -coverpkg=$(go list -mod=vendor ./... | grep -v "/test" | tr '\n' ',') ./...

24 changes: 24 additions & 0 deletions examples/testsuite/config/readtest.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,30 @@
"reason": "68656c6c6f"
}
},
{
"title": "close with invalid code",
"fin": true,
"opcode": 8,
"length": 0,
"payload": "03f6",
"expected": {
"event": "onClose",
"code": 1014,
"reason": ""
}
},
{
"title": "close with code 0",
"fin": true,
"opcode": 8,
"length": 0,
"payload": "",
"expected": {
"event": "onClose",
"code": 0,
"reason": ""
}
},
{
"title": "close with invalid payload",
"fin": true,
Expand Down
19 changes: 19 additions & 0 deletions websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/http"
"sync"
"testing"
"time"
"unsafe"
)

Expand Down Expand Up @@ -219,3 +220,21 @@ func TestMask(t *testing.T) {
}
}
}

func TestConn(t *testing.T) {
conn, _ := net.Pipe()
socket := &Conn{
conn: conn,
handler: new(webSocketMocker),
wmu: &sync.Mutex{},
wbuf: bufio.NewWriter(bytes.NewBuffer(nil)),
}
socket.SetDeadline(time.Time{})
socket.SetReadDeadline(time.Time{})
socket.SetWriteDeadline(time.Time{})
socket.LocalAddr()
socket.RemoteAddr()
socket.Close(1000, []byte("goodbye"))
socket.Listen()
return
}

0 comments on commit 7ad9792

Please sign in to comment.