You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

74 lines
1.6 KiB

  1. package worker
  2. import (
  3. "bytes"
  4. "testing"
  5. )
  6. var (
  7. inpackcases = map[uint32]map[string]string{
  8. dtNoop: map[string]string{
  9. "src": "\x00RES\x00\x00\x00\x06\x00\x00\x00\x00",
  10. },
  11. dtNoJob: map[string]string{
  12. "src": "\x00RES\x00\x00\x00\x0a\x00\x00\x00\x00",
  13. },
  14. dtJobAssign: map[string]string{
  15. "src": "\x00RES\x00\x00\x00\x0b\x00\x00\x00\x07a\x00b\x00xyz",
  16. "handle": "a",
  17. "fn": "b",
  18. "data": "xyz",
  19. },
  20. dtJobAssignUniq: map[string]string{
  21. "src": "\x00RES\x00\x00\x00\x1F\x00\x00\x00\x09a\x00b\x00c\x00xyz",
  22. "handle": "a",
  23. "fn": "b",
  24. "uid": "c",
  25. "data": "xyz",
  26. },
  27. }
  28. )
  29. func TestInPack(t *testing.T) {
  30. for k, v := range inpackcases {
  31. inpack, _, err := decodeInPack([]byte(v["src"]))
  32. if err != nil {
  33. t.Error(err)
  34. }
  35. if inpack.dataType != k {
  36. t.Errorf("DataType: %d expected, %d got.", k, inpack.dataType)
  37. }
  38. if handle, ok := v["handle"]; ok {
  39. if inpack.handle != handle {
  40. t.Errorf("Handle: %s expected, %s got.", handle, inpack.handle)
  41. }
  42. }
  43. if fn, ok := v["fn"]; ok {
  44. if inpack.fn != fn {
  45. t.Errorf("FuncName: %s expected, %s got.", fn, inpack.fn)
  46. }
  47. }
  48. if uid, ok := v["uid"]; ok {
  49. if inpack.uniqueId != uid {
  50. t.Errorf("UID: %s expected, %s got.", uid, inpack.uniqueId)
  51. }
  52. }
  53. if data, ok := v["data"]; ok {
  54. if bytes.Compare([]byte(data), inpack.data) != 0 {
  55. t.Errorf("UID: %v expected, %v got.", data, inpack.data)
  56. }
  57. }
  58. }
  59. }
  60. func BenchmarkDecode(b *testing.B) {
  61. for i := 0; i < b.N; i++ {
  62. for _, v := range inpackcases {
  63. _, _, err := decodeInPack([]byte(v["src"]))
  64. if err != nil {
  65. b.Error(err)
  66. }
  67. }
  68. }
  69. }