github.com/danil/iso8583@v0.21.0/codec8583/tsys_unmarshal_test.go (about)

     1  package codec8583_test
     2  
     3  import (
     4  	"errors"
     5  	"testing"
     6  
     7  	"github.com/danil/equal4"
     8  	"github.com/danil/iso8583/codec8583"
     9  )
    10  
    11  func TestTSYSUnmarshalerUnmarshalSmallMessage(t *testing.T) {
    12  	v := iso8583Msg2{}
    13  	expectedError := errors.New("ISO 8583 unmarshal: message too small to read: 6 < 12, message: []byte{0x46, 0x6f, 0x6f, 0x62, 0x61, 0x72}")
    14  	err := codec8583.TSYSUnmarshaler.Unmarshal([]byte("Foobar"), &v)
    15  	if !equal4.ErrorEqual(err, expectedError) {
    16  		t.Errorf("[error] expected: %#v, received: %#v", expectedError, err)
    17  	}
    18  }
    19  
    20  func TestTSYSUnmarshalerUnmarshalWithoutMTI(t *testing.T) {
    21  	type withoutMTI struct {
    22  		PrimaryAccountNumber string `iso8583:"2"`
    23  	}
    24  	v := withoutMTI{}
    25  	expectedError := errors.New("ISO 8583 unmarshal: decode MTI: struct must have MTI field, message: []byte{0x30, 0x32, 0x30, 0x30, 0xf2, 0x3a, 0xc4, 0x81, 0x28, 0xe0, 0x80, 0x10, 0x0, 0x0, 0x0, 0x0, 0x14, 0x0, 0x1, 0x0, 0x31, 0x36, 0x35, 0x33, 0x32, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x36, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x35, 0x31, 0x37, 0x31, 0x34, 0x31, 0x37, 0x32, 0x38, 0x30, 0x30, 0x30, 0x30, 0x36, 0x34, 0x31, 0x33, 0x35, 0x32, 0x35, 0x33, 0x30, 0x35, 0x31, 0x36, 0x30, 0x35, 0x31, 0x37, 0x30, 0x35, 0x31, 0x36, 0x36, 0x30, 0x31, 0x30, 0x39, 0x30, 0x32, 0x30, 0x30, 0x30, 0x30, 0x36, 0x39, 0x39, 0x39, 0x39, 0x30, 0x35, 0x33, 0x37, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x37, 0x31, 0x33, 0x36, 0x31, 0x39, 0x39, 0x30, 0x39, 0x34, 0x34, 0x38, 0x38, 0x30, 0x31, 0x31, 0x30, 0x30, 0x30, 0x31, 0x38, 0x30, 0x31, 0x31, 0x30, 0x30, 0x30, 0x31, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x43, 0x45, 0x4e, 0x54, 0x52, 0x41, 0x4c, 0x20, 0x4f, 0x46, 0x46, 0x49, 0x43, 0x45, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x4d, 0x6f, 0x73, 0x63, 0x6f, 0x77, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x52, 0x55, 0x36, 0x34, 0x33, 0x30, 0x38, 0x30, 0x32, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x38, 0x4d, 0x43, 0x54, 0x49, 0x44, 0x48, 0x49, 0x31, 0x31, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x36, 0x31, 0x31, 0x36, 0x34, 0x33, 0x30, 0x36, 0x35, 0x55, 0x44, 0x30, 0x36, 0x30, 0x43, 0x49, 0x30, 0x34, 0x35, 0x30, 0x31, 0x30, 0x31, 0x30, 0x30, 0x32, 0x30, 0x31, 0x30, 0x30, 0x33, 0x30, 0x31, 0x30, 0x30, 0x34, 0x30, 0x31, 0x32, 0x30, 0x35, 0x30, 0x31, 0x30, 0x30, 0x36, 0x30, 0x31, 0x30, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30, 0x38, 0x30, 0x31, 0x30, 0x30, 0x39, 0x30, 0x31, 0x30, 0x45, 0x52, 0x30, 0x30, 0x35, 0x34, 0x30, 0x30, 0x37, 0x33}")
    26  	err := codec8583.TSYSUnmarshaler.Unmarshal(iso8583Bytes[1], &v)
    27  	if !equal4.ErrorEqual(err, expectedError) {
    28  		t.Errorf("[error] expected: %#v, received: %#v", expectedError, err)
    29  	}
    30  }
    31  
    32  func TestTSYSUnmarshalerUnmarshalWithoutPAN(t *testing.T) {
    33  	type withoutPan struct {
    34  		MTI string `iso8583:"MTI"`
    35  	}
    36  	v := withoutPan{}
    37  	expectedError := errors.New(`ISO 8583 unmarshal: decode field: 2, struct does not have a field with tag: 2, the message in field: 2, has a value: "5321000000002610", all fields: [1 2 3 4 7 11 12 13 15 17 18 22 25 32 35 37 41 42 43 49 60 100 102 120], message: []byte{0x30, 0x32, 0x30, 0x30, 0xf2, 0x3a, 0xc4, 0x81, 0x28, 0xe0, 0x80, 0x10, 0x0, 0x0, 0x0, 0x0, 0x14, 0x0, 0x1, 0x0, 0x31, 0x36, 0x35, 0x33, 0x32, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x32, 0x36, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x35, 0x31, 0x37, 0x31, 0x34, 0x31, 0x37, 0x32, 0x38, 0x30, 0x30, 0x30, 0x30, 0x36, 0x34, 0x31, 0x33, 0x35, 0x32, 0x35, 0x33, 0x30, 0x35, 0x31, 0x36, 0x30, 0x35, 0x31, 0x37, 0x30, 0x35, 0x31, 0x36, 0x36, 0x30, 0x31, 0x30, 0x39, 0x30, 0x32, 0x30, 0x30, 0x30, 0x30, 0x36, 0x39, 0x39, 0x39, 0x39, 0x30, 0x35, 0x33, 0x37, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x37, 0x31, 0x33, 0x36, 0x31, 0x39, 0x39, 0x30, 0x39, 0x34, 0x34, 0x38, 0x38, 0x30, 0x31, 0x31, 0x30, 0x30, 0x30, 0x31, 0x38, 0x30, 0x31, 0x31, 0x30, 0x30, 0x30, 0x31, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x43, 0x45, 0x4e, 0x54, 0x52, 0x41, 0x4c, 0x20, 0x4f, 0x46, 0x46, 0x49, 0x43, 0x45, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x4d, 0x6f, 0x73, 0x63, 0x6f, 0x77, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x52, 0x55, 0x36, 0x34, 0x33, 0x30, 0x38, 0x30, 0x32, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x38, 0x4d, 0x43, 0x54, 0x49, 0x44, 0x48, 0x49, 0x31, 0x31, 0x34, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x36, 0x31, 0x31, 0x36, 0x34, 0x33, 0x30, 0x36, 0x35, 0x55, 0x44, 0x30, 0x36, 0x30, 0x43, 0x49, 0x30, 0x34, 0x35, 0x30, 0x31, 0x30, 0x31, 0x30, 0x30, 0x32, 0x30, 0x31, 0x30, 0x30, 0x33, 0x30, 0x31, 0x30, 0x30, 0x34, 0x30, 0x31, 0x32, 0x30, 0x35, 0x30, 0x31, 0x30, 0x30, 0x36, 0x30, 0x31, 0x30, 0x30, 0x37, 0x30, 0x31, 0x30, 0x30, 0x38, 0x30, 0x31, 0x30, 0x30, 0x39, 0x30, 0x31, 0x30, 0x45, 0x52, 0x30, 0x30, 0x35, 0x34, 0x30, 0x30, 0x37, 0x33}`)
    38  	err := codec8583.TSYSUnmarshaler.Unmarshal(iso8583Bytes[1], &v)
    39  	if !equal4.ErrorEqual(err, expectedError) {
    40  		t.Errorf("[error] expected: %#v, received: %#v", expectedError, err)
    41  	}
    42  }