-
Notifications
You must be signed in to change notification settings - Fork 40
/
fiReceiverFI_test.go
172 lines (127 loc) · 5.8 KB
/
fiReceiverFI_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package wire
import (
"errors"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// mockFIReceiverFI creates a FIReceiverFI
func mockFIReceiverFI() *FIReceiverFI {
firfi := NewFIReceiverFI()
firfi.FIToFI.LineOne = "Line One"
firfi.FIToFI.LineOne = "Line Two"
firfi.FIToFI.LineOne = "Line Three"
firfi.FIToFI.LineOne = "Line Four"
firfi.FIToFI.LineOne = "Line Five"
firfi.FIToFI.LineOne = "Line Six"
return firfi
}
// TestMockFIReceiverFI validates mockFIReceiverFI
func TestMockFIReceiverFI(t *testing.T) {
firfi := mockFIReceiverFI()
require.NoError(t, firfi.Validate(), "mockFIReceiverFI does not validate and will break other tests")
}
// TestFIReceiverFILineOneAlphaNumeric validates FIReceiverFI LineOne is alphanumeric
func TestFIReceiverFILineOneAlphaNumeric(t *testing.T) {
firfi := mockFIReceiverFI()
firfi.FIToFI.LineOne = "®"
err := firfi.Validate()
require.EqualError(t, err, fieldError("LineOne", ErrNonAlphanumeric, firfi.FIToFI.LineOne).Error())
}
// TestFIReceiverFILineTwoAlphaNumeric validates FIReceiverFI LineTwo is alphanumeric
func TestFIReceiverFILineTwoAlphaNumeric(t *testing.T) {
firfi := mockFIReceiverFI()
firfi.FIToFI.LineTwo = "®"
err := firfi.Validate()
require.EqualError(t, err, fieldError("LineTwo", ErrNonAlphanumeric, firfi.FIToFI.LineTwo).Error())
}
// TestFIReceiverFILineThreeAlphaNumeric validates FIReceiverFI LineThree is alphanumeric
func TestFIReceiverFILineThreeAlphaNumeric(t *testing.T) {
firfi := mockFIReceiverFI()
firfi.FIToFI.LineThree = "®"
err := firfi.Validate()
require.EqualError(t, err, fieldError("LineThree", ErrNonAlphanumeric, firfi.FIToFI.LineThree).Error())
}
// TestFIReceiverFILineFourAlphaNumeric validates FIReceiverFI LineFour is alphanumeric
func TestFIReceiverFILineFourAlphaNumeric(t *testing.T) {
firfi := mockFIReceiverFI()
firfi.FIToFI.LineFour = "®"
err := firfi.Validate()
require.EqualError(t, err, fieldError("LineFour", ErrNonAlphanumeric, firfi.FIToFI.LineFour).Error())
}
// TestFIReceiverFILineFiveAlphaNumeric validates FIReceiverFI LineFive is alphanumeric
func TestFIReceiverFILineFiveAlphaNumeric(t *testing.T) {
firfi := mockFIReceiverFI()
firfi.FIToFI.LineFive = "®"
err := firfi.Validate()
require.EqualError(t, err, fieldError("LineFive", ErrNonAlphanumeric, firfi.FIToFI.LineFive).Error())
}
// TestFIReceiverFILineSixAlphaNumeric validates FIReceiverFI LineSix is alphanumeric
func TestFIReceiverFILineSixAlphaNumeric(t *testing.T) {
firfi := mockFIReceiverFI()
firfi.FIToFI.LineSix = "®"
err := firfi.Validate()
require.EqualError(t, err, fieldError("LineSix", ErrNonAlphanumeric, firfi.FIToFI.LineSix).Error())
}
// TestParseFIReceiverFIWrongLength parses a wrong FIReceiverFI record length
func TestParseFIReceiverFIWrongLength(t *testing.T) {
var line = "{6100}Line Six "
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIReceiverFI()
require.EqualError(t, err, r.parseError(fieldError("LineOne", ErrRequireDelimiter)).Error())
}
// TestParseFIReceiverFIReaderParseError parses a wrong FIReceiverFI reader parse error
func TestParseFIReceiverFIReaderParseError(t *testing.T) {
var line = "{6100}Line Si® *"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIReceiverFI()
expected := r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "Line Si®")).Error()
require.EqualError(t, err, expected)
_, err = r.Read()
expected = r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "Line Si®")).Error()
require.EqualError(t, err, expected)
}
// TestFIReceiverFITagError validates a FIReceiverFI tag
func TestFIReceiverFITagError(t *testing.T) {
firfi := mockFIReceiverFI()
firfi.tag = "{9999}"
err := firfi.Validate()
require.EqualError(t, err, fieldError("tag", ErrValidTagForType, firfi.tag).Error())
}
// TestStringFIReceiverFIVariableLength parses using variable length
func TestStringFIReceiverFIVariableLength(t *testing.T) {
var line = "{6100}"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIReceiverFI()
require.Nil(t, err)
line = "{6100} NNN"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseFIReceiverFI()
require.ErrorContains(t, err, ErrRequireDelimiter.Error())
line = "{6100}********"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseFIReceiverFI()
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
line = "{6100}*"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseFIReceiverFI()
require.Equal(t, err, nil)
}
// TestStringFIReceiverFIOptions validates Format() formatted according to the FormatOptions
func TestStringFIReceiverFIOptions(t *testing.T) {
var line = "{6100}*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIReceiverFI()
require.Equal(t, err, nil)
record := r.currentFEDWireMessage.FIReceiverFI
require.Equal(t, record.String(), "{6100} * * * * * *")
require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6100}*")
require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false}))
}