gearman-go/worker/outpack_test.go

84 lines
2.1 KiB
Go
Raw Normal View History

2013-12-24 16:35:17 +08:00
package worker
import (
"bytes"
"testing"
)
var (
outpackcases = map[uint32]map[string]string{
2013-12-26 15:55:16 +08:00
dtCanDo: map[string]string{
2013-12-24 16:35:17 +08:00
"src": "\x00REQ\x00\x00\x00\x01\x00\x00\x00\x01a",
"data": "a",
},
2013-12-26 15:55:16 +08:00
dtCanDoTimeout: map[string]string{
2013-12-24 16:35:17 +08:00
"src": "\x00REQ\x00\x00\x00\x17\x00\x00\x00\x06a\x00\x00\x00\x00\x01",
"data": "a\x00\x00\x00\x00\x01",
},
2013-12-26 15:55:16 +08:00
dtCantDo: map[string]string{
2013-12-24 16:35:17 +08:00
"src": "\x00REQ\x00\x00\x00\x02\x00\x00\x00\x01a",
"data": "a",
},
2013-12-26 15:55:16 +08:00
dtResetAbilities: map[string]string{
2013-12-24 16:35:17 +08:00
"src": "\x00REQ\x00\x00\x00\x03\x00\x00\x00\x00",
},
2013-12-26 15:55:16 +08:00
dtPreSleep: map[string]string{
2013-12-24 16:35:17 +08:00
"src": "\x00REQ\x00\x00\x00\x04\x00\x00\x00\x00",
},
2013-12-26 15:55:16 +08:00
dtGrabJob: map[string]string{
2013-12-24 16:35:17 +08:00
"src": "\x00REQ\x00\x00\x00\x09\x00\x00\x00\x00",
},
2013-12-26 15:55:16 +08:00
dtGrabJobUniq: map[string]string{
2013-12-24 16:35:17 +08:00
"src": "\x00REQ\x00\x00\x00\x1E\x00\x00\x00\x00",
},
2013-12-26 15:55:16 +08:00
dtWorkData: map[string]string{
2013-12-24 16:35:17 +08:00
"src": "\x00REQ\x00\x00\x00\x1C\x00\x00\x00\x03a\x00b",
"data": "a\x00b",
},
2013-12-26 15:55:16 +08:00
dtWorkWarning: map[string]string{
2013-12-24 16:35:17 +08:00
"src": "\x00REQ\x00\x00\x00\x1D\x00\x00\x00\x03a\x00b",
"data": "a\x00b",
},
2013-12-26 15:55:16 +08:00
dtWorkStatus: map[string]string{
2013-12-24 16:35:17 +08:00
"src": "\x00REQ\x00\x00\x00\x0C\x00\x00\x00\x08a\x0050\x00100",
"data": "a\x0050\x00100",
},
2013-12-26 15:55:16 +08:00
dtWorkComplete: map[string]string{
2013-12-24 16:35:17 +08:00
"src": "\x00REQ\x00\x00\x00\x0D\x00\x00\x00\x03a\x00b",
"data": "a\x00b",
},
2013-12-26 15:55:16 +08:00
dtWorkFail: map[string]string{
2013-12-24 16:35:17 +08:00
"src": "\x00REQ\x00\x00\x00\x0E\x00\x00\x00\x01a",
"handle": "a",
},
2013-12-26 15:55:16 +08:00
dtWorkException: map[string]string{
2013-12-24 16:35:17 +08:00
"src": "\x00REQ\x00\x00\x00\x19\x00\x00\x00\x03a\x00b",
"data": "a\x00b",
},
dtSetClientId: map[string]string{
2013-12-24 16:35:17 +08:00
"src": "\x00REQ\x00\x00\x00\x16\x00\x00\x00\x01a",
"data": "a",
},
2013-12-26 15:55:16 +08:00
dtAllYours: map[string]string{
2013-12-24 16:35:17 +08:00
"src": "\x00REQ\x00\x00\x00\x18\x00\x00\x00\x00",
},
}
)
func TestOutPack(t *testing.T) {
for k, v := range outpackcases {
outpack := getOutPack()
outpack.dataType = k
if handle, ok := v["handle"]; ok {
outpack.handle = handle
}
if data, ok := v["data"]; ok {
outpack.data = []byte(data)
}
data := outpack.Encode()
if bytes.Compare([]byte(v["src"]), data) != 0 {
t.Errorf("%d: %X expected, %X got.", k, v["src"], data)
}
}
}