Skip to content

Commit

Permalink
test coverage
Browse files Browse the repository at this point in the history
go vet, go fmt
  • Loading branch information
bkmoovio committed May 8, 2019
1 parent 00d66f5 commit da8ac09
Show file tree
Hide file tree
Showing 50 changed files with 280 additions and 88 deletions.
2 changes: 1 addition & 1 deletion accountCreditedDrawdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func NewAccountCreditedDrawdown() *AccountCreditedDrawdown {
// Parse provides no guarantee about all fields being filled in. Callers should make a Validate() call to confirm
// successful parsing and data validity.
func (creditDD *AccountCreditedDrawdown) Parse(record string) error {
if utf8.RuneCountInString(record) != 15 {
if utf8.RuneCountInString(record) != 15 {
return NewTagWrongLengthErr(15, len(record))
}
creditDD.tag = record[:6]
Expand Down
2 changes: 1 addition & 1 deletion accountCreditedDrawdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ func TestParseAccountCreditedDrawdownReaderParseError(t *testing.T) {
t.Errorf("%T: %s", err, err)
}
}
}
}
2 changes: 1 addition & 1 deletion accountDebitedDrawdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewAccountDebitedDrawdown() *AccountDebitedDrawdown {
// Parse provides no guarantee about all fields being filled in. Callers should make a Validate() call to confirm
// successful parsing and data validity.
func (debitDD *AccountDebitedDrawdown) Parse(record string) error {
if utf8.RuneCountInString(record) != 181 {
if utf8.RuneCountInString(record) != 181 {
return NewTagWrongLengthErr(181, len(record))
}
debitDD.tag = record[:6]
Expand Down
2 changes: 1 addition & 1 deletion accountDebitedDrawdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,4 @@ func TestParseAccountDebitedDrawdownReaderParseError(t *testing.T) {
t.Errorf("%T: %s", err, err)
}
}
}
}
2 changes: 1 addition & 1 deletion amount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,4 @@ func TestParseAmountReaderParseError(t *testing.T) {
t.Errorf("%T: %s", err, err)
}
}
}
}
2 changes: 1 addition & 1 deletion beneficiary.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func NewBeneficiary() *Beneficiary {
// Parse provides no guarantee about all fields being filled in. Callers should make a Validate() call to confirm
// successful parsing and data validity.
func (ben *Beneficiary) Parse(record string) error {
if utf8.RuneCountInString(record) != 181 {
if utf8.RuneCountInString(record) != 181 {
return NewTagWrongLengthErr(181, len(record))
}
ben.tag = record[:6]
Expand Down
2 changes: 1 addition & 1 deletion beneficiaryFI.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func NewBeneficiaryFI() *BeneficiaryFI {
// Parse provides no guarantee about all fields being filled in. Callers should make a Validate() call to confirm
// successful parsing and data validity.
func (bfi *BeneficiaryFI) Parse(record string) error {
if utf8.RuneCountInString(record) != 181 {
if utf8.RuneCountInString(record) != 181 {
return NewTagWrongLengthErr(181, len(record))
}
bfi.tag = record[:6]
Expand Down
2 changes: 1 addition & 1 deletion beneficiaryFI_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,4 @@ func TestParseBeneficiaryFIReaderParseError(t *testing.T) {
t.Errorf("%T: %s", err, err)
}
}
}
}
2 changes: 1 addition & 1 deletion beneficiaryIntermediaryFI.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func NewBeneficiaryIntermediaryFI() *BeneficiaryIntermediaryFI {
// Parse provides no guarantee about all fields being filled in. Callers should make a Validate() call to confirm
// successful parsing and data validity.
func (bifi *BeneficiaryIntermediaryFI) Parse(record string) error {
if utf8.RuneCountInString(record) != 181 {
if utf8.RuneCountInString(record) != 181 {
return NewTagWrongLengthErr(181, len(record))
}
bifi.tag = record[:6]
Expand Down
2 changes: 1 addition & 1 deletion beneficiaryIntermediaryFI_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,4 @@ func TestParseBeneficiaryIntermediaryFIReaderParseError(t *testing.T) {
t.Errorf("%T: %s", err, err)
}
}
}
}
2 changes: 1 addition & 1 deletion beneficiaryReference.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func NewBeneficiaryReference() *BeneficiaryReference {
// Parse provides no guarantee about all fields being filled in. Callers should make a Validate() call to confirm
// successful parsing and data validity.
func (br *BeneficiaryReference) Parse(record string) error {
if utf8.RuneCountInString(record) != 22 {
if utf8.RuneCountInString(record) != 22 {
return NewTagWrongLengthErr(22, len(record))
}
br.tag = record[:6]
Expand Down
2 changes: 1 addition & 1 deletion beneficiaryReference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ func TestParseBeneficiaryReferenceReaderParseError(t *testing.T) {
t.Errorf("%T: %s", err, err)
}
}
}
}
2 changes: 1 addition & 1 deletion beneficiary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,4 @@ func TestParseBeneficiaryReaderParseError(t *testing.T) {
t.Errorf("%T: %s", err, err)
}
}
}
}
2 changes: 1 addition & 1 deletion businessFunctionCode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ func TestParseBusinessFunctionCodeReaderParseError(t *testing.T) {
t.Errorf("%T: %s", err, err)
}
}
}
}
2 changes: 1 addition & 1 deletion exchangeRate.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewExchangeRate() *ExchangeRate {
// Parse provides no guarantee about all fields being filled in. Callers should make a Validate() call to confirm
// successful parsing and data validity.
func (eRate *ExchangeRate) Parse(record string) error {
if utf8.RuneCountInString(record) != 18 {
if utf8.RuneCountInString(record) != 18 {
return NewTagWrongLengthErr(18, len(record))
}
eRate.tag = record[:6]
Expand Down
2 changes: 1 addition & 1 deletion exchangeRate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ func TestParseExchangeRateReaderParseError(t *testing.T) {
t.Errorf("%T: %s", err, err)
}
}
}
}
25 changes: 16 additions & 9 deletions fiAdditionalFIToFI.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

package wire

import "strings"
import (
"strings"
"unicode/utf8"
)

// FIAdditionalFIToFI is the financial institution beneficiary financial institution
type FIAdditionalFIToFI struct {
Expand All @@ -31,20 +34,24 @@ func NewFIAdditionalFIToFI() *FIAdditionalFIToFI {
//
// Parse provides no guarantee about all fields being filled in. Callers should make a Validate() call to confirm
// successful parsing and data validity.
func (fifi *FIAdditionalFIToFI) Parse(record string) {
func (fifi *FIAdditionalFIToFI) Parse(record string) error {
if utf8.RuneCountInString(record) != 216 {
return NewTagWrongLengthErr(216, len(record))
}
fifi.tag = record[:6]
fifi.AdditionalFIToFI.LineOne = fifi.parseStringField(record[6:36])
fifi.AdditionalFIToFI.LineTwo = fifi.parseStringField(record[36:71])
fifi.AdditionalFIToFI.LineThree = fifi.parseStringField(record[71:106])
fifi.AdditionalFIToFI.LineFour = fifi.parseStringField(record[106:141])
fifi.AdditionalFIToFI.LineFive = fifi.parseStringField(record[141:176])
fifi.AdditionalFIToFI.LineSix = fifi.parseStringField(record[176:211])
fifi.AdditionalFIToFI.LineOne = fifi.parseStringField(record[6:41])
fifi.AdditionalFIToFI.LineTwo = fifi.parseStringField(record[41:76])
fifi.AdditionalFIToFI.LineThree = fifi.parseStringField(record[76:111])
fifi.AdditionalFIToFI.LineFour = fifi.parseStringField(record[111:146])
fifi.AdditionalFIToFI.LineFive = fifi.parseStringField(record[146:181])
fifi.AdditionalFIToFI.LineSix = fifi.parseStringField(record[181:216])
return nil
}

// String writes FIAdditionalFIToFI
func (fifi *FIAdditionalFIToFI) String() string {
var buf strings.Builder
buf.Grow(211)
buf.Grow(216)
buf.WriteString(fifi.tag)
buf.WriteString(fifi.LineOneField())
buf.WriteString(fifi.LineTwoField())
Expand Down
39 changes: 39 additions & 0 deletions fiAdditionalFIToFI_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package wire

import (
"github.com/moov-io/base"
"strings"
"testing"
)

Expand Down Expand Up @@ -90,3 +91,41 @@ func TestFIAdditionalFIToFILineSixAlphaNumeric(t *testing.T) {
}
}
}

// 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
fwm := new(FEDWireMessage)
fifi := mockFIAdditionalFIToFI()
fwm.SetFIAdditionalFIToFI(fifi)
err := r.parseFIAdditionalFIToFI()
if err != nil {
if !base.Match(err, NewTagWrongLengthErr(216, len(r.line))) {
t.Errorf("%T: %s", err, err)
}
}
}

// 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
fwm := new(FEDWireMessage)
fifi := mockFIAdditionalFIToFI()
fwm.SetFIAdditionalFIToFI(fifi)
err := r.parseFIAdditionalFIToFI()
if err != nil {
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
_, err = r.Read()
if err != nil {
if !base.Has(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
}
11 changes: 9 additions & 2 deletions fiBeneficiary.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

package wire

import "strings"
import (
"strings"
"unicode/utf8"
)

// FIBeneficiary is the financial institution beneficiary
type FIBeneficiary struct {
Expand All @@ -31,14 +34,18 @@ func NewFIBeneficiary() *FIBeneficiary {
//
// Parse provides no guarantee about all fields being filled in. Callers should make a Validate() call to confirm
// successful parsing and data validity.
func (fib *FIBeneficiary) Parse(record string) {
func (fib *FIBeneficiary) Parse(record string) error {
if utf8.RuneCountInString(record) != 201 {
return NewTagWrongLengthErr(201, len(record))
}
fib.tag = record[:6]
fib.FIToFI.LineOne = fib.parseStringField(record[6:36])
fib.FIToFI.LineTwo = fib.parseStringField(record[36:69])
fib.FIToFI.LineThree = fib.parseStringField(record[69:102])
fib.FIToFI.LineFour = fib.parseStringField(record[102:135])
fib.FIToFI.LineFive = fib.parseStringField(record[135:168])
fib.FIToFI.LineSix = fib.parseStringField(record[168:201])
return nil
}

// String writes FIBeneficiary
Expand Down
11 changes: 9 additions & 2 deletions fiBeneficiaryFI.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

package wire

import "strings"
import (
"strings"
"unicode/utf8"
)

// FIBeneficiaryFI is the financial institution beneficiary financial institution
type FIBeneficiaryFI struct {
Expand All @@ -31,14 +34,18 @@ func NewFIBeneficiaryFI() *FIBeneficiaryFI {
//
// Parse provides no guarantee about all fields being filled in. Callers should make a Validate() call to confirm
// successful parsing and data validity.
func (fibfi *FIBeneficiaryFI) Parse(record string) {
func (fibfi *FIBeneficiaryFI) Parse(record string) error {
if utf8.RuneCountInString(record) != 201 {
return NewTagWrongLengthErr(201, len(record))
}
fibfi.tag = record[:6]
fibfi.FIToFI.LineOne = fibfi.parseStringField(record[6:36])
fibfi.FIToFI.LineTwo = fibfi.parseStringField(record[36:69])
fibfi.FIToFI.LineThree = fibfi.parseStringField(record[69:102])
fibfi.FIToFI.LineFour = fibfi.parseStringField(record[102:135])
fibfi.FIToFI.LineFive = fibfi.parseStringField(record[135:168])
fibfi.FIToFI.LineSix = fibfi.parseStringField(record[168:201])
return nil
}

// String writes FIBeneficiaryFI
Expand Down
39 changes: 39 additions & 0 deletions fiBeneficiaryFI_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package wire

import (
"github.com/moov-io/base"
"strings"
"testing"
)

Expand Down Expand Up @@ -90,3 +91,41 @@ func TestFIBeneficiaryFILineSixAlphaNumeric(t *testing.T) {
}
}
}

// TestParseFIBeneficiaryFIWrongLength parses a wrong FIBeneficiaryFI record length
func TestParseFIBeneficiaryFIWrongLength(t *testing.T) {
var line = "{6100}Line Six "
r := NewReader(strings.NewReader(line))
r.line = line
fwm := new(FEDWireMessage)
fibfi := mockFIBeneficiaryFI()
fwm.SetFIBeneficiaryFI(fibfi)
err := r.parseFIBeneficiaryFI()
if err != nil {
if !base.Match(err, NewTagWrongLengthErr(201, len(r.line))) {
t.Errorf("%T: %s", err, err)
}
}
}

// TestParseFIBeneficiaryFIReaderParseError parses a wrong FIBeneficiaryFI reader parse error
func TestParseFIBeneficiaryFIReaderParseError(t *testing.T) {
var line = "{6100}Line Si® "
r := NewReader(strings.NewReader(line))
r.line = line
fwm := new(FEDWireMessage)
fibfi := mockFIBeneficiaryFI()
fwm.SetFIBeneficiaryFI(fibfi)
err := r.parseFIBeneficiaryFI()
if err != nil {
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
_, err = r.Read()
if err != nil {
if !base.Has(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
}
39 changes: 39 additions & 0 deletions fiBeneficiary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package wire

import (
"github.com/moov-io/base"
"strings"
"testing"
)

Expand Down Expand Up @@ -90,3 +91,41 @@ func TestFIBeneficiaryLineSixAlphaNumeric(t *testing.T) {
}
}
}

// TestParseFIBeneficiaryWrongLength parses a wrong FIBeneficiary record length
func TestParseFIBeneficiaryWrongLength(t *testing.T) {
var line = "{6100}Line Six "
r := NewReader(strings.NewReader(line))
r.line = line
fwm := new(FEDWireMessage)
fib := mockFIBeneficiary()
fwm.SetFIBeneficiary(fib)
err := r.parseFIBeneficiary()
if err != nil {
if !base.Match(err, NewTagWrongLengthErr(201, len(r.line))) {
t.Errorf("%T: %s", err, err)
}
}
}

// TestParseFIBeneficiaryReaderParseError parses a wrong FIBeneficiary reader parse error
func TestParseFIBeneficiaryReaderParseError(t *testing.T) {
var line = "{6100}Line Si® "
r := NewReader(strings.NewReader(line))
r.line = line
fwm := new(FEDWireMessage)
fib := mockFIBeneficiary()
fwm.SetFIBeneficiary(fib)
err := r.parseFIBeneficiary()
if err != nil {
if !base.Match(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
_, err = r.Read()
if err != nil {
if !base.Has(err, ErrNonAlphanumeric) {
t.Errorf("%T: %s", err, err)
}
}
}
Loading

0 comments on commit da8ac09

Please sign in to comment.