added test for out of order conf, found bug that needs fixing

This commit is contained in:
Stephen McQuay 2013-08-26 23:09:39 -07:00
parent ad13aed9fd
commit 0512bb7664
2 changed files with 53 additions and 2 deletions

View File

@ -3,7 +3,6 @@ package main
import (
"code.google.com/p/go.net/websocket"
"errors"
"log"
)
// > identify
@ -114,9 +113,9 @@ func Negociate(ws *websocket.Conn, id string, width, height float64) (*Config, e
for {
err = websocket.JSON.Receive(ws, &conf)
if err != nil {
log.Print(err)
return nil, err
}
// TODO: verify conf's type
if conf.Stats.valid() {
_ = websocket.JSON.Send(ws, NewHandshake(id, true))
break

View File

@ -169,3 +169,55 @@ func TestBadUseragent(t *testing.T) {
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")
}
}