-
Notifications
You must be signed in to change notification settings - Fork 39
/
fiAdditionalFIToFI_test.go
171 lines (127 loc) · 6.32 KB
/
fiAdditionalFIToFI_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"
)
// mockFIAdditionalFIToFI creates a FIAdditionalFIToFI
func mockFIAdditionalFIToFI() *FIAdditionalFIToFI {
fifi := NewFIAdditionalFIToFI()
fifi.AdditionalFIToFI.LineOne = "Line One"
fifi.AdditionalFIToFI.LineTwo = "Line Two"
fifi.AdditionalFIToFI.LineThree = "Line Three"
fifi.AdditionalFIToFI.LineFour = "Line Four"
fifi.AdditionalFIToFI.LineFive = "Line Five"
fifi.AdditionalFIToFI.LineSix = "Line Six"
return fifi
}
// TestMockFIAdditionalFIToFI validates mockFIAdditionalFIToFI
func TestMockFIAdditionalFIToFI(t *testing.T) {
fifi := mockFIAdditionalFIToFI()
require.NoError(t, fifi.Validate(), "mockFIAdditionalFIToFI does not validate and will break other tests")
}
// TestFIAdditionalFIToFILineOneAlphaNumeric validates FIAdditionalFIToFI LineOne is alphanumeric
func TestFIAdditionalFIToFILineOneAlphaNumeric(t *testing.T) {
fifi := mockFIAdditionalFIToFI()
fifi.AdditionalFIToFI.LineOne = "®"
err := fifi.Validate()
require.EqualError(t, err, fieldError("LineOne", ErrNonAlphanumeric, fifi.AdditionalFIToFI.LineOne).Error())
}
// TestFIAdditionalFIToFILineTwoAlphaNumeric validates FIAdditionalFIToFI LineTwo is alphanumeric
func TestFIAdditionalFIToFILineTwoAlphaNumeric(t *testing.T) {
fifi := mockFIAdditionalFIToFI()
fifi.AdditionalFIToFI.LineTwo = "®"
err := fifi.Validate()
require.EqualError(t, err, fieldError("LineTwo", ErrNonAlphanumeric, fifi.AdditionalFIToFI.LineTwo).Error())
}
// TestFIAdditionalFIToFILineThreeAlphaNumeric validates FIAdditionalFIToFI LineThree is alphanumeric
func TestFIAdditionalFIToFILineThreeAlphaNumeric(t *testing.T) {
fifi := mockFIAdditionalFIToFI()
fifi.AdditionalFIToFI.LineThree = "®"
err := fifi.Validate()
require.EqualError(t, err, fieldError("LineThree", ErrNonAlphanumeric, fifi.AdditionalFIToFI.LineThree).Error())
}
// TestFIAdditionalFIToFILineFourAlphaNumeric validates FIAdditionalFIToFI LineFour is alphanumeric
func TestFIAdditionalFIToFILineFourAlphaNumeric(t *testing.T) {
fifi := mockFIAdditionalFIToFI()
fifi.AdditionalFIToFI.LineFour = "®"
err := fifi.Validate()
require.EqualError(t, err, fieldError("LineFour", ErrNonAlphanumeric, fifi.AdditionalFIToFI.LineFour).Error())
}
// TestFIAdditionalFIToFILineFiveAlphaNumeric validates FIAdditionalFIToFI LineFive is alphanumeric
func TestFIAdditionalFIToFILineFiveAlphaNumeric(t *testing.T) {
fifi := mockFIAdditionalFIToFI()
fifi.AdditionalFIToFI.LineFive = "®"
err := fifi.Validate()
require.EqualError(t, err, fieldError("LineFive", ErrNonAlphanumeric, fifi.AdditionalFIToFI.LineFive).Error())
}
// TestFIAdditionalFIToFILineSixAlphaNumeric validates FIAdditionalFIToFI LineSix is alphanumeric
func TestFIAdditionalFIToFILineSixAlphaNumeric(t *testing.T) {
fifi := mockFIAdditionalFIToFI()
fifi.AdditionalFIToFI.LineSix = "®"
err := fifi.Validate()
require.EqualError(t, err, fieldError("LineSix", ErrNonAlphanumeric, fifi.AdditionalFIToFI.LineSix).Error())
}
// TestParseFIAdditionalFIToFIWrongLength parses a wrong FIAdditionalFIToFI record length
func TestParseFIAdditionalFIToFIWrongLength(t *testing.T) {
var line = "{6500}Line One Line Two Line Three Line Four Line Five Line Six "
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIAdditionalFIToFI()
require.EqualError(t, err, r.parseError(fieldError("LineOne", ErrRequireDelimiter)).Error())
}
// TestParseFIAdditionalFIToFIReaderParseError parses a wrong FIAdditionalFIToFI reader parse error
func TestParseFIAdditionalFIToFIReaderParseError(t *testing.T) {
var line = "{6500}®ine One *Line Two *Line Three *Line Four *Line Five *Line Six *"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIAdditionalFIToFI()
expected := r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "®ine One")).Error()
require.EqualError(t, err, expected)
_, err = r.Read()
expected = r.parseError(fieldError("LineOne", ErrNonAlphanumeric, "®ine One")).Error()
require.EqualError(t, err, expected)
}
// TestFIAdditionalFIToFITagError validates a FIAdditionalFIToFI tag
func TestFIAdditionalFIToFITagError(t *testing.T) {
fifi := mockFIAdditionalFIToFI()
fifi.tag = "{9999}"
err := fifi.Validate()
require.EqualError(t, err, fieldError("tag", ErrValidTagForType, fifi.tag).Error())
}
// TestStringFIAdditionalFIToFIVariableLength parses using variable length
func TestStringFIAdditionalFIToFIVariableLength(t *testing.T) {
var line = "{6500}"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIAdditionalFIToFI()
require.Nil(t, err)
line = "{6500} NNN"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseFIAdditionalFIToFI()
require.ErrorContains(t, err, ErrRequireDelimiter.Error())
line = "{6500}********"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseFIAdditionalFIToFI()
require.ErrorContains(t, err, r.parseError(NewTagMaxLengthErr(errors.New(""))).Error())
line = "{6500}*"
r = NewReader(strings.NewReader(line))
r.line = line
err = r.parseFIAdditionalFIToFI()
require.Equal(t, err, nil)
}
// TestStringFIAdditionalFIToFIOptions validates Format() formatted according to the FormatOptions
func TestStringFIAdditionalFIToFIOptions(t *testing.T) {
var line = "{6500}*"
r := NewReader(strings.NewReader(line))
r.line = line
err := r.parseFIAdditionalFIToFI()
require.Equal(t, err, nil)
record := r.currentFEDWireMessage.FIAdditionalFIToFI
require.Equal(t, record.String(), "{6500} * * * * * *")
require.Equal(t, record.Format(FormatOptions{VariableLengthFields: true}), "{6500}*")
require.Equal(t, record.String(), record.Format(FormatOptions{VariableLengthFields: false}))
}