Browse Source

build: remove dep meta files, readd vendor directory

master
mappu 9 months ago
parent
commit
1c6e3b1c9d
61 changed files with 15 additions and 21485 deletions
  1. 0
    39
      Gopkg.lock
  2. 0
    30
      Gopkg.toml
  3. 0
    58
      vendor/code.ivysaur.me/libnmdc/Example_test.go
  4. 0
    97
      vendor/code.ivysaur.me/libnmdc/NmdcProtocol_test.go
  5. 0
    98
      vendor/code.ivysaur.me/libnmdc/__dist/README.txt
  6. 0
    36
      vendor/code.ivysaur.me/libnmdc/tth_test.go
  7. 0
    144
      vendor/github.com/cxmcc/tiger/tiger_test.go
  8. 0
    14
      vendor/github.com/googollee/go-engine.io/example/asset/index.html
  9. 0
    4137
      vendor/github.com/googollee/go-engine.io/example/asset/index.js
  10. 0
    5
      vendor/github.com/googollee/go-engine.io/example/asset/style.css
  11. 0
    60
      vendor/github.com/googollee/go-engine.io/example/main.go
  12. 0
    123
      vendor/github.com/googollee/go-engine.io/ioutil_test.go
  13. 0
    58
      vendor/github.com/googollee/go-engine.io/parser/limit_reader_test.go
  14. 0
    297
      vendor/github.com/googollee/go-engine.io/parser/packet_test.go
  15. 0
    212
      vendor/github.com/googollee/go-engine.io/parser/payload_test.go
  16. 0
    231
      vendor/github.com/googollee/go-engine.io/polling/polling_test.go
  17. 0
    507
      vendor/github.com/googollee/go-engine.io/polling/server_test.go
  18. 0
    47
      vendor/github.com/googollee/go-engine.io/polling/try_locker_test.go
  19. 0
    89
      vendor/github.com/googollee/go-engine.io/polling/writer_test.go
  20. 0
    377
      vendor/github.com/googollee/go-engine.io/server_conn_test.go
  21. 0
    92
      vendor/github.com/googollee/go-engine.io/server_test.go
  22. 0
    25
      vendor/github.com/googollee/go-engine.io/sessions_test.go
  23. 0
    458
      vendor/github.com/googollee/go-engine.io/websocket/websocket_test.go
  24. 0
    184
      vendor/github.com/googollee/go-socket.io/attachment_test.go
  25. 0
    38
      vendor/github.com/googollee/go-socket.io/example/asset/index.html
  26. 0
    10308
      vendor/github.com/googollee/go-socket.io/example/asset/jquery-1.11.1.js
  27. 0
    3
      vendor/github.com/googollee/go-socket.io/example/asset/socket.io-1.3.7.js
  28. 0
    53
      vendor/github.com/googollee/go-socket.io/example/main.go
  29. 0
    105
      vendor/github.com/googollee/go-socket.io/handler_test.go
  30. 0
    50
      vendor/github.com/googollee/go-socket.io/helper_test.go
  31. 0
    54
      vendor/github.com/googollee/go-socket.io/message_reader_test.go
  32. 0
    191
      vendor/github.com/googollee/go-socket.io/parser_test.go
  33. 0
    64
      vendor/github.com/googollee/go-socket.io/trim_writer_test.go
  34. 0
    512
      vendor/github.com/gorilla/websocket/client_server_test.go
  35. 0
    72
      vendor/github.com/gorilla/websocket/client_test.go
  36. 0
    80
      vendor/github.com/gorilla/websocket/compression_test.go
  37. 0
    134
      vendor/github.com/gorilla/websocket/conn_broadcast_test.go
  38. 0
    497
      vendor/github.com/gorilla/websocket/conn_test.go
  39. 0
    46
      vendor/github.com/gorilla/websocket/example_test.go
  40. 0
    13
      vendor/github.com/gorilla/websocket/examples/autobahn/README.md
  41. 0
    15
      vendor/github.com/gorilla/websocket/examples/autobahn/fuzzingclient.json
  42. 0
    265
      vendor/github.com/gorilla/websocket/examples/autobahn/server.go
  43. 0
    102
      vendor/github.com/gorilla/websocket/examples/chat/README.md
  44. 0
    137
      vendor/github.com/gorilla/websocket/examples/chat/client.go
  45. 0
    98
      vendor/github.com/gorilla/websocket/examples/chat/home.html
  46. 0
    53
      vendor/github.com/gorilla/websocket/examples/chat/hub.go
  47. 0
    40
      vendor/github.com/gorilla/websocket/examples/chat/main.go
  48. 0
    19
      vendor/github.com/gorilla/websocket/examples/command/README.md
  49. 0
    102
      vendor/github.com/gorilla/websocket/examples/command/home.html
  50. 0
    193
      vendor/github.com/gorilla/websocket/examples/command/main.go
  51. 0
    17
      vendor/github.com/gorilla/websocket/examples/echo/README.md
  52. 0
    81
      vendor/github.com/gorilla/websocket/examples/echo/client.go
  53. 0
    132
      vendor/github.com/gorilla/websocket/examples/echo/server.go
  54. 0
    9
      vendor/github.com/gorilla/websocket/examples/filewatch/README.md
  55. 0
    193
      vendor/github.com/gorilla/websocket/examples/filewatch/main.go
  56. 0
    119
      vendor/github.com/gorilla/websocket/json_test.go
  57. 0
    73
      vendor/github.com/gorilla/websocket/mask_test.go
  58. 0
    74
      vendor/github.com/gorilla/websocket/prepared_test.go
  59. 0
    51
      vendor/github.com/gorilla/websocket/server_test.go
  60. 0
    74
      vendor/github.com/gorilla/websocket/util_test.go
  61. 15
    0
      vendor/modules.txt

+ 0
- 39
Gopkg.lock View File

@@ -1,39 +0,0 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.


[[projects]]
name = "code.ivysaur.me/libnmdc"
packages = ["."]
revision = "a23cc9e61d24bb9b16b1126bdddd514e01d64792"
version = "v0.16.0"

[[projects]]
branch = "master"
name = "github.com/cxmcc/tiger"
packages = ["."]
revision = "bde35e2713d7f674987c2ecb21a6b0fc33749516"

[[projects]]
branch = "master"
name = "github.com/googollee/go-engine.io"
packages = [".","message","parser","polling","transport","websocket"]
revision = "80ae0e43aca17b4c5a6834999d0f2eaa16b9afda"

[[projects]]
branch = "master"
name = "github.com/googollee/go-socket.io"
packages = ["."]
revision = "5447e71f36d394766bf855d5714a487596809f0d"

[[projects]]
name = "github.com/gorilla/websocket"
packages = ["."]
revision = "ea4d1f681babbce9545c9c5f3d5194a789c89f5b"
version = "v1.2.0"

[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "7ac2438222289730d49b803fd1c631629921f95fd406c3154a54d34e11fb6947"
solver-name = "gps-cdcl"
solver-version = 1

+ 0
- 30
Gopkg.toml View File

@@ -1,30 +0,0 @@

# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"


[[constraint]]
name = "code.ivysaur.me/libnmdc"
version = "0.16.0"

[[constraint]]
branch = "master"
name = "github.com/googollee/go-socket.io"

+ 0
- 58
vendor/code.ivysaur.me/libnmdc/Example_test.go View File

@@ -1,58 +0,0 @@
package libnmdc
import (
"fmt"
)
func ExampleHubConnectionOptions_Connect() {
opts := HubConnectionOptions{
Address: "127.0.0.1",
Self: NewUserInfo("slowpoke9"),
}
events := make(chan HubEvent, 0)
hub := ConnectAsync(&opts, events)
for event := range events {
switch event.EventType {
case EVENT_CONNECTION_STATE_CHANGED:
fmt.Printf("Connection -- %s (%s)\n", event.StateChange, event.Message)
case EVENT_PUBLIC:
fmt.Printf("Message from '%s': '%s'\n", event.Nick, event.Message)
if event.Message == "how are you" {
hub.SayPublic("good thanks!")
}
default:
fmt.Printf("%+v\n", event)
}
}
}
func ExampleHubConnectionOptions_ConnectSync() {
cb := func(hub *HubConnection, event HubEvent) {
switch event.EventType {
case EVENT_CONNECTION_STATE_CHANGED:
fmt.Printf("Connection -- %s (%s)\n", event.StateChange, event.Message)
case EVENT_PUBLIC:
fmt.Printf("Message from '%s': '%s'\n", event.Nick, event.Message)
if event.Message == "how are you" {
hub.SayPublic("good thanks!")
}
default:
fmt.Printf("%+v\n", event)
}
}
opts := HubConnectionOptions{
Address: "127.0.0.1",
Self: NewUserInfo("slowpoke9"),
}
ConnectSync(&opts, cb) // blocking
}

+ 0
- 97
vendor/code.ivysaur.me/libnmdc/NmdcProtocol_test.go View File

@@ -1,97 +0,0 @@
package libnmdc

import (
"testing"
)

func TestMyINFOParse(t *testing.T) {

np := NewNmdcProtocol(nil).(*NmdcProtocol)

type myInfoTestPair struct {
in string
expect UserInfo
}

cases := []myInfoTestPair{

myInfoTestPair{
in: "$ALL Bxxxy description<ApexDC++ V:1.4.3,M:P,H:9/0/2,S:1>$ $0.01\x01$xyz@example.com$53054999578$",
expect: UserInfo{
Nick: "Bxxxy",
Description: "description",
ClientTag: "ApexDC++",
ClientVersion: "1.4.3",
Email: "xyz@example.com",
ShareSize: 53054999578,
Flag: FLAG_NORMAL,
Slots: 1,
HubsUnregistered: 9,
HubsRegistered: 0,
HubsOperator: 2,
UserInfo_NMDCOnly: UserInfo_NMDCOnly{
ConnectionMode: CONNECTIONMODE_PASSIVE,
Speed: "0.0",
},
},
},
myInfoTestPair{
in: "$ALL ixxxxxxx0 $P$10A$$0$",
expect: UserInfo{
Nick: "ixxxxxxx0",
ClientVersion: "0", // Auto-inserted by the parser for short-format MyINFO strings
Flag: UserFlag(rune('A')),
UserInfo_NMDCOnly: UserInfo_NMDCOnly{
ConnectionMode: CONNECTIONMODE_PASSIVE,
Speed: "1",
},
},
},
myInfoTestPair{
in: "$ALL SXXXX_XXXXXXR <ncdc V:1.19.1-12-g5561,M:P,H:1/0/0,S:10>$ $0.005Q$$0$",
expect: UserInfo{
Nick: "SXXXX_XXXXXXR",
ClientTag: "ncdc",
ClientVersion: "1.19.1-12-g5561",
Flag: UserFlag(rune('Q')),
Slots: 10,
HubsUnregistered: 1,
UserInfo_NMDCOnly: UserInfo_NMDCOnly{
ConnectionMode: CONNECTIONMODE_PASSIVE,
Speed: "0.00",
},
},
},
myInfoTestPair{
in: "$ALL mxxxu desccccc<HexChat V:2.12.1,M:P,H:1/0/0,S:0>$ $p$$0$",
expect: UserInfo{
Nick: "mxxxu",
Description: "desccccc",
ClientTag: "HexChat",
ClientVersion: "2.12.1",
Flag: UserFlag(rune('p')),
HubsUnregistered: 1,
Slots: 0,
UserInfo_NMDCOnly: UserInfo_NMDCOnly{
ConnectionMode: CONNECTIONMODE_PASSIVE,
},
},
},
}

for _, v := range cases {

got, err := np.parseMyINFO(v.in)

if err != nil {
t.Errorf("MyINFO parse warning (%s)", err.Error())
continue
}

if *got != v.expect {
t.Errorf("MyINFO parse failure\nExpected:\n%+v\nGot:\n%+v\n", v.expect, got)
continue
}
}

}

+ 0
- 98
vendor/code.ivysaur.me/libnmdc/__dist/README.txt View File

@@ -1,98 +0,0 @@
An NMDC / ADC client protocol library for Golang.

Written in golang
Tags: nmdc

=FEATURES=

- Connect to NMDC and ADC hubs
- SSL (NMDCS/ADCS) with option to ignore certificate validity
- Autodetect NMDC/ADC protocol by timeout
- Send public and private chat messages, UserCommand support
- Protocol keepalives
- Parse user details (including UserIP2 for NMDC)
- Fast NMDC login via NoHello and QuickList
- Both synchronous (callback) and asynchronous (channel) -based APIs, including example

=GO GET=

This package can be installed via go get: `go get code.ivysaur.me/libnmdc`
[go-get]code.ivysaur.me/libnmdc git https://git.ivysaur.me/code.ivysaur.me/libnmdc.git[/go-get]

=CHANGELOG=

2017-11-26 0.16
- Feature: Support connecting to ADC hubs
- BREAKING: Simplify connection API
- Vendor new dependency on github.com/cxmcc/tiger (MIT license)

2017-11-14 0.15
- Feature: Fallback reconnection if no data (not even keepalives) are recieved from the hub in 24 hours
- Fix an issue with detecting protocol messages inside multi-line chat messages
- Update examples and the default client version number

2017-02-09 0.14
- Fix an issue with crashing on malformed IP addresses supplied by the hub

2017-02-09 0.13
- Feature: Implement UserIP2 extension, to retrieve IP addresses of other users
- Enhancement: Implement QuickList extension (reduce one network roundtrip during initial connection)
- Enhancement: Implement NoHello extension (faster connection performance)
- Enhancement: Implement ChatOnly extension
- Fix an issue with not notifying client on all MyINFO updates

2017-02-05 0.12
- Fix an issue with mutex deadlock when accessing user information from a callback
- Fix an issue with silent disconnection if a password was required but not present

2016-11-29 0.11
- BREAKING: Remove some exported methods
- BREAKING: Fix an issue with missing sufficient parameters in the synchronous API
- Enhancement: Improve output under godoc
- Fix an issue with special characters appearing in recieved private messages
- Fix an issue with parsing active/passive connection modes
- Fix an issue with errors appearing on stdout

2016-10-08 r10
- Feature: Support `$UserCommand`

2016-08-27 r9
- Fix an issue with parsing MyINFO strings with zero-length speed descriptions
- Fix an issue with not storing updated profile information

2016-05-10 r8
- Enhancement: Separate `ClientTag` and `ClientVersion` in `UserInfo` structs

2016-05-08 r7
- BREAKING: Remove direct access to `HubConnection.Users` map
- Feature: Threadsafe user map accessor
- Feature: Option to disable auto-reconnection
- Feature: New `Disconnect()`, `UserCount()`, `UserExists()` functions
- Enhancement: Support `$OpList`, add `IsOperator` member to `UserInfo` structs
- Refactor into multiple files

2016-04-16 r6
- Fix an issue with calling `panic()` on certain types of abnormal network failure

2016-04-04 r5
- Enhancement: Support protocol keepalives
- Enhancement: Support hub redirects (`$ForceMove`)

2016-04-03 r4
- Feature: Add synchronous API
- Fix an issue with reading HubConnection's state parameter
- Fix an issue with buffered protocol commands

2016-04-03 r3
- Feature: Add `SkipVerifyTLS` option
- Fix an issue with calling `panic()` if connection failed

2016-04-02 r2
- Enhancement: Support NMDC-over-TLS (NMDCS)
- Fix an issue recieving private messages
- Fix an issue with calling `panic()` if connection failed
- Fix an issue parsing URIs without a specified port
- Move sample content into directory with excluded build

2016-02-12 r1
- Initial public release

+ 0
- 36
vendor/code.ivysaur.me/libnmdc/tth_test.go View File

@@ -1,36 +0,0 @@
package libnmdc

import (
"strings"
"testing"
)

func TestTTH(t *testing.T) {

// echo -n 'hello world' | tthsum
testCases := [][2]string{
[2]string{"hello world", "ZIIVRZDR2FD3W4KKNMNYUU3765LPPK7BWY64CHI"},
[2]string{"", "LWPNACQDBZRYXW3VHJVCJ64QBZNGHOHHHZWCLNQ"},
[2]string{"\x00", "VK54ZIEEVTWNAUI5D5RDFIL37LX2IQNSTAXFKSA"},
[2]string{strings.Repeat("A", 1024), "L66Q4YVNAFWVS23X2HJIRA5ZJ7WXR3F26RSASFA"},
}

short := func(s string) string {
if len(s) > 15 {
return s[0:15] + "..."
}
return s
}

for _, testCase := range testCases {
input, expected := testCase[0], testCase[1]
result, err := TTH(input)
if err != nil {
t.Fatalf("Error getting TTH for '%s': %s", short(input), err.Error())
}

if Base32(result) != expected {
t.Fatalf("Wrong TTH for '%s' (got '%s' expected '%s')", short(input), result, expected)
}
}
}

+ 0
- 144
vendor/github.com/cxmcc/tiger/tiger_test.go View File

@@ -1,144 +0,0 @@
package tiger

import (
"fmt"
"io"
"strings"
"testing"
"unsafe"
)

type Test struct {
out string
in string
}

var golden = []Test{
{"3293ac630c13f0245f92bbb1766e16167a4e58492dde73f3", ""},
{"77befbef2e7ef8ab2ec8f93bf587a7fc613e247f5f247809", "a"},
{"2aab1484e8c158f2bfb8c5ff41b57a525129131c957b5f93", "abc"},
{"d981f8cb78201a950dcf3048751e441c517fca1aa55a29f6", "message digest"},
{"1714a472eee57d30040412bfcc55032a0b11602ff37beee9", "abcdefghijklmnopqrstuvwxyz"},
{"0f7bf9a19b9c58f2b7610df7e84f0ac3a71c631e7b53f78e", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"},
{"8dcea680a17583ee502ba38a3c368651890ffbccdc49a8cc", "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"},
{"1c14795529fd9f207a958f84c52f11e887fa0cabdfd91bfd", "12345678901234567890123456789012345678901234567890123456789012345678901234567890"},
{"cdf0990c5c6b6b0bddd63a75ed20e2d448bf44e15fde0df4", strings.Repeat("A", 1024)},
{"89292aee0f82842abc080c57b3aadd9ca84d66bf0cae77aa", strings.Repeat("A", 1025)},
}

func TestGolden(t *testing.T) {
for i := 0; i < len(golden); i++ {
g := golden[i]
c := New()
buf := make([]byte, len(g.in)+4)
for j := 0; j < 7; j++ {
if j < 2 {
io.WriteString(c, g.in)
} else if j == 2 {
io.WriteString(c, g.in[0:len(g.in)/2])
c.Sum(nil)
io.WriteString(c, g.in[len(g.in)/2:])
} else if j > 2 {
// test unaligned write
buf = buf[1:]
copy(buf, g.in)
c.Write(buf[:len(g.in)])
}
s := fmt.Sprintf("%x", c.Sum(nil))
if s != g.out {
t.Fatalf("tiger[%d](%s) = %s want %s", j, g.in, s, g.out)
}
c.Reset()
}
}
}

type WriteTest struct {
out int
in string
}

var writeTestVectors = []WriteTest{
{0, ""},
{1, "A"},
{2, "AA"},
{10, strings.Repeat("A", 10)},
{1024, strings.Repeat("A", 1024)},
{1025, strings.Repeat("A", 1025)},
{0, ""},
}

func TestWriteReturnsCorrectSize(t *testing.T) {
c := New()
for i := 0; i < len(writeTestVectors); i++ {
v := writeTestVectors[i]
b := []byte(v.in)
length, err := c.Write(b[:len(v.in)])
if length != v.out {
t.Fatalf("Write() = %d want %d", length, v.out)
}
if err != nil {
t.Fatalf("Write(%s) failed.", v.in)
}
}
}

func ExampleNew() {
h := New()
io.WriteString(h, "It's the eye of the tiger, it's the thrill of the fight")
io.WriteString(h, "Rising up to the challenge of our rival!")
fmt.Printf("%x", h.Sum(nil))
// Output: a7bbad36cc17918e399ae8ee893e4595e4d24e1639fe822c
}

func ExampleNew2() {
h := New2()
io.WriteString(h, "It's the eye of the tiger, it's the thrill of the fight")
io.WriteString(h, "Rising up to the challenge of our rival!")
fmt.Printf("%x", h.Sum(nil))
// Output: c86695c2a639506682de2c12c2d23b61a12db78ea1ee1001
}

var bench = New()
var buf = make([]byte, 8192+1)
var sum = make([]byte, bench.Size())

func benchmarkSize(b *testing.B, size int, unaligned bool) {
b.SetBytes(int64(size))
buf := buf
if unaligned {
if uintptr(unsafe.Pointer(&buf[0]))&(unsafe.Alignof(uint32(0))-1) == 0 {
buf = buf[1:]
}
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
bench.Reset()
bench.Write(buf[:size])
bench.Sum(sum[:0])
}
}

func BenchmarkHash8Bytes(b *testing.B) {
benchmarkSize(b, 8, false)
}

func BenchmarkHash1K(b *testing.B) {
benchmarkSize(b, 1024, false)
}

func BenchmarkHash8K(b *testing.B) {
benchmarkSize(b, 8192, false)
}

func BenchmarkHash8BytesUnaligned(b *testing.B) {
benchmarkSize(b, 8, true)
}

func BenchmarkHash1KUnaligned(b *testing.B) {
benchmarkSize(b, 1024, true)
}

func BenchmarkHash8KUnaligned(b *testing.B) {
benchmarkSize(b, 8192, true)
}

+ 0
- 14
vendor/github.com/googollee/go-engine.io/example/asset/index.html View File

@@ -1,14 +0,0 @@
<!doctype html>
<html>
<head>
<title>EIO Latency</title>
<link rel="stylesheet" href="/style.css" />
</head>
<body>
<h1>EIO Latency <span id="latency"></span></h1>
<h2 id="transport">(connecting)</h2>
<canvas id="chart" height="200"></canvas>

<script src="/index.js"></script>
</body>
</html>

+ 0
- 4137
vendor/github.com/googollee/go-engine.io/example/asset/index.js
File diff suppressed because it is too large
View File


+ 0
- 5
vendor/github.com/googollee/go-engine.io/example/asset/style.css View File

@@ -1,5 +0,0 @@

body { margin: 0; padding: 0; font-family: Helvetica Neue; }
h1 { margin: 100px 100px 10px; }
h2 { color: #999; margin: 0 100px 30px; font-weight: normal; }
#latency { color: red; }

+ 0
- 60
vendor/github.com/googollee/go-engine.io/example/main.go View File

@@ -1,60 +0,0 @@
package main

import (
"encoding/hex"
"io/ioutil"
"log"
"net/http"
"time"

"github.com/googollee/go-engine.io"
)

func main() {
server, err := engineio.NewServer(nil)
if err != nil {
log.Fatal(err)
}
server.SetPingInterval(time.Second * 2)
server.SetPingTimeout(time.Second * 3)

go func() {
for {
conn, _ := server.Accept()
go func() {
log.Println("connected:", conn.Id())
defer func() {
conn.Close()
log.Println("disconnected:", conn.Id())
}()
for {
t, r, err := conn.NextReader()
if err != nil {
return
}
b, err := ioutil.ReadAll(r)
if err != nil {
return
}
r.Close()
if t == engineio.MessageText {
log.Println(t, string(b))
} else {
log.Println(t, hex.EncodeToString(b))
}
w, err := conn.NextWriter(t)
if err != nil {
return
}
w.Write([]byte("pong"))
w.Close()
}
}()
}
}()

http.Handle("/engine.io/", server)
http.Handle("/", http.FileServer(http.Dir("./asset")))
log.Println("Serving at localhost:4000...")
log.Fatal(http.ListenAndServe(":4000", nil))
}

+ 0
- 123
vendor/github.com/googollee/go-engine.io/ioutil_test.go View File

@@ -1,123 +0,0 @@
package engineio

import (
"bytes"
"github.com/googollee/go-engine.io/parser"
"io"
"sync"
"testing"
"time"

. "github.com/smartystreets/goconvey/convey"
)

func TestConnIoutil(t *testing.T) {

Convey("Reader", t, func() {
Convey("Normal read", func() {
r := bytes.NewBufferString("\x34\xe6\xb5\x8b\xe8\xaf\x95")
decoder, err := parser.NewDecoder(r)
So(err, ShouldBeNil)

closeChan := make(chan struct{})
reader := newConnReader(decoder, closeChan)
b := make([]byte, 1024)
n, err := reader.Read(b)
So(err, ShouldBeNil)
So(string(b[:n]), ShouldEqual, "测试")
n, err = reader.Read(b)
So(err, ShouldEqual, io.EOF)

Convey("Wait close", func() {
check := make(chan int)
go func() {
err := reader.Close()
if err != nil {
t.Fatal(err)
}
check <- 1
}()

time.Sleep(time.Second / 10) // wait goroutine start
select {
case <-check:
So("should not run here", ShouldEqual, "")
default:
}
<-closeChan
time.Sleep(time.Second / 10) // wait goroutine end
select {
case <-check:
default:
So("should not run here", ShouldEqual, "")
}

Convey("Close again", func() {
err := reader.Close()
So(err, ShouldBeNil)
})
})
})
})

Convey("Wrtier", t, func() {

Convey("Normal write", func() {
locker := sync.Mutex{}
w := bytes.NewBuffer(nil)
locker.Lock()
writer := newConnWriter(writeCloser{w}, &locker)

_, err := writer.Write([]byte("abc"))
So(err, ShouldBeNil)
So(w.String(), ShouldEqual, "abc")
writer.Close()
})

Convey("Sync", func() {
locker := sync.Mutex{}
w1 := bytes.NewBuffer(nil)
locker.Lock()
writer1 := newConnWriter(writeCloser{w1}, &locker)
check := make(chan int)

go func() {
w2 := bytes.NewBuffer(nil)
locker.Lock()
writer2 := newConnWriter(writeCloser{w2}, &locker)
defer writer2.Close()
check <- 1
}()

time.Sleep(time.Second / 10)
select {
case <-check:
So("should not run here", ShouldEqual, "")
default:
}
err := writer1.Close()
So(err, ShouldBeNil)
time.Sleep(time.Second / 10) // wait goroutine end
select {
case <-check:
default:
So("should not run here", ShouldEqual, "")
}

Convey("Close again", func() {
err := writer1.Close()
So(err, ShouldBeNil)
})
})

})

}

type writeCloser struct {
io.Writer
}

func (w writeCloser) Close() error {
return nil
}

+ 0
- 58
vendor/github.com/googollee/go-engine.io/parser/limit_reader_test.go View File

@@ -1,58 +0,0 @@
package parser

import (
"bytes"
"errors"
"io"
"testing"

. "github.com/smartystreets/goconvey/convey"
)

func TestLimitReader(t *testing.T) {

Convey("Read to limit", t, func() {
b := bytes.NewBufferString("1234567890")
r := newLimitReader(b, 5)
p := make([]byte, 1024)
n, err := r.Read(p)
So(err, ShouldBeNil)
So(string(p[:n]), ShouldEqual, "12345")
n, err = r.Read(p)
So(err, ShouldEqual, io.EOF)
err = r.Close()
So(err, ShouldBeNil)
So(b.String(), ShouldEqual, "67890")
})

Convey("Read some and close", t, func() {
b := bytes.NewBufferString("1234567890")
r := newLimitReader(b, 5)
p := make([]byte, 3)
n, err := r.Read(p)
So(err, ShouldBeNil)
So(string(p[:n]), ShouldEqual, "123")
err = r.Close()
So(err, ShouldBeNil)
So(b.String(), ShouldEqual, "67890")
err = r.Close()
So(err, ShouldBeNil)
})

Convey("Close with error", t, func() {
er := errorReader{}
r := newLimitReader(er, 5)
err := r.Close()
So(err, ShouldNotBeNil)
})
}

type errorReader struct{}

func (r errorReader) Read(p []byte) (int, error) {
return 0, errors.New("error")
}

func (r errorReader) Close() error {
return errors.New("error")
}

+ 0
- 297
vendor/github.com/googollee/go-engine.io/parser/packet_test.go View File

@@ -1,297 +0,0 @@
package parser

import (
"bytes"
"io"
"testing"

"github.com/googollee/go-engine.io/message"
. "github.com/smartystreets/goconvey/convey"
)

func TestPacketType(t *testing.T) {

Convey("Byte to type", t, func() {

Convey("Open", func() {
t, err := ByteToType(0)
So(err, ShouldBeNil)
So(t, ShouldEqual, OPEN)
})

Convey("Close", func() {
t, err := ByteToType(1)
So(err, ShouldBeNil)
So(t, ShouldEqual, CLOSE)
})

Convey("Ping", func() {
t, err := ByteToType(2)
So(err, ShouldBeNil)
So(t, ShouldEqual, PING)
})

Convey("Pong", func() {
t, err := ByteToType(3)
So(err, ShouldBeNil)
So(t, ShouldEqual, PONG)
})

Convey("Message", func() {
t, err := ByteToType(4)
So(err, ShouldBeNil)
So(t, ShouldEqual, MESSAGE)
})

Convey("Upgrade", func() {
t, err := ByteToType(5)
So(err, ShouldBeNil)
So(t, ShouldEqual, UPGRADE)
})

Convey("Noop", func() {
t, err := ByteToType(6)
So(err, ShouldBeNil)
So(t, ShouldEqual, NOOP)
})

Convey("Error", func() {
_, err := ByteToType(7)
So(err, ShouldNotBeNil)
})

})

Convey("Type to byte", t, func() {

Convey("Open", func() {
So(OPEN.Byte(), ShouldEqual, 0)
})

Convey("Close", func() {
So(CLOSE.Byte(), ShouldEqual, 1)
})

Convey("Ping", func() {
So(PING.Byte(), ShouldEqual, 2)
})

Convey("Pong", func() {
So(PONG.Byte(), ShouldEqual, 3)
})

Convey("Message", func() {
So(MESSAGE.Byte(), ShouldEqual, 4)
})

Convey("Upgrade", func() {
So(UPGRADE.Byte(), ShouldEqual, 5)
})

Convey("Noop", func() {
So(NOOP.Byte(), ShouldEqual, 6)
})

})

}

func TestStringParser(t *testing.T) {
type Test struct {
name string
t PacketType
data []byte
output string
}
var tests = []Test{
{"without data", OPEN, nil, "0"},
{"with data", MESSAGE, []byte("测试"), "\x34\xe6\xb5\x8b\xe8\xaf\x95"},
}

for _, test := range tests {
buf := bytes.NewBuffer(nil)

Convey("Given a packet type "+test.name, t, func() {

Convey("Create encoder", func() {
encoder, err := NewStringEncoder(buf, test.t)
So(err, ShouldBeNil)
So(encoder, ShouldImplement, (*io.WriteCloser)(nil))

Convey("Encoded", func() {
for d := test.data; len(d) > 0; {
n, err := encoder.Write(d)
So(err, ShouldBeNil)
d = d[n:]
}

Convey("End", func() {
err := encoder.Close()
So(err, ShouldBeNil)
So(buf.String(), ShouldEqual, test.output)
})
})
})

Convey("Create decoder", func() {
decoder, err := NewDecoder(buf)
So(err, ShouldBeNil)
So(decoder, ShouldImplement, (*io.ReadCloser)(nil))
So(decoder.MessageType(), ShouldEqual, message.MessageText)

Convey("Decoded", func() {
So(decoder.Type(), ShouldEqual, test.t)

decoded := make([]byte, len(test.data)+1)
n, err := decoder.Read(decoded)
if n > 0 {
So(err, ShouldBeNil)
So(decoded[:n], ShouldResemble, test.data)
}

Convey("End", func() {
_, err := decoder.Read(decoded[:])
So(err, ShouldEqual, io.EOF)
})
})
})
})
}
}

func TestBinaryParser(t *testing.T) {
type Test struct {
name string
t PacketType
data []byte
output string
}
var tests = []Test{
{"without data", OPEN, nil, "\x00"},
{"with data", MESSAGE, []byte("测试"), "\x04\xe6\xb5\x8b\xe8\xaf\x95"},
}
for _, test := range tests {
buf := bytes.NewBuffer(nil)

Convey("Given a packet type "+test.name, t, func() {

Convey("Create Encoder", func() {
encoder, err := NewBinaryEncoder(buf, test.t)
So(err, ShouldBeNil)
So(encoder, ShouldImplement, (*io.WriteCloser)(nil))

Convey("Encoded", func() {
for d := test.data; len(d) > 0; {
n, err := encoder.Write(d)
So(err, ShouldBeNil)
d = d[n:]
}

Convey("End", func() {
err := encoder.Close()
So(err, ShouldBeNil)
So(buf.String(), ShouldEqual, test.output)
})
})
})

Convey("Create decoder", func() {
decoder, err := NewDecoder(buf)
So(err, ShouldBeNil)
So(decoder, ShouldImplement, (*io.ReadCloser)(nil))
So(decoder.MessageType(), ShouldEqual, message.MessageBinary)

Convey("Decoded", func() {
So(decoder.Type(), ShouldEqual, test.t)
decoded := make([]byte, len(test.data)+1)
n, err := decoder.Read(decoded[:])
if n > 0 {
So(err, ShouldBeNil)
So(decoded[:n], ShouldResemble, test.data)
}

Convey("End", func() {
_, err := decoder.Read(decoded[:])
So(err, ShouldEqual, io.EOF)
})
})
})

})
}
}

func TestBase64Parser(t *testing.T) {
type Test struct {
name string
t PacketType
data []byte
output string
}
var tests = []Test{
{"without data", OPEN, nil, "b0"},
{"with data", MESSAGE, []byte("测试"), "b45rWL6K+V"},
}
for _, test := range tests {
buf := bytes.NewBuffer(nil)

Convey("Given a packet type "+test.name, t, func() {

Convey("Create Encoder", func() {
encoder, err := NewB64Encoder(buf, test.t)
So(err, ShouldBeNil)
So(encoder, ShouldImplement, (*io.WriteCloser)(nil))

Convey("Encoded", func() {
for d := test.data; len(d) > 0; {
n, err := encoder.Write(d)
So(err, ShouldBeNil)
d = d[n:]
}

Convey("End", func() {
err := encoder.Close()
So(err, ShouldBeNil)
So(buf.String(), ShouldEqual, test.output)
})
})
})

Convey("Create decoder", func() {
decoder, err := NewDecoder(buf)
So(err, ShouldBeNil)
So(decoder, ShouldImplement, (*io.ReadCloser)(nil))
So(decoder.MessageType(), ShouldEqual, message.MessageBinary)

Convey("Decoded", func() {
So(decoder.Type(), ShouldEqual, test.t)
decoded := make([]byte, len(test.data)+1)
n, err := decoder.Read(decoded[:])
if n > 0 {
So(err, ShouldBeNil)
So(decoded[:n], ShouldResemble, test.data)
}

Convey("End", func() {
_, err := decoder.Read(decoded[:])
So(err, ShouldEqual, io.EOF)
})
})
})

})
}
}

func TestLimitReaderDecoder(t *testing.T) {
Convey("Test decoder with limit reader", t, func() {
buf := bytes.NewBufferString("\x34\xe6\xb5\x8b\xe8\xaf\x95123")
reader := newLimitReader(buf, 7)
decoder, err := NewDecoder(reader)
So(err, ShouldBeNil)
So(decoder.Type(), ShouldEqual, MESSAGE)
err = decoder.Close()
So(err, ShouldBeNil)
So(buf.String(), ShouldEqual, "123")
})
}

+ 0
- 212
vendor/github.com/googollee/go-engine.io/parser/payload_test.go View File

@@ -1,212 +0,0 @@
package parser

import (
"bytes"
"io"
"runtime"
"testing"

. "github.com/smartystreets/goconvey/convey"
)

func TestStringPayload(t *testing.T) {
type packet struct {
Type PacketType
Data []byte
IsString bool
}
type Test struct {
name string
packets []packet
output string
}
var tests = []Test{
{"all in one", []packet{packet{OPEN, nil, true}, packet{MESSAGE, []byte("测试"), true}, packet{MESSAGE, []byte("测试"), false}}, "\x31\x3a\x30\x37\x3a\x34\xe6\xb5\x8b\xe8\xaf\x95\x31\x30\x3a\x62\x34\x35\x72\x57\x4c\x36\x4b\x2b\x56"},
}
for _, test := range tests {
buf := bytes.NewBuffer(nil)

Convey("Given an array of packet "+test.name, t, func() {

Convey("Create encoder", func() {
encoder := NewStringPayloadEncoder()
So(encoder.IsString(), ShouldBeTrue)

Convey("Encoded", func() {
for _, p := range test.packets {
var e io.WriteCloser
var err error
if p.IsString {
e, err = encoder.NextString(p.Type)
} else {
e, err = encoder.NextBinary(p.Type)
}
So(err, ShouldBeNil)
for d := p.Data; len(d) > 0; {
n, err := e.Write(d)
So(err, ShouldBeNil)
d = d[n:]
}
err = e.Close()
So(err, ShouldBeNil)
}

Convey("End", func() {
err := encoder.EncodeTo(buf)
So(err, ShouldBeNil)
So(buf.String(), ShouldEqual, test.output)
})
})
})

Convey("Create decoder", func() {
decoder := NewPayloadDecoder(buf)

Convey("Decode", func() {
for i := 0; ; i++ {
d, err := decoder.Next()
if err == io.EOF {
break
}
So(err, ShouldBeNil)
So(d.Type(), ShouldEqual, test.packets[i].Type)

if l := len(test.packets[i].Data); l > 0 {
buf := make([]byte, len(test.packets[i].Data)+1)
n, err := d.Read(buf)
if n > 0 {
So(err, ShouldBeNil)
So(buf[:n], ShouldResemble, test.packets[i].Data)
}
_, err = d.Read(buf)
So(err, ShouldEqual, io.EOF)
}
err = d.Close()
So(err, ShouldBeNil)
}
})
})
})
}
}

func TestBinaryPayload(t *testing.T) {
type packet struct {
Type PacketType
Data []byte
IsString bool
}
type Test struct {
name string
packets []packet
output string
}
var tests = []Test{
{"all in one", []packet{packet{OPEN, nil, true}, packet{MESSAGE, []byte("测试"), true}, packet{MESSAGE, []byte("测试"), false}}, "\x00\x01\xff\x30\x00\x07\xff\x34\xe6\xb5\x8b\xe8\xaf\x95\x01\x07\xff\x04\xe6\xb5\x8b\xe8\xaf\x95"},
}
for _, test := range tests {
buf := bytes.NewBuffer(nil)

Convey("Given an array of packet "+test.name, t, func() {

Convey("Create encoder", func() {
encoder := NewBinaryPayloadEncoder()
So(encoder.IsString(), ShouldBeFalse)

Convey("Encoded", func() {
for _, p := range test.packets {
var e io.WriteCloser
var err error
if p.IsString {
e, err = encoder.NextString(p.Type)
} else {
e, err = encoder.NextBinary(p.Type)
}
So(err, ShouldBeNil)
for d := p.Data; len(d) > 0; {
n, err := e.Write(d)
So(err, ShouldBeNil)
d = d[n:]
}
err = e.Close()
So(err, ShouldBeNil)
}

Convey("End", func() {
err := encoder.EncodeTo(buf)
So(err, ShouldBeNil)
So(buf.String(), ShouldEqual, test.output)
})
})
})

Convey("Create decoder", func() {
decoder := NewPayloadDecoder(buf)

Convey("Decode", func() {
for i := 0; ; i++ {
d, err := decoder.Next()
if err == io.EOF {
break
}
So(err, ShouldBeNil)
So(d.Type(), ShouldEqual, test.packets[i].Type)

if l := len(test.packets[i].Data); l > 0 {
buf := make([]byte, len(test.packets[i].Data)+1)
n, err := d.Read(buf)
if n > 0 {
So(err, ShouldBeNil)
So(buf[:n], ShouldResemble, test.packets[i].Data)
}
_, err = d.Read(buf)
So(err, ShouldEqual, io.EOF)
}
err = d.Close()
So(err, ShouldBeNil)
}
})
})
})
}
}

func TestParallelEncode(t *testing.T) {
prev := runtime.GOMAXPROCS(10)
defer runtime.GOMAXPROCS(prev)

Convey("Test parallel encode", t, func() {
c := make(chan int)
max := 1000
buf1 := bytes.NewBuffer(nil)
buf2 := bytes.NewBuffer(nil)
encoder := NewStringPayloadEncoder()
for i := 0; i < max; i++ {
go func() {
e, _ := encoder.NextString(MESSAGE)
e.Write([]byte("1234"))
e.Close()
c <- 1
}()
}
for i := 0; i < max/2; i++ {
<-c
}
err := encoder.EncodeTo(buf1)
So(err, ShouldBeNil)
for i := 0; i < max/2; i++ {
<-c
}
err = encoder.EncodeTo(buf2)
So(err, ShouldBeNil)

for s := buf1.String(); len(s) > 0; {
So(s, ShouldStartWith, "5:41234")
s = s[len("5:41234"):]
}
for s := buf2.String(); len(s) > 0; {
So(s, ShouldStartWith, "5:41234")
s = s[len("5:41234"):]
}
})
}

+ 0
- 231
vendor/github.com/googollee/go-engine.io/polling/polling_test.go View File

@@ -1,231 +0,0 @@
package polling

import (
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"

"github.com/googollee/go-engine.io/message"
"github.com/googollee/go-engine.io/parser"
"github.com/googollee/go-engine.io/transport"
. "github.com/smartystreets/goconvey/convey"
)

func TestPolling(t *testing.T) {

Convey("Normal", t, func() {
s := newServer()
server := httptest.NewServer(s)
defer server.Close()

req, err := http.NewRequest("GET", server.URL, nil)
So(err, ShouldBeNil)
client, err := NewClient(req)
So(err, ShouldBeNil)

So(client.Response(), ShouldBeNil)

sync := make(chan int)

go func() {
<-s.callback.onPacket
sync <- 1
}()

{
w, err := client.NextWriter(message.MessageBinary, parser.MESSAGE)
So(err, ShouldBeNil)
_, err = w.Write([]byte("123"))
So(err, ShouldBeNil)
err = w.Close()
So(err, ShouldBeNil)
}

{
<-sync
So(s.callback.messageType, ShouldEqual, message.MessageBinary)
So(s.callback.packetType, ShouldEqual, parser.MESSAGE)
So(s.callback.body, ShouldResemble, []byte("123"))
}

So(client.Response(), ShouldNotBeNil)
So(client.Response().StatusCode, ShouldEqual, http.StatusOK)
So(client.Response().Header.Get("Custom"), ShouldEqual, "value")

{
w, err := s.server.NextWriter(message.MessageText, parser.MESSAGE)
So(err, ShouldBeNil)
_, err = w.Write([]byte("abc1"))
So(err, ShouldBeNil)
err = w.Close()
So(err, ShouldBeNil)

w, err = s.server.NextWriter(message.MessageText, parser.MESSAGE)
So(err, ShouldBeNil)
_, err = w.Write([]byte("abc2"))
So(err, ShouldBeNil)
err = w.Close()
So(err, ShouldBeNil)
}

{
r, err := client.NextReader()
So(err, ShouldBeNil)
b, err := ioutil.ReadAll(r)
So(err, ShouldBeNil)
So(b, ShouldResemble, []byte("abc1"))
err = r.Close()
So(err, ShouldBeNil)

r, err = client.NextReader()
So(err, ShouldBeNil)
b, err = ioutil.ReadAll(r)
So(err, ShouldBeNil)
So(b, ShouldResemble, []byte("abc2"))
err = r.Close()
So(err, ShouldBeNil)
}

{
w, err := s.server.NextWriter(message.MessageText, parser.MESSAGE)
So(err, ShouldBeNil)
_, err = w.Write([]byte("abc"))
So(err, ShouldBeNil)
err = w.Close()
So(err, ShouldBeNil)
}

{
r, err := client.NextReader()
So(err, ShouldBeNil)
b, err := ioutil.ReadAll(r)
So(err, ShouldBeNil)
So(b, ShouldResemble, []byte("abc"))
err = r.Close()
So(err, ShouldBeNil)
}

client.Close()
})

Convey("Normal b64", t, func() {
s := newServer()
server := httptest.NewServer(s)
defer server.Close()

req, err := http.NewRequest("GET", server.URL+"?b64", nil)
So(err, ShouldBeNil)
client, err := NewClient(req)
So(err, ShouldBeNil)

So(client.Response(), ShouldBeNil)

sync := make(chan int)

go func() {
<-s.callback.onPacket
sync <- 1
}()

{
w, err := client.NextWriter(message.MessageBinary, parser.MESSAGE)
So(err, ShouldBeNil)
_, err = w.Write([]byte("123"))
So(err, ShouldBeNil)
err = w.Close()
So(err, ShouldBeNil)
}

{
<-sync
So(s.callback.messageType, ShouldEqual, message.MessageBinary)
So(s.callback.packetType, ShouldEqual, parser.MESSAGE)
So(s.callback.body, ShouldResemble, []byte("123"))
}

So(client.Response(), ShouldNotBeNil)
So(client.Response().StatusCode, ShouldEqual, http.StatusOK)
So(client.Response().Header.Get("Custom"), ShouldEqual, "value")

{
w, err := s.server.NextWriter(message.MessageText, parser.MESSAGE)
So(err, ShouldBeNil)
_, err = w.Write([]byte("abc1"))
So(err, ShouldBeNil)
err = w.Close()
So(err, ShouldBeNil)

w, err = s.server.NextWriter(message.MessageText, parser.MESSAGE)
So(err, ShouldBeNil)
_, err = w.Write([]byte("abc2"))
So(err, ShouldBeNil)
err = w.Close()
So(err, ShouldBeNil)
}

{
r, err := client.NextReader()
So(err, ShouldBeNil)
b, err := ioutil.ReadAll(r)
So(err, ShouldBeNil)
So(b, ShouldResemble, []byte("abc1"))
err = r.Close()
So(err, ShouldBeNil)

r, err = client.NextReader()
So(err, ShouldBeNil)
b, err = ioutil.ReadAll(r)
So(err, ShouldBeNil)
So(b, ShouldResemble, []byte("abc2"))
err = r.Close()
So(err, ShouldBeNil)
}

{
w, err := s.server.NextWriter(message.MessageText, parser.MESSAGE)
So(err, ShouldBeNil)
_, err = w.Write([]byte("abc"))
So(err, ShouldBeNil)
err = w.Close()
So(err, ShouldBeNil)
}

{
r, err := client.NextReader()
So(err, ShouldBeNil)
b, err := ioutil.ReadAll(r)
So(err, ShouldBeNil)
So(b, ShouldResemble, []byte("abc"))
err = r.Close()
So(err, ShouldBeNil)
}

client.Close()
})

}

type server struct {
server transport.Server
callback *fakeCallback
}

func newServer() *server {
return &server{
callback: newFakeCallback(),
}
}

func (s *server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if s.server == nil {
var err error
s.server, err = NewServer(w, r, s.callback)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
w.Header().Set("Custom", "value")
s.server.ServeHTTP(w, r)
}

+ 0
- 507
vendor/github.com/googollee/go-engine.io/polling/server_test.go View File

@@ -1,507 +0,0 @@
package polling

import (
"bytes"
"encoding/hex"
"io"
"io/ioutil"
"net/http"
"net/http/httptest"
"sync"
"testing"
"time"

"github.com/googollee/go-engine.io/message"
"github.com/googollee/go-engine.io/parser"
"github.com/googollee/go-engine.io/transport"
. "github.com/smartystreets/goconvey/convey"
)

func TestServer(t *testing.T) {
Convey("Test polling", t, func() {

Convey("Overlay get", func() {
sync := make(chan int)
f := newFakeCallback()
w := httptest.NewRecorder()
r, err := http.NewRequest("GET", "/", nil)
So(err, ShouldBeNil)

server, err := NewServer(w, r, f)
So(err, ShouldBeNil)

go func() {
w := httptest.NewRecorder()
r, _ := http.NewRequest("GET", "/", nil)

server.ServeHTTP(w, r)

sync <- 1
}()

time.Sleep(time.Second)

{
w := httptest.NewRecorder()
r, err := http.NewRequest("GET", "/", nil)
So(err, ShouldBeNil)

server.ServeHTTP(w, r)

So(w.Code, ShouldEqual, http.StatusBadRequest)
So(w.Body.String(), ShouldEqual, "overlay get\n")
}

server.Close()
<-sync
So(f.ClosedCount(), ShouldEqual, 1)
})

Convey("Overlay post", func() {
sync := make(chan int)
f := newFakeCallback()
w := httptest.NewRecorder()
r, err := http.NewRequest("GET", "/", nil)
So(err, ShouldBeNil)

server, err := NewServer(w, r, f)
So(err, ShouldBeNil)

go func() {
w := httptest.NewRecorder()
r, _ := http.NewRequest("POST", "/", bytes.NewBufferString("\x00\x07\xff4测试"))

server.ServeHTTP(w, r)

sync <- 1
}()

time.Sleep(time.Second)

{
w := httptest.NewRecorder()
r, err := http.NewRequest("POST", "/", bytes.NewBufferString("\x00\x07\xff4测试"))
So(err, ShouldBeNil)

server.ServeHTTP(w, r)

So(w.Code, ShouldEqual, http.StatusBadRequest)
So(w.Body.String(), ShouldEqual, "overlay post\n")
}

<-f.onPacket
server.Close()
<-sync
So(f.ClosedCount(), ShouldEqual, 1)
})

Convey("Get", func() {
f := newFakeCallback()
w := httptest.NewRecorder()
r, err := http.NewRequest("GET", "/", nil)
So(err, ShouldBeNil)

server, err := NewServer(w, r, f)
So(err, ShouldBeNil)

{
writer, err := server.NextWriter(message.MessageBinary, parser.MESSAGE)
So(err, ShouldBeNil)
_, err = writer.Write([]byte("测试"))
So(err, ShouldBeNil)
err = writer.Close()
So(err, ShouldBeNil)

w := httptest.NewRecorder()
r, err := http.NewRequest("GET", "/", nil)
So(err, ShouldBeNil)

server.ServeHTTP(w, r)

So(w.Code, ShouldEqual, http.StatusOK)
So(w.Header().Get("Content-Type"), ShouldEqual, "application/octet-stream")
So(hex.EncodeToString(w.Body.Bytes()), ShouldEqual, "0107ff04e6b58be8af95")
So(w.Body.String(), ShouldEqual, "\x01\x07\xff\x04测试")
}

{
writer, err := server.NextWriter(message.MessageText, parser.MESSAGE)
So(err, ShouldBeNil)
_, err = writer.Write([]byte("测试"))
So(err, ShouldBeNil)
err = writer.Close()
So(err, ShouldBeNil)

w := httptest.NewRecorder()
r, err := http.NewRequest("GET", "/", nil)
So(err, ShouldBeNil)

server.ServeHTTP(w, r)

So(w.Code, ShouldEqual, http.StatusOK)
So(w.Header().Get("Content-Type"), ShouldEqual, "application/octet-stream")
So(hex.EncodeToString(w.Body.Bytes()), ShouldEqual, "0007ff34e6b58be8af95")
So(w.Body.String(), ShouldEqual, "\x00\x07\xff4测试")
}

err = server.Close()
So(err, ShouldBeNil)

{
w := httptest.NewRecorder()
r, err := http.NewRequest("GET", "/", nil)
So(err, ShouldBeNil)

server.ServeHTTP(w, r)

So(w.Code, ShouldEqual, http.StatusBadRequest)
So(w.Body.String(), ShouldEqual, "closed\n")
}

{
writer, err := server.NextWriter(message.MessageText, parser.MESSAGE)
So(err, ShouldEqual, io.EOF)
So(writer, ShouldBeNil)
}
})

Convey("Get b64", func() {
f := newFakeCallback()
w := httptest.NewRecorder()
r, err := http.NewRequest("GET", "/?b64", nil)
So(err, ShouldBeNil)

server, err := NewServer(w, r, f)
So(err, ShouldBeNil)

{
writer, err := server.NextWriter(message.MessageBinary, parser.MESSAGE)
So(err, ShouldBeNil)
_, err = writer.Write([]byte("测试"))
So(err, ShouldBeNil)
err = writer.Close()
So(err, ShouldBeNil)

w := httptest.NewRecorder()
r, err := http.NewRequest("GET", "/", nil)
So(err, ShouldBeNil)

server.ServeHTTP(w, r)

So(w.Code, ShouldEqual, http.StatusOK)
So(w.Header().Get("Content-Type"), ShouldEqual, "text/plain; charset=UTF-8")
So(w.Body.String(), ShouldEqual, "10:b45rWL6K+V")
}

{
writer, err := server.NextWriter(message.MessageText, parser.MESSAGE)
So(err, ShouldBeNil)
_, err = writer.Write([]byte("测试"))
So(err, ShouldBeNil)
err = writer.Close()
So(err, ShouldBeNil)

w := httptest.NewRecorder()
r, err := http.NewRequest("GET", "/", nil)
So(err, ShouldBeNil)

server.ServeHTTP(w, r)

So(w.Code, ShouldEqual, http.StatusOK)
So(w.Header().Get("Content-Type"), ShouldEqual, "text/plain; charset=UTF-8")
So(w.Body.String(), ShouldEqual, "7:4测试")
}

err = server.Close()
So(err, ShouldBeNil)

{
w := httptest.NewRecorder()
r, err := http.NewRequest("GET", "/", nil)
So(err, ShouldBeNil)

server.ServeHTTP(w, r)

So(w.Code, ShouldEqual, http.StatusBadRequest)
So(w.Body.String(), ShouldEqual, "closed\n")
}

{
writer, err := server.NextWriter(message.MessageText, parser.MESSAGE)
So(err, ShouldEqual, io.EOF)
So(writer, ShouldBeNil)
}
})

Convey("Post", func() {
f := newFakeCallback()
w := httptest.NewRecorder()
r, err := http.NewRequest("GET", "/", nil)
So(err, ShouldBeNil)

server, err := NewServer(w, r, f)
So(err, ShouldBeNil)

go func() {
<-f.onPacket
}()

{
w := httptest.NewRecorder()
r, err := http.NewRequest("POST", "/", bytes.NewBufferString("\x00\x07\xff4测试"))
So(err, ShouldBeNil)

server.ServeHTTP(w, r)

So(w.Code, ShouldEqual, http.StatusOK)
So(w.Body.String(), ShouldEqual, "ok")
So(hex.EncodeToString(f.body), ShouldEqual, "e6b58be8af95")
}

{
w := httptest.NewRecorder()
r, err := http.NewRequest("POST", "/", bytes.NewBufferString("\x00\xff4测试"))
So(err, ShouldBeNil)

server.ServeHTTP(w, r)

So(w.Code, ShouldEqual, http.StatusBadRequest)
So(w.Body.String(), ShouldEqual, "invalid input\n")
}

err = server.Close()
So(err, ShouldBeNil)

{
w := httptest.NewRecorder()
r, err := http.NewRequest("POST", "/", bytes.NewBufferString("\x00\x07\xff4测试"))
So(err, ShouldBeNil)

server.ServeHTTP(w, r)

So(w.Code, ShouldEqual, http.StatusBadRequest)
So(w.Body.String(), ShouldEqual, "closed\n")
}

})

Convey("Closing", func() {
Convey("No get no post", func() {
f := newFakeCallback()
w := httptest.NewRecorder()
r, err := http.NewRequest("GET", "/", nil)
So(err, ShouldBeNil)

server, err := NewServer(w, r, f)
So(err, ShouldBeNil)

So(f.ClosedCount(), ShouldEqual, 0)
err = server.Close()
So(err, ShouldBeNil)

So(f.ClosedCount(), ShouldEqual, 1)
So(f.closeServer, ShouldEqual, server)
})

Convey("No get has post", func() {
f := newFakeCallback()
sync := make(chan int)
w := httptest.NewRecorder()
r, err := http.NewRequest("GET", "/", nil)
So(err, ShouldBeNil)

server, err := NewServer(w, r, f)
So(err, ShouldBeNil)

go func() {
w := httptest.NewRecorder()
r, _ := http.NewRequest("POST", "/", bytes.NewBufferString("\x00\x07\xff4测试"))

server.ServeHTTP(w, r)
sync <- 1
}()

time.Sleep(time.Second)

So(f.ClosedCount(), ShouldEqual, 0)
err = server.Close()
So(err, ShouldBeNil)
So(f.ClosedCount(), ShouldEqual, 0)
<-f.onPacket
<-sync
So(f.closeServer, ShouldEqual, server)
So(f.ClosedCount(), ShouldEqual, 1)
})

Convey("has get no post", func() {
f := newFakeCallback()
sync := make(chan int)
w := httptest.NewRecorder()
r, err := http.NewRequest("GET", "/", nil)
So(err, ShouldBeNil)

server, err := NewServer(w, r, f)
So(err, ShouldBeNil)

go func() {
w := httptest.NewRecorder()
r, _ := http.NewRequest("GET", "/", nil)

server.ServeHTTP(w, r)

sync <- 1
}()

time.Sleep(time.Second)

So(f.ClosedCount(), ShouldEqual, 0)
err = server.Close()
So(err, ShouldBeNil)
<-sync
So(f.closeServer, ShouldEqual, server)
So(f.ClosedCount(), ShouldEqual, 1)
})

Convey("has get has post", func() {
f := newFakeCallback()
sync := make(chan int)
w := httptest.NewRecorder()
r, err := http.NewRequest("GET", "/", nil)
So(err, ShouldBeNil)

server, err := NewServer(w, r, f)
So(err, ShouldBeNil)

go func() {
w := httptest.NewRecorder()
r, _ := http.NewRequest("GET", "/", nil)

server.ServeHTTP(w, r)

sync <- 1
}()

go func() {
w := httptest.NewRecorder()
r, _ = http.NewRequest("POST", "/", bytes.NewBufferString("\x00\x07\xff4测试"))

server.ServeHTTP(w, r)
sync <- 1
}()

time.Sleep(time.Second)

So(f.ClosedCount(), ShouldEqual, 0)
err = server.Close()
So(err, ShouldBeNil)
So(f.ClosedCount(), ShouldEqual, 0)
<-f.onPacket
<-sync
<-sync
So(f.closeServer, ShouldEqual, server)
So(f.ClosedCount(), ShouldEqual, 1)
})

Convey("Multi-close", func() {
f := newFakeCallback()
sync := make(chan int)
w := httptest.NewRecorder()
r, err := http.NewRequest("GET", "/", nil)
So(err, ShouldBeNil)

server, err := NewServer(w, r, f)
So(err, ShouldBeNil)

go func() {
w := httptest.NewRecorder()
r, _ := http.NewRequest("GET", "/", nil)

server.ServeHTTP(w, r)

sync <- 1
}()

go func() {
w := httptest.NewRecorder()
r, _ := http.NewRequest("POST", "/", bytes.NewBufferString("\x00\x07\xff4测试"))

server.ServeHTTP(w, r)
sync <- 1
}()

time.Sleep(time.Second)

So(f.ClosedCount(), ShouldEqual, 0)
err = server.Close()
So(err, ShouldBeNil)
So(f.ClosedCount(), ShouldEqual, 0)
<-f.onPacket
<-sync
<-sync
So(f.closeServer, ShouldEqual, server)
server.Close()
server.Close()
server.Close()
server.Close()
So(f.ClosedCount(), ShouldEqual, 1)
})

Convey("Closed before writer closed", func() {
f := newFakeCallback()
w := httptest.NewRecorder()
r, err := http.NewRequest("GET", "/", nil)
So(err, ShouldBeNil)

server, err := NewServer(w, r, f)
So(err, ShouldBeNil)

writer, err := server.NextWriter(message.MessageText, parser.MESSAGE)
So(err, ShouldBeNil)

err = server.Close()
So(err, ShouldBeNil)

err = writer.Close()
So(err, ShouldNotBeNil)
})
})

})
}

type fakeCallback struct {
onPacket chan bool
messageType message.MessageType
packetType parser.PacketType
body []byte
err error
closedCount int
countLocker sync.Mutex
closeServer transport.Server
}

func newFakeCallback() *fakeCallback {
return &fakeCallback{
onPacket: make(chan bool),
}
}

func (f *fakeCallback) OnPacket(r *parser.PacketDecoder) {
f.packetType = r.Type()
f.messageType = r.MessageType()
f.body, f.err = ioutil.ReadAll(r)
f.onPacket <- true
}

func (f *fakeCallback) OnClose(s transport.Server) {
f.countLocker.Lock()
defer f.countLocker.Unlock()
f.closedCount++
f.closeServer = s
}

func (f *fakeCallback) ClosedCount() int {
f.countLocker.Lock()
defer f.countLocker.Unlock()
return f.closedCount
}

+ 0
- 47
vendor/github.com/googollee/go-engine.io/polling/try_locker_test.go View File

@@ -1,47 +0,0 @@
package polling

import (
"testing"
"time"

. "github.com/smartystreets/goconvey/convey"
)

func TestTryLocker(t *testing.T) {

Convey("Lock/Unlock", t, func() {
locker := NewLocker()
sync := make(chan int)
go func() {
locker.Lock()
sync <- 1
time.Sleep(time.Second)
locker.Unlock()
}()
<-sync
start := time.Now()
locker.Lock()
now := time.Now()
So(now.Sub(start), ShouldBeGreaterThanOrEqualTo, time.Second)
locker.Unlock()
})

Convey("TryLock/Unlock", t, func() {
locker := NewLocker()
sync := make(chan int)
go func() {
locker.Lock()
sync <- 1
time.Sleep(time.Second)
locker.Unlock()
}()
<-sync
ok := locker.TryLock()
So(ok, ShouldBeFalse)
time.Sleep(time.Second * 3 / 2)
ok = locker.TryLock()
So(ok, ShouldBeTrue)
locker.Unlock()
})

}

+ 0
- 89
vendor/github.com/googollee/go-engine.io/polling/writer_test.go View File

@@ -1,89 +0,0 @@
package polling

import (
"bytes"
"testing"

. "github.com/smartystreets/goconvey/convey"
)

func TestWriter(t *testing.T) {