added test for out of order conf, found bug that needs fixing
This commit is contained in:
parent
ad13aed9fd
commit
0512bb7664
@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"code.google.com/p/go.net/websocket"
|
"code.google.com/p/go.net/websocket"
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// > identify
|
// > identify
|
||||||
@ -114,9 +113,9 @@ func Negociate(ws *websocket.Conn, id string, width, height float64) (*Config, e
|
|||||||
for {
|
for {
|
||||||
err = websocket.JSON.Receive(ws, &conf)
|
err = websocket.JSON.Receive(ws, &conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
// TODO: verify conf's type
|
||||||
if conf.Stats.valid() {
|
if conf.Stats.valid() {
|
||||||
_ = websocket.JSON.Send(ws, NewHandshake(id, true))
|
_ = websocket.JSON.Send(ws, NewHandshake(id, true))
|
||||||
break
|
break
|
||||||
|
@ -169,3 +169,55 @@ func TestBadUseragent(t *testing.T) {
|
|||||||
t.Errorf("tried sending bad type, didn't detect it")
|
t.Errorf("tried sending bad type, didn't detect it")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestOutOfOrderProtocol(t *testing.T) {
|
||||||
|
ws, err := DummyServer()
|
||||||
|
|
||||||
|
// send early here:
|
||||||
|
err = websocket.JSON.Send(ws, ClientID{
|
||||||
|
"robot",
|
||||||
|
"smcquay test robot 2",
|
||||||
|
"unittest",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var idreq IdRequest
|
||||||
|
err = websocket.JSON.Receive(ws, &idreq)
|
||||||
|
if idreq.Type != "idreq" {
|
||||||
|
t.Errorf("Server skipped a step (idreq)")
|
||||||
|
}
|
||||||
|
|
||||||
|
// XXX: this thing gets interpreted server-side as a Config ...
|
||||||
|
err = websocket.JSON.Send(ws, ClientID{
|
||||||
|
Type: "why doesn't this matter?",
|
||||||
|
Name: "smcquay test robot 2",
|
||||||
|
Useragent: "unittest",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var gameparam GameParam
|
||||||
|
err = websocket.JSON.Receive(ws, &gameparam)
|
||||||
|
if gameparam.Type != "gameparam" {
|
||||||
|
t.Errorf("didn't receive a good gameparam")
|
||||||
|
}
|
||||||
|
|
||||||
|
err = websocket.JSON.Send(ws, &Config{
|
||||||
|
"bogus",
|
||||||
|
stats{
|
||||||
|
Hp: 200000,
|
||||||
|
Speed: 10000,
|
||||||
|
WeaponRadius: 5000,
|
||||||
|
ScannerRadius: 50,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
var handshake Handshake
|
||||||
|
websocket.JSON.Receive(ws, &handshake)
|
||||||
|
if !handshake.Success {
|
||||||
|
t.Errorf("failed to validate correct stats request")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user