-
Notifications
You must be signed in to change notification settings - Fork 40
/
errorWire_test.go
97 lines (76 loc) · 2.69 KB
/
errorWire_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package wire
import (
"errors"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// mockErrorWire creates a ErrorWire
func mockErrorWire() *ErrorWire {
ew := NewErrorWire()
ew.ErrorCategory = "E"
ew.ErrorCode = "XYZ"
ew.ErrorDescription = "Data Error"
return ew
}
// TestMockErrorWire validates mockErrorWire
func TestMockErrorWire(t *testing.T) {
ew := mockErrorWire()
require.NoError(t, ew.Validate(), "mockErrorWire does not validate and will break other tests")
}
// TestParseErrorWire parses a known ErrorWire record string
func TestParseErrorWire(t *testing.T) {
var line = "{1130}1XYZData Error *"
r := NewReader(strings.NewReader(line))
r.line = line
require.NoError(t, r.parseErrorWire())
record := r.currentFEDWireMessage.ErrorWire
assert.Equal(t, "1", record.ErrorCategory)
assert.Equal(t, "XYZ", record.ErrorCode)
assert.Equal(t, "Data Error", record.ErrorDescription)
}
// TestWriteErrorWire writes a ErrorWire record string
func TestWriteErrorWire(t *testing.T) {
var line = "{1130}1XYZData Error *"
r := NewReader(strings.NewReader(line))
r.line = line
require.NoError(t, r.parseErrorWire())
record := r.currentFEDWireMessage.ErrorWire
assert.Equal(t, line, record.String())
}
// TestStringErrorWireAmountVariableLength parses using variable length
func TestStringErrorWireAmountVariableLength(t *testing.T) {
var line = "{1130}"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseErrorWire()
require.Nil(t, err)
line = "{1130}1XYZData Error NNN"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseErrorWire()
require.ErrorContains(t, err, ErrRequireDelimiter.Error())
line = "{1130}1XYZData Error***"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseErrorWire()
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
line = "{1130}1XYZData Error*"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseErrorWire()
require.Equal(t, err, nil)
}
// TestStringErrorWireOptions validates Format() formatted according to the FormatOptions
func TestStringErrorWireOptions(t *testing.T) {
var line = "{1130}1XYZData Error*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseErrorWire()
require.Equal(t, err, nil)
record := r.currentFEDWireMessage.ErrorWire
require.Equal(t, record.String(), "{1130}1XYZData Error *")
require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{1130}1XYZData Error*")
require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false}))
}