codex_test.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package codex
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func Test_iso8583_decode(t *testing.T) {
  7. codex := LoadCodex("iso8583.yaml")
  8. msg := "0800822000000000000004000000000000020623135417005592001005REQ 1"
  9. data := make(map[string]interface{})
  10. pos, err := codex.Decode([]byte(msg), 0, data)
  11. assert.Nil(t, err, "decode err")
  12. assert.Equal(t, 63, pos, "decode pos")
  13. result := map[string]interface{}{
  14. "F000": "0800",
  15. "F007": "0623135417",
  16. "F011": "005592",
  17. "F070": "001",
  18. "F127": "REQ 1",
  19. }
  20. assert.Equal(t, result, data, "decode data")
  21. }
  22. func Test_iso8583_encode(t *testing.T) {
  23. codex := LoadCodex("iso8583.yaml")
  24. data := map[string]interface{}{
  25. "F000": "0800",
  26. "F007": "0623135417",
  27. "F011": "005592",
  28. "F070": "001",
  29. "F127": "REQ 1",
  30. }
  31. msg := make([]byte, 1024)
  32. pos, err := codex.Encode(msg, 0, data)
  33. assert.Nil(t, err, "encode err")
  34. assert.Equal(t, 63, pos, "encode pos")
  35. result := "0800822000000000000004000000000000020623135417005592001005REQ 1"
  36. assert.Equal(t, result, string(msg[0:pos]), "encode data")
  37. }