12345678910111213141516171819202122232425262728293031323334353637383940 |
- package codex
- import (
- "testing"
- "github.com/stretchr/testify/assert"
- )
- func Test_iso8583_decode(t *testing.T) {
- codex := LoadCodex("iso8583.yaml")
- msg := "0800822000000000000004000000000000020623135417005592001005REQ 1"
- data := make(map[string]interface{})
- pos, err := codex.Decode([]byte(msg), 0, data)
- assert.Nil(t, err, "decode err")
- assert.Equal(t, 63, pos, "decode pos")
- result := map[string]interface{}{
- "F000": "0800",
- "F007": "0623135417",
- "F011": "005592",
- "F070": "001",
- "F127": "REQ 1",
- }
- assert.Equal(t, result, data, "decode data")
- }
- func Test_iso8583_encode(t *testing.T) {
- codex := LoadCodex("iso8583.yaml")
- data := map[string]interface{}{
- "F000": "0800",
- "F007": "0623135417",
- "F011": "005592",
- "F070": "001",
- "F127": "REQ 1",
- }
- msg := make([]byte, 1024)
- pos, err := codex.Encode(msg, 0, data)
- assert.Nil(t, err, "encode err")
- assert.Equal(t, 63, pos, "encode pos")
- result := "0800822000000000000004000000000000020623135417005592001005REQ 1"
- assert.Equal(t, result, string(msg[0:pos]), "encode data")
- }
|