-
Notifications
You must be signed in to change notification settings - Fork 40
/
fiIntermediaryFI_test.go
171 lines (127 loc) · 6.02 KB
/
fiIntermediaryFI_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
package wire
import (
"errors"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
// mockFIIntermediaryFI creates a FIIntermediaryFI
func mockFIIntermediaryFI() *FIIntermediaryFI {
fiifi := NewFIIntermediaryFI()
fiifi.FIToFI.LineOne = "Line One"
fiifi.FIToFI.LineOne = "Line Two"
fiifi.FIToFI.LineOne = "Line Three"
fiifi.FIToFI.LineOne = "Line Four"
fiifi.FIToFI.LineOne = "Line Five"
fiifi.FIToFI.LineOne = "Line Six"
return fiifi
}
// TestMockFIIntermediaryFI validates mockFIIntermediaryFI
func TestMockFIIntermediaryFI(t *testing.T) {
fiifi := mockFIIntermediaryFI()
require.NoError(t, fiifi.Validate(), "mockFIIntermediaryFI does not validate and will break other tests")
}
// TestFIIntermediaryFILineOneAlphaNumeric validates FIIntermediaryFI LineOne is alphanumeric
func TestFIIntermediaryFILineOneAlphaNumeric(t *testing.T) {
fiifi := mockFIIntermediaryFI()
fiifi.FIToFI.LineOne = "®"
err := fiifi.Validate()
require.EqualError(t, err, fieldError("LineOne", ErrNonAlphanumeric, fiifi.FIToFI.LineOne).Error())
}
// TestFIIntermediaryFILineTwoAlphaNumeric validates FIIntermediaryFI LineTwo is alphanumeric
func TestFIIntermediaryFILineTwoAlphaNumeric(t *testing.T) {
fiifi := mockFIIntermediaryFI()
fiifi.FIToFI.LineTwo = "®"
err := fiifi.Validate()
require.EqualError(t, err, fieldError("LineTwo", ErrNonAlphanumeric, fiifi.FIToFI.LineTwo).Error())
}
// TestFIIntermediaryFILineThreeAlphaNumeric validates FIIntermediaryFI LineThree is alphanumeric
func TestFIIntermediaryFILineThreeAlphaNumeric(t *testing.T) {
fiifi := mockFIIntermediaryFI()
fiifi.FIToFI.LineThree = "®"
err := fiifi.Validate()
require.EqualError(t, err, fieldError("LineThree", ErrNonAlphanumeric, fiifi.FIToFI.LineThree).Error())
}
// TestFIIntermediaryFILineFourAlphaNumeric validates FIIntermediaryFI LineFour is alphanumeric
func TestFIIntermediaryFILineFourAlphaNumeric(t *testing.T) {
fiifi := mockFIIntermediaryFI()
fiifi.FIToFI.LineFour = "®"
err := fiifi.Validate()
require.EqualError(t, err, fieldError("LineFour", ErrNonAlphanumeric, fiifi.FIToFI.LineFour).Error())
}
// TestFIIntermediaryFILineFiveAlphaNumeric validates FIIntermediaryFI LineFive is alphanumeric
func TestFIIntermediaryFILineFiveAlphaNumeric(t *testing.T) {
fiifi := mockFIIntermediaryFI()
fiifi.FIToFI.LineFive = "®"
err := fiifi.Validate()
require.EqualError(t, err, fieldError("LineFive", ErrNonAlphanumeric, fiifi.FIToFI.LineFive).Error())
}
// TestFIIntermediaryFILineSixAlphaNumeric validates FIIntermediaryFI LineSix is alphanumeric
func TestFIIntermediaryFILineSixAlphaNumeric(t *testing.T) {
fiifi := mockFIIntermediaryFI()
fiifi.FIToFI.LineSix = "®"
err := fiifi.Validate()
require.EqualError(t, err, fieldError("LineSix", ErrNonAlphanumeric, fiifi.FIToFI.LineSix).Error())
}
// TestParseFIIntermediaryFIWrongLength parses a wrong FIIntermediaryFI record length
func TestParseFIIntermediaryFIWrongLength(t *testing.T) {
var line = "{6200}Line ®ix "
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIIntermediaryFI()
require.EqualError(t, err, r.parseError(fieldError("LineOne", ErrRequireDelimiter)).Error())
}
// TestParseFIIntermediaryFIReaderParseError parses a wrong FIIntermediaryFI reader parse error
func TestParseFIIntermediaryFIReaderParseError(t *testing.T) {
var line = "{6200}Line ®ix *"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIIntermediaryFI()
expected := r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "Line ®ix")).Error()
require.EqualError(t, err, expected)
_, err = r.Read()
expected = r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "Line ®ix")).Error()
require.EqualError(t, err, expected)
}
// TestFIIntermediaryFITagError validates a FIIntermediaryFI tag
func TestFIIntermediaryFITagError(t *testing.T) {
fiifi := mockFIIntermediaryFI()
fiifi.tag = "{9999}"
err := fiifi.Validate()
require.EqualError(t, err, fieldError("tag", ErrValidTagForType, fiifi.tag).Error())
}
// TestStringFIIntermediaryFIVariableLength parses using variable length
func TestStringFIIntermediaryFIVariableLength(t *testing.T) {
var line = "{6200}"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIIntermediaryFI()
require.Nil(t, err)
line = "{6200} NNN"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseFIIntermediaryFI()
require.ErrorContains(t, err, ErrRequireDelimiter.Error())
line = "{6200}********"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseFIIntermediaryFI()
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
line = "{6200}*"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseFIIntermediaryFI()
require.Equal(t, err, nil)
}
// TestStringFIIntermediaryFIOptions validates Format() formatted according to the FormatOptions
func TestStringFIIntermediaryFIOptions(t *testing.T) {
var line = "{6200}*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIIntermediaryFI()
require.Equal(t, err, nil)
record := r.currentFEDWireMessage.FIIntermediaryFI
require.Equal(t, record.String(), "{6200} * * * * * *")
require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6200}*")
require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false}))
}