From a4f8112575e625a88dfb645b362cae314d750361 Mon Sep 17 00:00:00 2001 From: Daniel Tonks Date: Wed, 28 Oct 2020 10:14:49 -0600 Subject: [PATCH] refactor unit tests - through fiIntermediaryFIAdvice --- beneficiaryCustomer_test.go | 121 +++++++++++------------ beneficiaryFI_test.go | 141 +++++++++++++-------------- beneficiaryIntermediaryFI.go | 2 +- beneficiaryIntermediaryFI_test.go | 138 +++++++++++++------------- beneficiaryReference_test.go | 61 +++++------- businessFunctionCode_test.go | 75 +++++++------- charges_test.go | 26 +++-- currencyInstructedAmount_test.go | 73 ++++++-------- dateRemittanceDocument_test.go | 61 +++++------- errorWire_test.go | 46 +++------ exchangeRate_test.go | 61 +++++------- fIBeneficiaryFIAdvice_test.go | 121 +++++++++++------------ fiAdditionalFIToFI_test.go | 115 +++++++++++----------- fiBeneficiaryAdvice_test.go | 120 +++++++++++------------ fiBeneficiaryFI_test.go | 111 ++++++++++----------- fiBeneficiary_test.go | 111 ++++++++++----------- fiDrawdownDebitAccountAdvice_test.go | 121 +++++++++++------------ fiIntermediaryFIAdvice_test.go | 119 ++++++++++------------ fiIntermediaryFI_test.go | 111 ++++++++++----------- 19 files changed, 789 insertions(+), 945 deletions(-) diff --git a/beneficiaryCustomer_test.go b/beneficiaryCustomer_test.go index 5e704ed6..0896f010 100644 --- a/beneficiaryCustomer_test.go +++ b/beneficiaryCustomer_test.go @@ -1,9 +1,10 @@ package wire import ( - "github.com/moov-io/base" "strings" "testing" + + "github.com/stretchr/testify/require" ) // mockBeneficiaryCustomer creates a BeneficiaryCustomer @@ -21,86 +22,85 @@ func mockBeneficiaryCustomer() *BeneficiaryCustomer { // TestMockBeneficiaryCustomer validates mockBeneficiaryCustomer func TestMockBeneficiaryCustomer(t *testing.T) { bc := mockBeneficiaryCustomer() - if err := bc.Validate(); err != nil { - t.Error("mockBeneficiaryCustomer does not validate and will break other tests") - } + + require.NoError(t, bc.Validate(), "mockBeneficiaryCustomer does not validate and will break other tests") } // TestBeneficiaryCustomerSwiftFieldTagAlphaNumeric validates BeneficiaryCustomer SwiftFieldTag is alphanumeric func TestBeneficiaryCustomerSwiftFieldTagAlphaNumeric(t *testing.T) { bc := mockBeneficiaryCustomer() bc.CoverPayment.SwiftFieldTag = "®" - if err := bc.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := bc.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("SwiftFieldTag", ErrNonAlphanumeric, bc.CoverPayment.SwiftFieldTag).Error(), err.Error()) } // TestBeneficiaryCustomerSwiftLineOneAlphaNumeric validates BeneficiaryCustomer SwiftLineOne is alphanumeric func TestBeneficiaryCustomerSwiftLineOneAlphaNumeric(t *testing.T) { bc := mockBeneficiaryCustomer() bc.CoverPayment.SwiftLineOne = "®" - if err := bc.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := bc.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("SwiftLineOne", ErrNonAlphanumeric, bc.CoverPayment.SwiftLineOne).Error(), err.Error()) } // TestBeneficiaryCustomerSwiftLineTwoAlphaNumeric validates BeneficiaryCustomer SwiftLineTwo is alphanumeric func TestBeneficiaryCustomerSwiftLineTwoAlphaNumeric(t *testing.T) { bc := mockBeneficiaryCustomer() bc.CoverPayment.SwiftLineTwo = "®" - if err := bc.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := bc.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("SwiftLineTwo", ErrNonAlphanumeric, bc.CoverPayment.SwiftLineTwo).Error(), err.Error()) } // TestBeneficiaryCustomerSwiftLineThreeAlphaNumeric validates BeneficiaryCustomer SwiftLineThree is alphanumeric func TestBeneficiaryCustomerSwiftLineThreeAlphaNumeric(t *testing.T) { bc := mockBeneficiaryCustomer() bc.CoverPayment.SwiftLineThree = "®" - if err := bc.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := bc.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("SwiftLineThree", ErrNonAlphanumeric, bc.CoverPayment.SwiftLineThree).Error(), err.Error()) } // TestBeneficiaryCustomerSwiftLineFourAlphaNumeric validates BeneficiaryCustomer SwiftLineFour is alphanumeric func TestBeneficiaryCustomerSwiftLineFourAlphaNumeric(t *testing.T) { bc := mockBeneficiaryCustomer() bc.CoverPayment.SwiftLineFour = "®" - if err := bc.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := bc.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("SwiftLineFour", ErrNonAlphanumeric, bc.CoverPayment.SwiftLineFour).Error(), err.Error()) } // TestBeneficiaryCustomerSwiftLineFiveAlphaNumeric validates BeneficiaryCustomer SwiftLineFive is alphanumeric func TestBeneficiaryCustomerSwiftLineFiveAlphaNumeric(t *testing.T) { bc := mockBeneficiaryCustomer() bc.CoverPayment.SwiftLineFive = "®" - if err := bc.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := bc.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("SwiftLineFive", ErrNonAlphanumeric, bc.CoverPayment.SwiftLineFive).Error(), err.Error()) } // TestBeneficiaryCustomerSwiftLineSixAlphaNumeric validates BeneficiaryCustomer SwiftLineSix is alphanumeric func TestBeneficiaryCustomerSwiftLineSixAlphaNumeric(t *testing.T) { sr := mockBeneficiaryCustomer() sr.CoverPayment.SwiftLineSix = "Test" - if err := sr.Validate(); err != nil { - if !base.Match(err, ErrInvalidProperty) { - t.Errorf("%T: %s", err, err) - } - } + + err := sr.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("SwiftLineSix", ErrInvalidProperty, sr.CoverPayment.SwiftLineSix).Error(), err.Error()) } // TestParseBeneficiaryCustomerWrongLength parses a wrong BeneficiaryCustomer record length @@ -108,15 +108,11 @@ func TestParseBeneficiaryCustomerWrongLength(t *testing.T) { var line = "{7059}SwiftSwift Line One Swift Line Two Swift Line Three Swift Line Four Swift Line Five " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - bc := mockBeneficiaryCustomer() - fwm.SetBeneficiaryCustomer(bc) + err := r.parseBeneficiaryCustomer() - if err != nil { - if !base.Match(err, NewTagWrongLengthErr(186, len(r.line))) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), NewTagWrongLengthErr(186, len(r.line)).Error()) } // TestParseBeneficiaryCustomerReaderParseError parses a wrong BeneficiaryCustomer reader parse error @@ -124,30 +120,25 @@ func TestParseBeneficiaryCustomerReaderParseError(t *testing.T) { var line = "{7059}SwiftSwift ®ine One Swift Line Two Swift Line Three Swift Line Four Swift Line Five " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - bc := mockBeneficiaryCustomer() - fwm.SetBeneficiaryCustomer(bc) + err := r.parseBeneficiaryCustomer() - if err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + _, err = r.Read() - if err != nil { - if !base.Has(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) } // TestBeneficiaryCustomerTagError validates a BeneficiaryCustomer tag func TestBeneficiaryCustomerTagError(t *testing.T) { bc := mockBeneficiaryCustomer() bc.tag = "{9999}" - if err := bc.Validate(); err != nil { - if !base.Match(err, ErrValidTagForType) { - t.Errorf("%T: %s", err, err) - } - } + + err := bc.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("tag", ErrValidTagForType, bc.tag).Error(), err.Error()) } diff --git a/beneficiaryFI_test.go b/beneficiaryFI_test.go index 2847a91b..12624664 100644 --- a/beneficiaryFI_test.go +++ b/beneficiaryFI_test.go @@ -1,9 +1,10 @@ package wire import ( - "github.com/moov-io/base" "strings" "testing" + + "github.com/stretchr/testify/require" ) // mockBeneficiaryFI creates a BeneficiaryFI @@ -21,108 +22,107 @@ func mockBeneficiaryFI() *BeneficiaryFI { // TestMockBeneficiaryFI validates mockBeneficiaryFI func TestMockBeneficiaryFI(t *testing.T) { bfi := mockBeneficiaryFI() - if err := bfi.Validate(); err != nil { - t.Error("mockBeneficiaryFI does not validate and will break other tests") - } + + require.NoError(t, bfi.Validate(), "mockBeneficiaryFI does not validate and will break other tests") } // TestBeneficiaryFIIdentificationCodeValid validates BeneficiaryFI IdentificationCode func TestBeneficiaryFIIdentificationCodeValid(t *testing.T) { bfi := mockBeneficiaryFI() bfi.FinancialInstitution.IdentificationCode = "Football Card ID" - if err := bfi.Validate(); err != nil { - if !base.Match(err, ErrIdentificationCode) { - t.Errorf("%T: %s", err, err) - } - } + + err := bfi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("IdentificationCode", ErrIdentificationCode, bfi.FinancialInstitution.IdentificationCode).Error(), err.Error()) } // TestBeneficiaryFIIdentificationCodeFI validates BeneficiaryFI IdentificationCode is an FI code func TestBeneficiaryFIIdentificationCodeFI(t *testing.T) { bfi := mockBeneficiaryFI() bfi.FinancialInstitution.IdentificationCode = "1" - if err := bfi.Validate(); err != nil { - if !base.Match(err, ErrIdentificationCode) { - t.Errorf("%T: %s", err, err) - } - } + + err := bfi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("IdentificationCode", ErrIdentificationCode, bfi.FinancialInstitution.IdentificationCode).Error(), err.Error()) } // TestBeneficiaryFIIdentifierAlphaNumeric validates BeneficiaryFI Identifier is alphanumeric func TestBeneficiaryFIIdentifierAlphaNumeric(t *testing.T) { bfi := mockBeneficiaryFI() bfi.FinancialInstitution.Identifier = "®" - if err := bfi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := bfi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("Identifier", ErrNonAlphanumeric, bfi.FinancialInstitution.Identifier).Error(), err.Error()) } // TestBeneficiaryFINameAlphaNumeric validates BeneficiaryFI Name is alphanumeric func TestBeneficiaryFINameAlphaNumeric(t *testing.T) { bfi := mockBeneficiaryFI() bfi.FinancialInstitution.Name = "®" - if err := bfi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := bfi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("Name", ErrNonAlphanumeric, bfi.FinancialInstitution.Name).Error(), err.Error()) } // TestBeneficiaryFIAddressLineOneAlphaNumeric validates BeneficiaryFI AddressLineOne is alphanumeric func TestBeneficiaryFIAddressLineOneAlphaNumeric(t *testing.T) { bfi := mockBeneficiaryFI() bfi.FinancialInstitution.Address.AddressLineOne = "®" - if err := bfi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := bfi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("AddressLineOne", ErrNonAlphanumeric, bfi.FinancialInstitution.Address.AddressLineOne).Error(), err.Error()) } // TestBeneficiaryFIAddressLineTwoAlphaNumeric validates BeneficiaryFI AddressLineTwo is alphanumeric func TestBeneficiaryFIAddressLineTwoAlphaNumeric(t *testing.T) { bfi := mockBeneficiaryFI() bfi.FinancialInstitution.Address.AddressLineTwo = "®" - if err := bfi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := bfi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("AddressLineTwo", ErrNonAlphanumeric, bfi.FinancialInstitution.Address.AddressLineTwo).Error(), err.Error()) } // TestBeneficiaryFIAddressLineThreeAlphaNumeric validates BeneficiaryFI AddressLineThree is alphanumeric func TestBeneficiaryFIAddressLineThreeAlphaNumeric(t *testing.T) { bfi := mockBeneficiaryFI() bfi.FinancialInstitution.Address.AddressLineThree = "®" - if err := bfi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := bfi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("AddressLineThree", ErrNonAlphanumeric, bfi.FinancialInstitution.Address.AddressLineThree).Error(), err.Error()) } // TestBeneficiaryFIIdentificationCodeRequired validates BeneficiaryFI IdentificationCode is required func TestBeneficiaryFIIdentificationCodeRequired(t *testing.T) { bfi := mockBeneficiaryFI() bfi.FinancialInstitution.IdentificationCode = "" - if err := bfi.Validate(); err != nil { - if !base.Match(err, ErrFieldRequired) { - t.Errorf("%T: %s", err, err) - } - } + + err := bfi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("IdentificationCode", ErrFieldRequired).Error(), err.Error()) } // TestBeneficiaryFIIdentifierRequired validates BeneficiaryFI Identifier is required func TestBeneficiaryFIIdentifierRequired(t *testing.T) { bfi := mockBeneficiaryFI() bfi.FinancialInstitution.Identifier = "" - if err := bfi.Validate(); err != nil { - if !base.Match(err, ErrFieldRequired) { - t.Errorf("%T: %s", err, err) - } - } + + err := bfi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("Identifier", ErrFieldRequired).Error(), err.Error()) } // TestParseBeneficiaryFIWrongLength parses a wrong BeneficiaryFI record length @@ -130,15 +130,11 @@ func TestParseBeneficiaryFIWrongLength(t *testing.T) { var line = "{4100}D123456789 FI Name Address One Address Two Address Three " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - bfi := mockBeneficiaryFI() - fwm.SetBeneficiaryFI(bfi) + err := r.parseBeneficiaryFI() - if err != nil { - if !base.Match(err, NewTagWrongLengthErr(181, len(r.line))) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), NewTagWrongLengthErr(181, len(r.line)).Error()) } // TestParseBeneficiaryFIReaderParseError parses a wrong BeneficiaryFI reader parse error @@ -146,30 +142,25 @@ func TestParseBeneficiaryFIReaderParseError(t *testing.T) { var line = "{4100}D123456789 F® Name Address One Address Two Address Three " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - bfi := mockBeneficiaryFI() - fwm.SetBeneficiaryFI(bfi) + err := r.parseBeneficiaryFI() - if err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + _, err = r.Read() - if err != nil { - if !base.Has(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) } // TestBeneficiaryFITagError validates a BeneficiaryFI tag func TestBeneficiaryFITagError(t *testing.T) { bfi := mockBeneficiaryFI() bfi.tag = "{9999}" - if err := bfi.Validate(); err != nil { - if !base.Match(err, ErrValidTagForType) { - t.Errorf("%T: %s", err, err) - } - } + + err := bfi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("tag", ErrValidTagForType, bfi.tag).Error(), err.Error()) } diff --git a/beneficiaryIntermediaryFI.go b/beneficiaryIntermediaryFI.go index 81cb9a80..b2b2101f 100644 --- a/beneficiaryIntermediaryFI.go +++ b/beneficiaryIntermediaryFI.go @@ -107,7 +107,7 @@ func (bifi *BeneficiaryIntermediaryFI) fieldInclusion() error { return fieldError("BeneficiaryIntermediaryFI.FinancialInstitution.Identifier", ErrFieldRequired) } if bifi.FinancialInstitution.IdentificationCode == "" && bifi.FinancialInstitution.Identifier != "" { - return fieldError("fwm.BeneficiaryIntermediaryFI.FinancialInstitution.IdentificationCode", ErrFieldRequired) + return fieldError("BeneficiaryIntermediaryFI.FinancialInstitution.IdentificationCode", ErrFieldRequired) } return nil } diff --git a/beneficiaryIntermediaryFI_test.go b/beneficiaryIntermediaryFI_test.go index ea6e3ae0..87a5b24e 100644 --- a/beneficiaryIntermediaryFI_test.go +++ b/beneficiaryIntermediaryFI_test.go @@ -1,9 +1,10 @@ package wire import ( - "github.com/moov-io/base" "strings" "testing" + + "github.com/stretchr/testify/require" ) // mockBeneficiaryIntermediaryFI creates a BeneficiaryIntermediaryFI @@ -21,108 +22,107 @@ func mockBeneficiaryIntermediaryFI() *BeneficiaryIntermediaryFI { // TestMockBeneficiaryIntermediaryFI validates mockBeneficiaryIntermediaryFI func TestMockBeneficiaryIntermediaryFI(t *testing.T) { bifi := mockBeneficiaryIntermediaryFI() - if err := bifi.Validate(); err != nil { - t.Error("mockBeneficiaryIntermediaryFI does not validate and will break other tests") - } + + require.NoError(t, bifi.Validate(), "mockBeneficiaryIntermediaryFI does not validate and will break other tests") } // TestBeneficiaryIntermediaryFIIdentificationCodeValid validates BeneficiaryIntermediaryFI IdentificationCode func TestBeneficiaryIntermediaryFIIdentificationCodeValid(t *testing.T) { bifi := mockBeneficiaryIntermediaryFI() bifi.FinancialInstitution.IdentificationCode = "Football Card ID" - if err := bifi.Validate(); err != nil { - if !base.Match(err, ErrIdentificationCode) { - t.Errorf("%T: %s", err, err) - } - } + + err := bifi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("IdentificationCode", ErrIdentificationCode, bifi.FinancialInstitution.IdentificationCode).Error(), err.Error()) } // TestBeneficiaryIntermediaryFIIdentificationCodeFI validates BeneficiaryIntermediaryFI IdentificationCode is an FI code func TestBeneficiaryIntermediaryFIIdentificationCodeFI(t *testing.T) { bifi := mockBeneficiaryIntermediaryFI() bifi.FinancialInstitution.IdentificationCode = "1" - if err := bifi.Validate(); err != nil { - if !base.Match(err, ErrIdentificationCode) { - t.Errorf("%T: %s", err, err) - } - } + + err := bifi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("IdentificationCode", ErrIdentificationCode, bifi.FinancialInstitution.IdentificationCode).Error(), err.Error()) } // TestBeneficiaryIntermediaryFIIdentifierAlphaNumeric validates BeneficiaryIntermediaryFI Identifier is alphanumeric func TestBeneficiaryIntermediaryFIIdentifierAlphaNumeric(t *testing.T) { bifi := mockBeneficiaryIntermediaryFI() bifi.FinancialInstitution.Identifier = "®" - if err := bifi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := bifi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("Identifier", ErrNonAlphanumeric, bifi.FinancialInstitution.Identifier).Error(), err.Error()) } // TestBeneficiaryIntermediaryFINameAlphaNumeric validates BeneficiaryIntermediaryFI Name is alphanumeric func TestBeneficiaryIntermediaryFINameAlphaNumeric(t *testing.T) { bifi := mockBeneficiaryIntermediaryFI() bifi.FinancialInstitution.Name = "®" - if err := bifi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := bifi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("Name", ErrNonAlphanumeric, bifi.FinancialInstitution.Name).Error(), err.Error()) } // TestBeneficiaryIntermediaryFIAddressLineOneAlphaNumeric validates BeneficiaryIntermediaryFI AddressLineOne is alphanumeric func TestBeneficiaryIntermediaryFIAddressLineOneAlphaNumeric(t *testing.T) { bifi := mockBeneficiaryIntermediaryFI() bifi.FinancialInstitution.Address.AddressLineOne = "®" - if err := bifi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := bifi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("AddressLineOne", ErrNonAlphanumeric, bifi.FinancialInstitution.Address.AddressLineOne).Error(), err.Error()) } // TestBeneficiaryIntermediaryFIAddressLineTwoAlphaNumeric validates BeneficiaryIntermediaryFI AddressLineTwo is alphanumeric func TestBeneficiaryIntermediaryFIAddressLineTwoAlphaNumeric(t *testing.T) { bifi := mockBeneficiaryIntermediaryFI() bifi.FinancialInstitution.Address.AddressLineTwo = "®" - if err := bifi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := bifi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("AddressLineTwo", ErrNonAlphanumeric, bifi.FinancialInstitution.Address.AddressLineTwo).Error(), err.Error()) } // TestBeneficiaryIntermediaryFIAddressLineThreeAlphaNumeric validates BeneficiaryIntermediaryFI AddressLineThree is alphanumeric func TestBeneficiaryIntermediaryFIAddressLineThreeAlphaNumeric(t *testing.T) { bifi := mockBeneficiaryIntermediaryFI() bifi.FinancialInstitution.Address.AddressLineThree = "®" - if err := bifi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := bifi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("AddressLineThree", ErrNonAlphanumeric, bifi.FinancialInstitution.Address.AddressLineThree).Error(), err.Error()) } // TestBeneficiaryIntermediaryFIIdentificationCodeRequired validates BeneficiaryIntermediaryFI IdentificationCode is required func TestBeneficiaryIntermediaryFIIdentificationCodeRequired(t *testing.T) { bifi := mockBeneficiaryIntermediaryFI() bifi.FinancialInstitution.IdentificationCode = "" - if err := bifi.Validate(); err != nil { - if !base.Match(err, ErrFieldRequired) { - t.Errorf("%T: %s", err, err) - } - } + + err := bifi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("BeneficiaryIntermediaryFI.FinancialInstitution.IdentificationCode", ErrFieldRequired).Error(), err.Error()) } // TestBeneficiaryIntermediaryFIIdentifierRequired validates BeneficiaryIntermediaryFI Identifier is required func TestBeneficiaryIntermediaryFIIdentifierRequired(t *testing.T) { bifi := mockBeneficiaryIntermediaryFI() bifi.FinancialInstitution.Identifier = "" - if err := bifi.Validate(); err != nil { - if !base.Match(err, ErrFieldRequired) { - t.Errorf("%T: %s", err, err) - } - } + + err := bifi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("BeneficiaryIntermediaryFI.FinancialInstitution.Identifier", ErrFieldRequired).Error(), err.Error()) } // TestParseBeneficiaryIntermediaryFIWrongLength parses a wrong BeneficiaryIntermediaryFI record length @@ -130,15 +130,11 @@ func TestParseBeneficiaryIntermediaryFIWrongLength(t *testing.T) { var line = "{4000}D123456789 FI Name Address One Address Two Address Three " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - bifi := mockBeneficiaryIntermediaryFI() - fwm.SetBeneficiaryIntermediaryFI(bifi) + err := r.parseBeneficiaryIntermediaryFI() - if err != nil { - if !base.Match(err, NewTagWrongLengthErr(181, len(r.line))) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), NewTagWrongLengthErr(181, len(r.line)).Error()) } // TestParseBeneficiaryIntermediaryFIReaderParseError parses a wrong BeneficiaryIntermediaryFI reader parse error @@ -149,27 +145,25 @@ func TestParseBeneficiaryIntermediaryFIReaderParseError(t *testing.T) { fwm := new(FEDWireMessage) bifi := mockBeneficiaryIntermediaryFI() fwm.SetBeneficiaryIntermediaryFI(bifi) + err := r.parseBeneficiaryIntermediaryFI() - if err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + _, err = r.Read() - if err != nil { - if !base.Has(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) } // TestBeneficiaryIntermediaryFITagError validates a BeneficiaryFI tag func TestBeneficiaryIntermediaryFITagError(t *testing.T) { bifi := mockBeneficiaryIntermediaryFI() bifi.tag = "{9999}" - if err := bifi.Validate(); err != nil { - if !base.Match(err, ErrValidTagForType) { - t.Errorf("%T: %s", err, err) - } - } + + err := bifi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("tag", ErrValidTagForType, bifi.tag).Error(), err.Error()) } diff --git a/beneficiaryReference_test.go b/beneficiaryReference_test.go index a51a44d2..fad795eb 100644 --- a/beneficiaryReference_test.go +++ b/beneficiaryReference_test.go @@ -1,9 +1,10 @@ package wire import ( - "github.com/moov-io/base" "strings" "testing" + + "github.com/stretchr/testify/require" ) // mockBeneficiaryReference creates a BeneficiaryReference @@ -16,20 +17,19 @@ func mockBeneficiaryReference() *BeneficiaryReference { // TestMockBeneficiary validates mockBeneficiaryReference func TestMockBeneficiaryReference(t *testing.T) { br := mockBeneficiaryReference() - if err := br.Validate(); err != nil { - t.Error("mockBeneficiaryReference does not validate and will break other tests") - } + + require.NoError(t, br.Validate(), "mockBeneficiaryReference does not validate and will break other tests") } // TestBeneficiaryReferenceAlphaNumeric validates BeneficiaryReference is alphanumeric func TestBeneficiaryReferenceAlphaNumeric(t *testing.T) { br := mockBeneficiaryReference() br.BeneficiaryReference = "®" - if err := br.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := br.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("BeneficiaryReference", ErrNonAlphanumeric, br.BeneficiaryReference).Error(), err.Error()) } // TestParseBeneficiaryReferenceWrongLength parses a wrong BeneficiaryReference record length @@ -37,15 +37,11 @@ func TestParseBeneficiaryReferenceWrongLength(t *testing.T) { var line = "{4320}Reference " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - br := mockBeneficiaryReference() - fwm.SetBeneficiaryReference(br) + err := r.parseBeneficiaryReference() - if err != nil { - if !base.Match(err, NewTagWrongLengthErr(22, len(r.line))) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), NewTagWrongLengthErr(22, len(r.line)).Error()) } // TestParseBeneficiaryReferenceReaderParseError parses a wrong BeneficiaryReference reader parse error @@ -53,30 +49,25 @@ func TestParseBeneficiaryReferenceReaderParseError(t *testing.T) { var line = "{4320}Reference® " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - br := mockBeneficiaryReference() - fwm.SetBeneficiaryReference(br) + err := r.parseBeneficiaryReference() - if err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err.Error()) + require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + _, err = r.Read() - if err != nil { - if !base.Has(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err.Error()) + require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) } // TestBeneficiaryReferenceTagError validates a BeneficiaryReference tag func TestBeneficiaryReferenceTagError(t *testing.T) { br := mockBeneficiaryReference() br.tag = "{9999}" - if err := br.Validate(); err != nil { - if !base.Match(err, ErrValidTagForType) { - t.Errorf("%T: %s", err, err) - } - } + + err := br.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("tag", ErrValidTagForType, br.tag).Error(), err.Error()) } diff --git a/businessFunctionCode_test.go b/businessFunctionCode_test.go index 63c4a0eb..48a46f74 100644 --- a/businessFunctionCode_test.go +++ b/businessFunctionCode_test.go @@ -1,9 +1,10 @@ package wire import ( - "github.com/moov-io/base" "strings" "testing" + + "github.com/stretchr/testify/require" ) // mockBusinessFunctionCode creates a BusinessFunctionCode @@ -17,31 +18,30 @@ func mockBusinessFunctionCode() *BusinessFunctionCode { // TestMockBusinessFunctionCode validates mockBusinessFunctionCode func TestMockBusinessFunctionCode(t *testing.T) { bfc := mockBusinessFunctionCode() - if err := bfc.Validate(); err != nil { - t.Error("mockBusinessFunctionCode does not validate and will break other tests") - } + + require.NoError(t, bfc.Validate(), "mockBusinessFunctionCode does not validate and will break other tests") } // TestBusinessFunctionCodeValid validates BusinessFunctionCode func TestBusinessFunctionCodeValid(t *testing.T) { bfc := mockBusinessFunctionCode() bfc.BusinessFunctionCode = "ZZZ" - if err := bfc.Validate(); err != nil { - if !base.Match(err, ErrBusinessFunctionCode) { - t.Errorf("%T: %s", err, err) - } - } + + err := bfc.Validate() + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrBusinessFunctionCode.Error()) } // TestBusinessFunctionCodeRequired validates BusinessFunctionCode is required func TestBusinessFunctionCodeRequired(t *testing.T) { bfc := mockBusinessFunctionCode() bfc.BusinessFunctionCode = "" - if err := bfc.Validate(); err != nil { - if !base.Match(err, ErrFieldRequired) { - t.Errorf("%T: %s", err, err) - } - } + + err := bfc.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("BusinessFunctionCode", ErrFieldRequired, bfc.BusinessFunctionCode).Error(), err.Error()) } // TestParseBusinessFunctionCodeWrongLength parses a wrong BusinessFunctionCode record length @@ -49,14 +49,11 @@ func TestParseBusinessFunctionCodeWrongLength(t *testing.T) { var line = "{3600}CT" r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - bfc := mockBusinessFunctionCode() - fwm.SetBusinessFunctionCode(bfc) - if err := r.parseBusinessFunctionCode(); err != nil { - if !base.Match(err, NewTagWrongLengthErr(12, len(r.line))) { - t.Errorf("%T: %s", err, err) - } - } + + err := r.parseBusinessFunctionCode() + + require.NotNil(t, err) + require.Contains(t, err.Error(), NewTagWrongLengthErr(12, len(r.line)).Error()) } // TestParseBusinessFunctionCodeReaderParseError parses a wrong BusinessFunctionCode reader parse error @@ -64,29 +61,25 @@ func TestParseBusinessFunctionCodeReaderParseError(t *testing.T) { var line = "{3600}CTAXXY" r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - bfc := mockBusinessFunctionCode() - fwm.SetBusinessFunctionCode(bfc) - if err := r.parseBusinessFunctionCode(); err != nil { - if !base.Match(err, ErrBusinessFunctionCode) { - t.Errorf("%T: %s", err, err) - } - } - _, err := r.Read() - if err != nil { - if !base.Has(err, ErrBusinessFunctionCode) { - t.Errorf("%T: %s", err, err) - } - } + + err := r.parseBusinessFunctionCode() + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrBusinessFunctionCode.Error()) + + _, err = r.Read() + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrBusinessFunctionCode.Error()) } // TestBusinessFunctionCodeTagError validates a BusinessFunctionCode tag func TestBusinessFunctionCodeTagError(t *testing.T) { bfc := mockBusinessFunctionCode() bfc.tag = "{9999}" - if err := bfc.Validate(); err != nil { - if !base.Match(err, ErrValidTagForType) { - t.Errorf("%T: %s", err, err) - } - } + + err := bfc.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("tag", ErrValidTagForType, bfc.tag).Error(), err.Error()) } diff --git a/charges_test.go b/charges_test.go index 5fb11e30..077e0aaa 100644 --- a/charges_test.go +++ b/charges_test.go @@ -1,8 +1,9 @@ package wire import ( - "github.com/moov-io/base" "testing" + + "github.com/stretchr/testify/require" ) // mockCharges creates a Charges @@ -19,30 +20,25 @@ func mockCharges() *Charges { // TestMockCharges validates mockCharges func TestMockCharges(t *testing.T) { c := mockCharges() - if err := c.Validate(); err != nil { - t.Error("mockCharges does not validate and will break other tests") - } + + require.NoError(t, c.Validate(), "mockCharges does not validate and will break other tests") } // TestChargeDetailsValid validates ChargeDetails is valid func TestPaymentNotificationIndicatorValid(t *testing.T) { c := mockCharges() c.ChargeDetails = "F" - if err := c.Validate(); err != nil { - if !base.Match(err, ErrChargeDetails) { - t.Errorf("%T: %s", err, err) - } - } + + err := c.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("ChargeDetails", ErrChargeDetails, c.ChargeDetails).Error(), err.Error()) } func TestChargesCrash(t *testing.T) { c := &Charges{} c.Parse("{3700}") // invalid, caused a fuzz crash - if c.tag != "" { - t.Errorf("c.tag=%s", c.tag) - } - if c.ChargeDetails != "" { - t.Errorf("unexpected c.ChargeDetails=%s", c.ChargeDetails) - } + require.Empty(t, c.tag) + require.Empty(t, c.ChargeDetails) } diff --git a/currencyInstructedAmount_test.go b/currencyInstructedAmount_test.go index 0af7a9c2..0acde8e4 100644 --- a/currencyInstructedAmount_test.go +++ b/currencyInstructedAmount_test.go @@ -1,9 +1,10 @@ package wire import ( - "github.com/moov-io/base" "strings" "testing" + + "github.com/stretchr/testify/require" ) // CurrencyInstructedAmount creates a CurrencyInstructedAmount @@ -17,31 +18,30 @@ func mockCurrencyInstructedAmount() *CurrencyInstructedAmount { // TestMockCurrencyInstructedAmount validates mockCurrencyInstructedAmount func TestMockCurrencyInstructedAmount(t *testing.T) { cia := mockCurrencyInstructedAmount() - if err := cia.Validate(); err != nil { - t.Error("mockCurrencyInstructedAmount does not validate and will break other tests") - } + + require.NoError(t, cia.Validate(), "mockCurrencyInstructedAmount does not validate and will break other tests") } // TestCurrencyInstructedAmountSwiftFieldTagAlphaNumeric validates CurrencyInstructedAmount SwiftFieldTag is alphanumeric func TestCurrencyInstructedAmountSwiftFieldTagAlphaNumeric(t *testing.T) { cia := mockCurrencyInstructedAmount() cia.SwiftFieldTag = "®" - if err := cia.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := cia.Validate() + + require.NotEmpty(t, err) + require.Equal(t, fieldError("SwiftFieldTag", ErrNonAlphanumeric, cia.SwiftFieldTag).Error(), err.Error()) } -// TestCurrencyInstructedAmountValid validates CurrencyInstructedAmount InstructedAmount is valid +// TestCurrencyInstructedAmountValid validates CurrencyInstructedAmount Amount is valid func TestCurrencyInstructedAmountValid(t *testing.T) { cia := mockCurrencyInstructedAmount() cia.Amount = "1-0" - if err := cia.Validate(); err != nil { - if !base.Match(err, ErrNonAmount) { - t.Errorf("%T: %s", err, err) - } - } + + err := cia.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("Amount", ErrNonAmount, cia.Amount).Error(), err.Error()) } // TestParseCurrencyInstructedAmountWrongLength parses a wrong CurrencyInstructedAmount record length @@ -49,15 +49,11 @@ func TestParseCurrencyInstructedAmountWrongLength(t *testing.T) { var line = "{7033}Swift000000000001500,4" r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - cia := mockCurrencyInstructedAmount() - fwm.SetCurrencyInstructedAmount(cia) + err := r.parseCurrencyInstructedAmount() - if err != nil { - if !base.Match(err, NewTagWrongLengthErr(41, len(r.line))) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), NewTagWrongLengthErr(29, len(r.line)).Error()) } // TestParseCurrencyInstructedAmountReaderParseError parses a wrong CurrencyInstructedAmount reader parse error @@ -65,30 +61,25 @@ func TestParseCurrencyInstructedAmountReaderParseError(t *testing.T) { var line = "{7033}Swift00000000Z001500,49" r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - cia := mockCurrencyInstructedAmount() - fwm.SetCurrencyInstructedAmount(cia) + err := r.parseCurrencyInstructedAmount() - if err != nil { - if !base.Match(err, ErrNonAmount) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrNonAmount.Error()) + _, err = r.Read() - if err != nil { - if !base.Has(err, ErrNonAmount) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrNonAmount.Error()) } // TestCurrencyInstructedAmountTagError validates a CurrencyInstructedAmount tag func TestCurrencyInstructedAmountTagError(t *testing.T) { cia := mockCurrencyInstructedAmount() cia.tag = "{9999}" - if err := cia.Validate(); err != nil { - if !base.Match(err, ErrValidTagForType) { - t.Errorf("%T: %s", err, err) - } - } + + err := cia.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("tag", ErrValidTagForType, cia.tag).Error(), err.Error()) } diff --git a/dateRemittanceDocument_test.go b/dateRemittanceDocument_test.go index 1802605c..be1ae10f 100644 --- a/dateRemittanceDocument_test.go +++ b/dateRemittanceDocument_test.go @@ -1,10 +1,11 @@ package wire import ( - "github.com/moov-io/base" "strings" "testing" "time" + + "github.com/stretchr/testify/require" ) // DateRemittanceDocument creates a DateRemittanceDocument @@ -17,20 +18,19 @@ func mockDateRemittanceDocument() *DateRemittanceDocument { // TestMockDateRemittanceDocument validates mockDateRemittanceDocument func TestMockDateRemittanceDocument(t *testing.T) { drd := mockDateRemittanceDocument() - if err := drd.Validate(); err != nil { - t.Error("mockDateRemittanceDocument does not validate and will break other tests") - } + + require.NoError(t, drd.Validate(), "mockDateRemittanceDocument does not validate and will break other tests") } // TestDateRemittanceDocumentRequired validates DateRemittanceDocument DateRemittanceDocument is required func TestDateRemittanceDocumentDateRemittanceDocumentRequired(t *testing.T) { drd := mockDateRemittanceDocument() drd.DateRemittanceDocument = "" - if err := drd.Validate(); err != nil { - if !base.Match(err, ErrFieldRequired) { - t.Errorf("%T: %s", err, err) - } - } + + err := drd.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("DateRemittanceDocument", ErrFieldRequired).Error(), err.Error()) } // TestParseDateRemittanceDocumentWrongLength parses a wrong DateRemittanceDocument record length @@ -38,15 +38,11 @@ func TestParseDateRemittanceDocumentWrongLength(t *testing.T) { var line = "{8650}20190509 " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - rd := mockDateRemittanceDocument() - fwm.SetDateRemittanceDocument(rd) + err := r.parseDateRemittanceDocument() - if err != nil { - if !base.Match(err, NewTagWrongLengthErr(14, len(r.line))) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), NewTagWrongLengthErr(14, len(r.line)).Error()) } // TestParseDateRemittanceDocumentReaderParseError parses a wrong DateRemittanceDocument reader parse error @@ -54,30 +50,25 @@ func TestParseDateRemittanceDocumentReaderParseError(t *testing.T) { var line = "{8650}14190509" r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - rd := mockDateRemittanceDocument() - fwm.SetDateRemittanceDocument(rd) + err := r.parseDateRemittanceDocument() - if err != nil { - if !base.Match(err, ErrValidDate) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrValidDate.Error()) + _, err = r.Read() - if err != nil { - if !base.Has(err, ErrValidDate) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrValidDate.Error()) } // TestDateRemittanceDocumentTagError validates a DateRemittanceDocument tag func TestDateRemittanceDocumentTagError(t *testing.T) { drd := mockDateRemittanceDocument() drd.tag = "{9999}" - if err := drd.Validate(); err != nil { - if !base.Match(err, ErrValidTagForType) { - t.Errorf("%T: %s", err, err) - } - } + + err := drd.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("tag", ErrValidTagForType, drd.tag).Error(), err.Error()) } diff --git a/errorWire_test.go b/errorWire_test.go index 9a8d31d0..633625c9 100644 --- a/errorWire_test.go +++ b/errorWire_test.go @@ -1,9 +1,12 @@ package wire import ( - "log" "strings" "testing" + + "gotest.tools/assert" + + "github.com/stretchr/testify/require" ) // mockErrorWire creates a ErrorWire @@ -18,9 +21,8 @@ func mockErrorWire() *ErrorWire { // TestMockErrorWire validates mockErrorWire func TestMockErrorWire(t *testing.T) { ew := mockErrorWire() - if err := ew.Validate(); err != nil { - t.Error("mockErrorWire does not validate and will break other tests") - } + + require.NoError(t, ew.Validate(), "mockErrorWire does not validate and will break other tests") } // TestParseErrorWire parses a known ErrorWire record string @@ -28,25 +30,13 @@ func TestParseErrorWire(t *testing.T) { var line = "{1130}1XYZData Error " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - ew := mockErrorWire() - fwm.SetErrorWire(ew) - err := r.parseErrorWire() - if err != nil { - t.Errorf("%T: %s", err, err) - log.Fatal(err) - } + + require.NoError(t, r.parseErrorWire()) record := r.currentFEDWireMessage.ErrorWire - if record.ErrorCategory != "1" { - t.Errorf("ErrorCategory Expected '1' got: %v", record.ErrorCategory) - } - if record.ErrorCode != "XYZ" { - t.Errorf("ErrorCode Expected 'XYZ' got: %v", record.ErrorCode) - } - if record.ErrorDescription != "Data Error" { - t.Errorf("ErrorDescription Expected 'Data Error' got: %v", record.ErrorDescription) - } + 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 @@ -54,16 +44,8 @@ func TestWriteErrorWire(t *testing.T) { var line = "{1130}1XYZData Error " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - ew := mockErrorWire() - fwm.SetErrorWire(ew) - err := r.parseErrorWire() - if err != nil { - t.Errorf("%T: %s", err, err) - log.Fatal(err) - } + require.NoError(t, r.parseErrorWire()) record := r.currentFEDWireMessage.ErrorWire - if record.String() != line { - t.Errorf("\nStrings do not match %s\n %s", line, record.String()) - } + + assert.Equal(t, line, record.String()) } diff --git a/exchangeRate_test.go b/exchangeRate_test.go index cabc4e18..1064b250 100644 --- a/exchangeRate_test.go +++ b/exchangeRate_test.go @@ -1,9 +1,10 @@ package wire import ( - "github.com/moov-io/base" "strings" "testing" + + "github.com/stretchr/testify/require" ) // mockExchangeRate creates a ExchangeRate @@ -16,20 +17,19 @@ func mockExchangeRate() *ExchangeRate { // TestMockExchangeRate validates mockExchangeRate func TestMockExchangeRate(t *testing.T) { eRate := mockExchangeRate() - if err := eRate.Validate(); err != nil { - t.Error("mockExchangeRate does not validate and will break other tests") - } + + require.NoError(t, eRate.Validate(), "mockExchangeRate does not validate and will break other tests") } // TestExchangeRate validates ExchangeRate func TestExchangeRateNumeric(t *testing.T) { eRate := mockExchangeRate() eRate.ExchangeRate = "1,--0.00" - if err := eRate.Validate(); err != nil { - if !base.Match(err, ErrNonAmount) { - t.Errorf("%T: %s", err, err) - } - } + + err := eRate.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("ExchangeRate", ErrNonAmount, eRate.ExchangeRate).Error(), err.Error()) } // TestParseExchangeRateWrongLength parses a wrong ExchangeRate record length @@ -37,15 +37,11 @@ func TestParseExchangeRateWrongLength(t *testing.T) { var line = "{3720}1,2345" r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - eRate := mockExchangeRate() - fwm.SetExchangeRate(eRate) + err := r.parseExchangeRate() - if err != nil { - if !base.Match(err, NewTagWrongLengthErr(18, len(r.line))) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), NewTagWrongLengthErr(18, len(r.line)).Error()) } // TestParseExchangeRateReaderParseError parses a wrong ExchangeRate reader parse error @@ -53,30 +49,25 @@ func TestParseExchangeRateReaderParseError(t *testing.T) { var line = "{3720}1,2345Z " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - eRate := mockExchangeRate() - fwm.SetExchangeRate(eRate) + err := r.parseExchangeRate() - if err != nil { - if !base.Match(err, ErrNonAmount) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrNonAmount.Error()) + _, err = r.Read() - if err != nil { - if !base.Has(err, ErrNonAmount) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrNonAmount.Error()) } // TestExchangeRateTagError validates a ExchangeRate tag func TestExchangeRateTagError(t *testing.T) { eRate := mockCurrencyInstructedAmount() eRate.tag = "{9999}" - if err := eRate.Validate(); err != nil { - if !base.Match(err, ErrValidTagForType) { - t.Errorf("%T: %s", err, err) - } - } + + err := eRate.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("tag", ErrValidTagForType, eRate.tag).Error(), err.Error()) } diff --git a/fIBeneficiaryFIAdvice_test.go b/fIBeneficiaryFIAdvice_test.go index 3c0b1398..465bd8f4 100644 --- a/fIBeneficiaryFIAdvice_test.go +++ b/fIBeneficiaryFIAdvice_test.go @@ -1,9 +1,10 @@ package wire import ( - "github.com/moov-io/base" "strings" "testing" + + "github.com/stretchr/testify/require" ) // mockFIBeneficiaryFIAdvice creates a FIBeneficiaryFIAdvice @@ -22,86 +23,85 @@ func mockFIBeneficiaryFIAdvice() *FIBeneficiaryFIAdvice { // TestMockFIBeneficiaryFIAdvice validates mockFIBeneficiaryFIAdvice func TestMockFIBeneficiaryFIAdvice(t *testing.T) { fibfia := mockFIBeneficiaryFIAdvice() - if err := fibfia.Validate(); err != nil { - t.Error("mockFIBeneficiaryFIAdvice does not validate and will break other tests") - } + + require.NoError(t, fibfia.Validate(), "mockFIBeneficiaryFIAdvice does not validate and will break other tests") } // TestFIBeneficiaryFIAdviceAdviceCodeValid validates FIBeneficiaryFIAdvice AdviceCode is alphanumeric func TestFIBeneficiaryFIAdviceAdviceCodeValid(t *testing.T) { fibfia := mockFIBeneficiaryFIAdvice() fibfia.Advice.AdviceCode = "Z" - if err := fibfia.Validate(); err != nil { - if !base.Match(err, ErrAdviceCode) { - t.Errorf("%T: %s", err, err) - } - } + + err := fibfia.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("AdviceCode", ErrAdviceCode, fibfia.Advice.AdviceCode).Error(), err.Error()) } // TestFIBeneficiaryFIAdviceLineOneAlphaNumeric validates FIBeneficiaryFIAdvice LineOne is alphanumeric func TestFIBeneficiaryFIAdviceLineOneAlphaNumeric(t *testing.T) { fibfia := mockFIBeneficiaryFIAdvice() fibfia.Advice.LineOne = "®" - if err := fibfia.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fibfia.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineOne", ErrNonAlphanumeric, fibfia.Advice.LineOne).Error(), err.Error()) } // TestFIBeneficiaryFIAdviceLineTwoAlphaNumeric validates FIBeneficiaryFIAdvice LineTwo is alphanumeric func TestFIBeneficiaryFIAdviceLineTwoAlphaNumeric(t *testing.T) { fibfia := mockFIBeneficiaryFIAdvice() fibfia.Advice.LineTwo = "®" - if err := fibfia.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fibfia.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineTwo", ErrNonAlphanumeric, fibfia.Advice.LineTwo).Error(), err.Error()) } // TestFIBeneficiaryFIAdviceLineThreeAlphaNumeric validates FIBeneficiaryFIAdvice LineThree is alphanumeric func TestFIBeneficiaryFIAdviceLineThreeAlphaNumeric(t *testing.T) { fibfia := mockFIBeneficiaryFIAdvice() fibfia.Advice.LineThree = "®" - if err := fibfia.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fibfia.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineThree", ErrNonAlphanumeric, fibfia.Advice.LineThree).Error(), err.Error()) } // TestFIBeneficiaryFIAdviceLineFourAlphaNumeric validates FIBeneficiaryFIAdvice LineFour is alphanumeric func TestFIBeneficiaryFIAdviceLineFourAlphaNumeric(t *testing.T) { fibfia := mockFIBeneficiaryFIAdvice() fibfia.Advice.LineFour = "®" - if err := fibfia.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fibfia.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineFour", ErrNonAlphanumeric, fibfia.Advice.LineFour).Error(), err.Error()) } // TestFIBeneficiaryFIAdviceLineFiveAlphaNumeric validates FIBeneficiaryFIAdvice LineFive is alphanumeric func TestFIBeneficiaryFIAdviceLineFiveAlphaNumeric(t *testing.T) { fibfia := mockFIBeneficiaryFIAdvice() fibfia.Advice.LineFive = "®" - if err := fibfia.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fibfia.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineFive", ErrNonAlphanumeric, fibfia.Advice.LineFive).Error(), err.Error()) } // TestFIBeneficiaryFIAdviceLineSixAlphaNumeric validates FIBeneficiaryFIAdvice LineSix is alphanumeric func TestFIBeneficiaryFIAdviceLineSixAlphaNumeric(t *testing.T) { fibfia := mockFIBeneficiaryFIAdvice() fibfia.Advice.LineSix = "®" - if err := fibfia.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fibfia.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineSix", ErrNonAlphanumeric, fibfia.Advice.LineSix).Error(), err.Error()) } // TestParseFIBeneficiaryFIAdviceWrongLength parses a wrong FIBeneficiaryFIAdvice record length @@ -109,15 +109,11 @@ func TestParseFIBeneficiaryFIAdviceWrongLength(t *testing.T) { var line = "{6310}TLXLine One Line Two Line Three Line Four Line Five Line Six " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - fibfia := mockFIBeneficiaryFIAdvice() - fwm.SetFIBeneficiaryFIAdvice(fibfia) + err := r.parseFIBeneficiaryFIAdvice() - if err != nil { - if !base.Match(err, NewTagWrongLengthErr(200, len(r.line))) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), NewTagWrongLengthErr(200, len(r.line)).Error(), err.Error()) } // TestParseFIBeneficiaryFIAdviceReaderParseError parses a wrong FIBeneficiaryFIAdvice reader parse error @@ -125,30 +121,25 @@ func TestParseFIBeneficiaryFIAdviceReaderParseError(t *testing.T) { var line = "{6310}TLXLine ®ne Line Two Line Three Line Four Line Five Line Six " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - fibfia := mockFIBeneficiaryFIAdvice() - fwm.SetFIBeneficiaryFIAdvice(fibfia) + err := r.parseFIBeneficiaryFIAdvice() - if err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + _, err = r.Read() - if err != nil { - if !base.Has(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) } // TestFIBeneficiaryFIAdviceTagError validates a FIBeneficiaryFIAdvice tag func TestFIBeneficiaryFIAdviceTagError(t *testing.T) { fibfia := mockFIBeneficiaryFIAdvice() fibfia.tag = "{9999}" - if err := fibfia.Validate(); err != nil { - if !base.Match(err, ErrValidTagForType) { - t.Errorf("%T: %s", err, err) - } - } + + err := fibfia.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("tag", ErrValidTagForType, fibfia.tag).Error(), err.Error()) } diff --git a/fiAdditionalFIToFI_test.go b/fiAdditionalFIToFI_test.go index 2f7e431a..61cddb08 100644 --- a/fiAdditionalFIToFI_test.go +++ b/fiAdditionalFIToFI_test.go @@ -1,9 +1,11 @@ package wire import ( - "github.com/moov-io/base" "strings" "testing" + + "github.com/moov-io/base" + "github.com/stretchr/testify/require" ) // mockFIAdditionalFIToFI creates a FIAdditionalFIToFI @@ -21,75 +23,74 @@ func mockFIAdditionalFIToFI() *FIAdditionalFIToFI { // TestMockFIAdditionalFIToFI validates mockFIAdditionalFIToFI func TestMockFIAdditionalFIToFI(t *testing.T) { fifi := mockFIAdditionalFIToFI() - if err := fifi.Validate(); err != nil { - t.Error("mockFIAdditionalFIToFI does not validate and will break other tests") - } + + 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 = "®" - if err := fifi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fifi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineOne", ErrNonAlphanumeric, fifi.AdditionalFIToFI.LineOne).Error(), err.Error()) } // TestFIAdditionalFIToFILineTwoAlphaNumeric validates FIAdditionalFIToFI LineTwo is alphanumeric func TestFIAdditionalFIToFILineTwoAlphaNumeric(t *testing.T) { fifi := mockFIAdditionalFIToFI() fifi.AdditionalFIToFI.LineTwo = "®" - if err := fifi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fifi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineTwo", ErrNonAlphanumeric, fifi.AdditionalFIToFI.LineTwo).Error(), err.Error()) } // TestFIAdditionalFIToFILineThreeAlphaNumeric validates FIAdditionalFIToFI LineThree is alphanumeric func TestFIAdditionalFIToFILineThreeAlphaNumeric(t *testing.T) { fifi := mockFIAdditionalFIToFI() fifi.AdditionalFIToFI.LineThree = "®" - if err := fifi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fifi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineThree", ErrNonAlphanumeric, fifi.AdditionalFIToFI.LineThree).Error(), err.Error()) } // TestFIAdditionalFIToFILineFourAlphaNumeric validates FIAdditionalFIToFI LineFour is alphanumeric func TestFIAdditionalFIToFILineFourAlphaNumeric(t *testing.T) { fifi := mockFIAdditionalFIToFI() fifi.AdditionalFIToFI.LineFour = "®" - if err := fifi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fifi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineFour", ErrNonAlphanumeric, fifi.AdditionalFIToFI.LineFour).Error(), err.Error()) } // TestFIAdditionalFIToFILineFiveAlphaNumeric validates FIAdditionalFIToFI LineFive is alphanumeric func TestFIAdditionalFIToFILineFiveAlphaNumeric(t *testing.T) { fifi := mockFIAdditionalFIToFI() fifi.AdditionalFIToFI.LineFive = "®" - if err := fifi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fifi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineFive", ErrNonAlphanumeric, fifi.AdditionalFIToFI.LineFive).Error(), err.Error()) } // TestFIAdditionalFIToFILineSixAlphaNumeric validates FIAdditionalFIToFI LineSix is alphanumeric func TestFIAdditionalFIToFILineSixAlphaNumeric(t *testing.T) { fifi := mockFIAdditionalFIToFI() fifi.AdditionalFIToFI.LineSix = "®" - if err := fifi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fifi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineSix", ErrNonAlphanumeric, fifi.AdditionalFIToFI.LineSix).Error(), err.Error()) } // TestParseFIAdditionalFIToFIWrongLength parses a wrong FIAdditionalFIToFI record length @@ -97,15 +98,11 @@ 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) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), NewTagWrongLengthErr(216, len(r.line)).Error()) } // TestParseFIAdditionalFIToFIReaderParseError parses a wrong FIAdditionalFIToFI reader parse error @@ -113,20 +110,22 @@ 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) - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + 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) - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + + if !base.Has(err, ErrNonAlphanumeric) { + t.Errorf("%T: %s", err, err) } } @@ -134,9 +133,9 @@ func TestParseFIAdditionalFIToFIReaderParseError(t *testing.T) { func TestFIAdditionalFIToFITagError(t *testing.T) { fifi := mockFIAdditionalFIToFI() fifi.tag = "{9999}" - if err := fifi.Validate(); err != nil { - if !base.Match(err, ErrValidTagForType) { - t.Errorf("%T: %s", err, err) - } - } + + err := fifi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("tag", ErrValidTagForType, fifi.tag).Error(), err.Error()) } diff --git a/fiBeneficiaryAdvice_test.go b/fiBeneficiaryAdvice_test.go index a709f668..b90551ee 100644 --- a/fiBeneficiaryAdvice_test.go +++ b/fiBeneficiaryAdvice_test.go @@ -1,9 +1,10 @@ package wire import ( - "github.com/moov-io/base" "strings" "testing" + + "github.com/stretchr/testify/require" ) // mockFIBeneficiaryAdvice creates a FIBeneficiaryAdvice @@ -22,86 +23,85 @@ func mockFIBeneficiaryAdvice() *FIBeneficiaryAdvice { // TestMockFIBeneficiaryAdvice validates mockFIBeneficiaryAdvice func TestMockFIBeneficiaryAdvice(t *testing.T) { fiba := mockFIBeneficiaryAdvice() - if err := fiba.Validate(); err != nil { - t.Error("mockFIBeneficiary does not validate and will break other tests") - } + + require.NoError(t, fiba.Validate(), "mockFIBeneficiaryAdvice does not validate and will break other tests") } // TestFIBeneficiaryAdviceCodeValid validates FIBeneficiaryAdvice AdviceCode is alphanumeric func TestFIBeneficiaryAdviceCodeValid(t *testing.T) { fiba := mockFIBeneficiaryAdvice() fiba.Advice.AdviceCode = "Z" - if err := fiba.Validate(); err != nil { - if !base.Match(err, ErrAdviceCode) { - t.Errorf("%T: %s", err, err) - } - } + + err := fiba.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("AdviceCode", ErrAdviceCode, fiba.Advice.AdviceCode).Error(), err.Error()) } // TestFIBeneficiaryAdviceLineOneAlphaNumeric validates FIBeneficiaryAdvice LineOne is alphanumeric func TestFIBeneficiaryAdviceLineOneAlphaNumeric(t *testing.T) { fiba := mockFIBeneficiaryAdvice() fiba.Advice.LineOne = "®" - if err := fiba.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fiba.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineOne", ErrNonAlphanumeric, fiba.Advice.LineOne).Error(), err.Error()) } // TestFIBeneficiaryAdviceLineTwoAlphaNumeric validates FIBeneficiaryAdvice LineTwo is alphanumeric func TestFIBeneficiaryAdviceLineTwoAlphaNumeric(t *testing.T) { fiba := mockFIBeneficiaryAdvice() fiba.Advice.LineTwo = "®" - if err := fiba.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fiba.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineTwo", ErrNonAlphanumeric, fiba.Advice.LineTwo).Error(), err.Error()) } // TestFIBeneficiaryAdviceLineThreeAlphaNumeric validates FIBeneficiaryAdvice LineThree is alphanumeric func TestFIBeneficiaryAdviceLineThreeAlphaNumeric(t *testing.T) { fiba := mockFIBeneficiaryAdvice() fiba.Advice.LineThree = "®" - if err := fiba.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fiba.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineThree", ErrNonAlphanumeric, fiba.Advice.LineThree).Error(), err.Error()) } // TestFIBeneficiaryAdviceLineFourAlphaNumeric validates FIBeneficiaryAdvice LineFour is alphanumeric func TestFIBeneficiaryAdviceLineFourAlphaNumeric(t *testing.T) { fiba := mockFIBeneficiaryAdvice() fiba.Advice.LineFour = "®" - if err := fiba.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fiba.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineFour", ErrNonAlphanumeric, fiba.Advice.LineFour).Error(), err.Error()) } // TestFIBeneficiaryAdviceLineFiveAlphaNumeric validates FIBeneficiaryAdvice LineFive is alphanumeric func TestFIBeneficiaryAdviceLineFiveAlphaNumeric(t *testing.T) { fiba := mockFIBeneficiaryAdvice() fiba.Advice.LineFive = "®" - if err := fiba.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fiba.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineFive", ErrNonAlphanumeric, fiba.Advice.LineFive).Error(), err.Error()) } // TestFIBeneficiaryAdviceLineSixAlphaNumeric validates FIBeneficiaryAdvice LineSix is alphanumeric func TestFIBeneficiaryAdviceLineSixAlphaNumeric(t *testing.T) { fiba := mockFIBeneficiaryAdvice() fiba.Advice.LineSix = "®" - if err := fiba.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fiba.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineSix", ErrNonAlphanumeric, fiba.Advice.LineSix).Error(), err.Error()) } // TestParseFIBeneficiaryAdviceWrongLength parses a wrong FIBeneficiaryAdvice record length @@ -109,15 +109,11 @@ func TestParseFIBeneficiaryAdviceWrongLength(t *testing.T) { var line = "{6410}LTRLine One Line Two Line Three Line Four Line Five Line Six " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - fiba := mockFIBeneficiaryAdvice() - fwm.SetFIBeneficiaryAdvice(fiba) + err := r.parseFIBeneficiaryAdvice() - if err != nil { - if !base.Match(err, NewTagWrongLengthErr(200, len(r.line))) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), NewTagWrongLengthErr(200, len(r.line)).Error(), err.Error()) } // TestParseFIBeneficiaryAdviceReaderParseError parses a wrong FIBeneficiaryAdvice reader parse error @@ -125,30 +121,24 @@ func TestParseFIBeneficiaryAdviceReaderParseError(t *testing.T) { var line = "{6410}LTRLine ®ne Line Two Line Three Line Four Line Five Line Six " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - fiba := mockFIBeneficiaryAdvice() - fwm.SetFIBeneficiaryAdvice(fiba) + err := r.parseFIBeneficiaryAdvice() - if err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + _, err = r.Read() - if err != nil { - if !base.Has(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) } // TestFIBeneficiaryAdviceTagError validates a FIBeneficiaryAdvice tag func TestFIBeneficiaryAdviceTagError(t *testing.T) { fiba := mockFIBeneficiaryAdvice() fiba.tag = "{9999}" - if err := fiba.Validate(); err != nil { - if !base.Match(err, ErrValidTagForType) { - t.Errorf("%T: %s", err, err) - } - } + err := fiba.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("tag", ErrValidTagForType, fiba.tag).Error(), err.Error()) } diff --git a/fiBeneficiaryFI_test.go b/fiBeneficiaryFI_test.go index 75a8ec0a..7ead6ca6 100644 --- a/fiBeneficiaryFI_test.go +++ b/fiBeneficiaryFI_test.go @@ -1,9 +1,10 @@ package wire import ( - "github.com/moov-io/base" "strings" "testing" + + "github.com/stretchr/testify/require" ) // mockFIBeneficiaryFI creates a FIBeneficiaryFI @@ -21,75 +22,74 @@ func mockFIBeneficiaryFI() *FIBeneficiaryFI { // TestMockFIBeneficiaryFI validates mockFIBeneficiaryFI func TestMockFIBeneficiaryFI(t *testing.T) { fibfi := mockFIBeneficiaryFI() - if err := fibfi.Validate(); err != nil { - t.Error("mockFIBeneficiaryFI does not validate and will break other tests") - } + + require.NoError(t, fibfi.Validate(), "mockFIBeneficiaryFI does not validate and will break other tests") } // TestFIBeneficiaryFILineOneAlphaNumeric validates FIBeneficiaryFI LineOne is alphanumeric func TestFIBeneficiaryFILineOneAlphaNumeric(t *testing.T) { fibfi := mockFIBeneficiaryFI() fibfi.FIToFI.LineOne = "®" - if err := fibfi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fibfi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineOne", ErrNonAlphanumeric, fibfi.FIToFI.LineOne).Error(), err.Error()) } // TestFIBeneficiaryFILineTwoAlphaNumeric validates FIBeneficiaryFI LineTwo is alphanumeric func TestFIBeneficiaryFILineTwoAlphaNumeric(t *testing.T) { fibfi := mockFIBeneficiaryFI() fibfi.FIToFI.LineTwo = "®" - if err := fibfi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fibfi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineTwo", ErrNonAlphanumeric, fibfi.FIToFI.LineTwo).Error(), err.Error()) } // TestFIBeneficiaryFILineThreeAlphaNumeric validates FIBeneficiaryFI LineThree is alphanumeric func TestFIBeneficiaryFILineThreeAlphaNumeric(t *testing.T) { fibfi := mockFIBeneficiaryFI() fibfi.FIToFI.LineThree = "®" - if err := fibfi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fibfi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineThree", ErrNonAlphanumeric, fibfi.FIToFI.LineThree).Error(), err.Error()) } // TestFIBeneficiaryFILineFourAlphaNumeric validates FIBeneficiaryFI LineFour is alphanumeric func TestFIBeneficiaryFILineFourAlphaNumeric(t *testing.T) { fibfi := mockFIBeneficiaryFI() fibfi.FIToFI.LineFour = "®" - if err := fibfi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fibfi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineFour", ErrNonAlphanumeric, fibfi.FIToFI.LineFour).Error(), err.Error()) } // TestFIBeneficiaryFILineFiveAlphaNumeric validates FIBeneficiaryFI LineFive is alphanumeric func TestFIBeneficiaryFILineFiveAlphaNumeric(t *testing.T) { fibfi := mockFIBeneficiaryFI() fibfi.FIToFI.LineFive = "®" - if err := fibfi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fibfi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineFive", ErrNonAlphanumeric, fibfi.FIToFI.LineFive).Error(), err.Error()) } // TestFIBeneficiaryFILineSixAlphaNumeric validates FIBeneficiaryFI LineSix is alphanumeric func TestFIBeneficiaryFILineSixAlphaNumeric(t *testing.T) { fibfi := mockFIBeneficiaryFI() fibfi.FIToFI.LineSix = "®" - if err := fibfi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fibfi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineSix", ErrNonAlphanumeric, fibfi.FIToFI.LineSix).Error(), err.Error()) } // TestParseFIBeneficiaryFIWrongLength parses a wrong FIBeneficiaryFI record length @@ -97,15 +97,11 @@ func TestParseFIBeneficiaryFIWrongLength(t *testing.T) { var line = "{6300}Line One Line Two Line Three Line Four Line Five 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) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), NewTagWrongLengthErr(201, len(r.line)).Error(), err.Error()) } // TestParseFIBeneficiaryFIReaderParseError parses a wrong FIBeneficiaryFI reader parse error @@ -113,30 +109,25 @@ func TestParseFIBeneficiaryFIReaderParseError(t *testing.T) { var line = "{6300}Line ®ne Line Two Line Three Line Four Line Five 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, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + _, err = r.Read() - if err != nil { - if !base.Has(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) } // TestFIBeneficiaryFITagError validates a FIBeneficiaryFI tag func TestFIBeneficiaryFITagError(t *testing.T) { fibfi := mockFIBeneficiaryFI() fibfi.tag = "{9999}" - if err := fibfi.Validate(); err != nil { - if !base.Match(err, ErrValidTagForType) { - t.Errorf("%T: %s", err, err) - } - } + + err := fibfi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("tag", ErrValidTagForType, fibfi.tag).Error(), err.Error()) } diff --git a/fiBeneficiary_test.go b/fiBeneficiary_test.go index 928e8d2a..b2253318 100644 --- a/fiBeneficiary_test.go +++ b/fiBeneficiary_test.go @@ -1,9 +1,10 @@ package wire import ( - "github.com/moov-io/base" "strings" "testing" + + "github.com/stretchr/testify/require" ) // mockFIBeneficiary creates a FIBeneficiary @@ -21,75 +22,74 @@ func mockFIBeneficiary() *FIBeneficiary { // TestMockFIBeneficiary validates mockFIBeneficiary func TestMockFIBeneficiary(t *testing.T) { fib := mockFIBeneficiary() - if err := fib.Validate(); err != nil { - t.Error("mockFIBeneficiary does not validate and will break other tests") - } + + require.NoError(t, fib.Validate(), "mockFIBeneficiary does not validate and will break other tests") } // TestFIBeneficiaryLineOneAlphaNumeric validates FIBeneficiary LineOne is alphanumeric func TestFIBeneficiaryLineOneAlphaNumeric(t *testing.T) { fib := mockFIBeneficiary() fib.FIToFI.LineOne = "®" - if err := fib.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fib.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineOne", ErrNonAlphanumeric, fib.FIToFI.LineOne).Error(), err.Error()) } // TestFIBeneficiaryLineTwoAlphaNumeric validates FIBeneficiary LineTwo is alphanumeric func TestFIBeneficiaryLineTwoAlphaNumeric(t *testing.T) { fib := mockFIBeneficiary() fib.FIToFI.LineTwo = "®" - if err := fib.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fib.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineTwo", ErrNonAlphanumeric, fib.FIToFI.LineTwo).Error(), err.Error()) } // TestFIBeneficiaryLineThreeAlphaNumeric validates FIBeneficiary LineThree is alphanumeric func TestFIBeneficiaryLineThreeAlphaNumeric(t *testing.T) { fib := mockFIBeneficiary() fib.FIToFI.LineThree = "®" - if err := fib.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fib.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineThree", ErrNonAlphanumeric, fib.FIToFI.LineThree).Error(), err.Error()) } // TestFIBeneficiaryLineFourAlphaNumeric validates FIBeneficiary LineFour is alphanumeric func TestFIBeneficiaryLineFourAlphaNumeric(t *testing.T) { fib := mockFIBeneficiary() fib.FIToFI.LineFour = "®" - if err := fib.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fib.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineFour", ErrNonAlphanumeric, fib.FIToFI.LineFour).Error(), err.Error()) } // TestFIBeneficiaryLineFiveAlphaNumeric validates FIBeneficiary LineFive is alphanumeric func TestFIBeneficiaryLineFiveAlphaNumeric(t *testing.T) { fib := mockFIBeneficiary() fib.FIToFI.LineFive = "®" - if err := fib.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fib.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineFive", ErrNonAlphanumeric, fib.FIToFI.LineFive).Error(), err.Error()) } // TestFIBeneficiaryLineSixAlphaNumeric validates FIBeneficiary LineSix is alphanumeric func TestFIBeneficiaryLineSixAlphaNumeric(t *testing.T) { fib := mockFIBeneficiary() fib.FIToFI.LineSix = "®" - if err := fib.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fib.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineSix", ErrNonAlphanumeric, fib.FIToFI.LineSix).Error(), err.Error()) } // TestParseFIBeneficiaryWrongLength parses a wrong FIBeneficiary record length @@ -97,15 +97,11 @@ func TestParseFIBeneficiaryWrongLength(t *testing.T) { var line = "{6400}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) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), NewTagWrongLengthErr(201, len(r.line)).Error()) } // TestParseFIBeneficiaryReaderParseError parses a wrong FIBeneficiary reader parse error @@ -113,30 +109,25 @@ func TestParseFIBeneficiaryReaderParseError(t *testing.T) { var line = "{6400}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) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + _, err = r.Read() - if err != nil { - if !base.Has(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) } // TestFIBeneficiaryTagError validates a FIBeneficiary tag func TestFIBeneficiaryTagError(t *testing.T) { fib := mockFIBeneficiary() fib.tag = "{9999}" - if err := fib.Validate(); err != nil { - if !base.Match(err, ErrValidTagForType) { - t.Errorf("%T: %s", err, err) - } - } + + err := fib.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("tag", ErrValidTagForType, fib.tag).Error(), err.Error()) } diff --git a/fiDrawdownDebitAccountAdvice_test.go b/fiDrawdownDebitAccountAdvice_test.go index db436d78..2fab7ef1 100644 --- a/fiDrawdownDebitAccountAdvice_test.go +++ b/fiDrawdownDebitAccountAdvice_test.go @@ -1,9 +1,10 @@ package wire import ( - "github.com/moov-io/base" "strings" "testing" + + "github.com/stretchr/testify/require" ) // mockFIDrawdownDebitAccountAdvice creates a FIDrawdownDebitAccountAdvice @@ -22,86 +23,85 @@ func mockFIDrawdownDebitAccountAdvice() *FIDrawdownDebitAccountAdvice { // TestMockFIDrawdownDebitAccountAdvice validates mockFIDrawdownDebitAccountAdvice func TestMockFIDrawdownDebitAccountAdvice(t *testing.T) { debitDDAdvice := mockFIDrawdownDebitAccountAdvice() - if err := debitDDAdvice.Validate(); err != nil { - t.Error("mockFIDrawdownDebitAccountAdvice does not validate and will break other tests") - } + + require.NoError(t, debitDDAdvice.Validate(), "mockFIDrawdownDebitAccountAdvice does not validate and will break other tests") } // TestFIDrawdownDebitAccountAdviceAdviceCodeValid validates FIDrawdownDebitAccountAdvice AdviceCode is alphanumeric func TestFIDrawdownDebitAccountAdviceCodeValid(t *testing.T) { debitDDAdvice := mockFIDrawdownDebitAccountAdvice() debitDDAdvice.Advice.AdviceCode = "Z" - if err := debitDDAdvice.Validate(); err != nil { - if !base.Match(err, ErrAdviceCode) { - t.Errorf("%T: %s", err, err) - } - } + + err := debitDDAdvice.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("AdviceCode", ErrAdviceCode, debitDDAdvice.Advice.AdviceCode).Error(), err.Error()) } // TestFIDrawdownDebitAccountAdviceLineOneAlphaNumeric validates FIDrawdownDebitAccountAdvice LineOne is alphanumeric func TestFIDrawdownDebitAccountAdviceLineOneAlphaNumeric(t *testing.T) { debitDDAdvice := mockFIDrawdownDebitAccountAdvice() debitDDAdvice.Advice.LineOne = "®" - if err := debitDDAdvice.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := debitDDAdvice.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineOne", ErrNonAlphanumeric, debitDDAdvice.Advice.LineOne).Error(), err.Error()) } // TestFIDrawdownDebitAccountAdviceLineTwoAlphaNumeric validates FIDrawdownDebitAccountAdvice LineTwo is alphanumeric func TestFIDrawdownDebitAccountAdviceLineTwoAlphaNumeric(t *testing.T) { debitDDAdvice := mockFIDrawdownDebitAccountAdvice() debitDDAdvice.Advice.LineTwo = "®" - if err := debitDDAdvice.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := debitDDAdvice.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineTwo", ErrNonAlphanumeric, debitDDAdvice.Advice.LineTwo).Error(), err.Error()) } // TestFIDrawdownDebitAccountAdviceLineThreeAlphaNumeric validates FIDrawdownDebitAccountAdvice LineThree is alphanumeric func TestFIDrawdownDebitAccountAdviceLineThreeAlphaNumeric(t *testing.T) { debitDDAdvice := mockFIDrawdownDebitAccountAdvice() debitDDAdvice.Advice.LineThree = "®" - if err := debitDDAdvice.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := debitDDAdvice.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineThree", ErrNonAlphanumeric, debitDDAdvice.Advice.LineThree).Error(), err.Error()) } // TestFIDrawdownDebitAccountAdviceLineFourAlphaNumeric validates FIDrawdownDebitAccountAdvice LineFour is alphanumeric func TestFIDrawdownDebitAccountAdviceLineFourAlphaNumeric(t *testing.T) { debitDDAdvice := mockFIDrawdownDebitAccountAdvice() debitDDAdvice.Advice.LineFour = "®" - if err := debitDDAdvice.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := debitDDAdvice.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineFour", ErrNonAlphanumeric, debitDDAdvice.Advice.LineFour).Error(), err.Error()) } // TestFIDrawdownDebitAccountAdviceLineFiveAlphaNumeric validates FIDrawdownDebitAccountAdvice LineFive is alphanumeric func TestFIDrawdownDebitAccountAdviceLineFiveAlphaNumeric(t *testing.T) { debitDDAdvice := mockFIDrawdownDebitAccountAdvice() debitDDAdvice.Advice.LineFive = "®" - if err := debitDDAdvice.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := debitDDAdvice.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineFive", ErrNonAlphanumeric, debitDDAdvice.Advice.LineFive).Error(), err.Error()) } // TestFIDrawdownDebitAccountAdviceLineSixAlphaNumeric validates FIDrawdownDebitAccountAdvice LineSix is alphanumeric func TestFIDrawdownDebitAccountAdviceLineSixAlphaNumeric(t *testing.T) { debitDDAdvice := mockFIDrawdownDebitAccountAdvice() debitDDAdvice.Advice.LineSix = "®" - if err := debitDDAdvice.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := debitDDAdvice.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineSix", ErrNonAlphanumeric, debitDDAdvice.Advice.LineSix).Error(), err.Error()) } // TestParseFIDrawdownDebitAccountAdviceWrongLength parses a wrong FIDrawdownDebitAccountAdvice record length @@ -109,15 +109,11 @@ func TestParseFIDrawdownDebitAccountAdviceWrongLength(t *testing.T) { var line = "{6110}LTRLine One Line Two Line Three Line Four Line Five Line Six " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - fibfia := mockFIDrawdownDebitAccountAdvice() - fwm.SetFIDrawdownDebitAccountAdvice(fibfia) + err := r.parseFIDrawdownDebitAccountAdvice() - if err != nil { - if !base.Match(err, NewTagWrongLengthErr(200, len(r.line))) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), NewTagWrongLengthErr(200, len(r.line)).Error(), err.Error()) } // TestParseFIDrawdownDebitAccountAdviceReaderParseError parses a wrong FIDrawdownDebitAccountAdvice reader parse error @@ -125,30 +121,25 @@ func TestParseFIDrawdownDebitAccountAdviceReaderParseError(t *testing.T) { var line = "{6110}LTR®ine One Line Two Line Three Line Four Line Five Line Six " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - fibfia := mockFIDrawdownDebitAccountAdvice() - fwm.SetFIDrawdownDebitAccountAdvice(fibfia) + err := r.parseFIDrawdownDebitAccountAdvice() - if err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + _, err = r.Read() - if err != nil { - if !base.Has(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) } // TestFIDrawdownDebitAccountAdviceTagError validates a FIDrawdownDebitAccountAdvice tag func TestFIDrawdownDebitAccountAdviceTagError(t *testing.T) { debitDDAdvice := mockFIDrawdownDebitAccountAdvice() debitDDAdvice.tag = "{9999}" - if err := debitDDAdvice.Validate(); err != nil { - if !base.Match(err, ErrValidTagForType) { - t.Errorf("%T: %s", err, err) - } - } + + err := debitDDAdvice.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("tag", ErrValidTagForType, debitDDAdvice.tag).Error(), err.Error()) } diff --git a/fiIntermediaryFIAdvice_test.go b/fiIntermediaryFIAdvice_test.go index 10f0998f..03d17ae7 100644 --- a/fiIntermediaryFIAdvice_test.go +++ b/fiIntermediaryFIAdvice_test.go @@ -1,9 +1,10 @@ package wire import ( - "github.com/moov-io/base" "strings" "testing" + + "github.com/stretchr/testify/require" ) // mockFIIntermediaryFIAdvice creates a FIIntermediaryFIAdvice @@ -22,86 +23,85 @@ func mockFIIntermediaryFIAdvice() *FIIntermediaryFIAdvice { // TestMockFIIntermediaryFIAdvice validates mockFIIntermediaryFIAdvice func TestMockFIIntermediaryFIAdvice(t *testing.T) { fiifia := mockFIIntermediaryFIAdvice() - if err := fiifia.Validate(); err != nil { - t.Error("mockFIIntermediaryFIAdvice does not validate and will break other tests") - } + + require.NoError(t, fiifia.Validate(), "mockFIIntermediaryFIAdvice does not validate and will break other tests") } // TestFIIntermediaryFIAdviceAdviceCodeValid validates FIIntermediaryFIAdvice AdviceCode is alphanumeric func TestFIIntermediaryFIAdviceAdviceCodeValid(t *testing.T) { fiifia := mockFIIntermediaryFIAdvice() fiifia.Advice.AdviceCode = "Z" - if err := fiifia.Validate(); err != nil { - if !base.Match(err, ErrAdviceCode) { - t.Errorf("%T: %s", err, err) - } - } + + err := fiifia.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("AdviceCode", ErrAdviceCode, fiifia.Advice.AdviceCode).Error(), err.Error()) } // TestFIIntermediaryFIAdviceLineOneAlphaNumeric validates FIIntermediaryFIAdvice LineOne is alphanumeric func TestFIIntermediaryFIAdviceLineOneAlphaNumeric(t *testing.T) { fiifia := mockFIIntermediaryFIAdvice() fiifia.Advice.LineOne = "®" - if err := fiifia.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fiifia.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineOne", ErrNonAlphanumeric, fiifia.Advice.LineOne).Error(), err.Error()) } // TestFIIntermediaryFIAdviceLineTwoAlphaNumeric validates FIIntermediaryFIAdvice LineTwo is alphanumeric func TestFIIntermediaryFIAdviceLineTwoAlphaNumeric(t *testing.T) { fiifia := mockFIIntermediaryFIAdvice() fiifia.Advice.LineTwo = "®" - if err := fiifia.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fiifia.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineTwo", ErrNonAlphanumeric, fiifia.Advice.LineTwo).Error(), err.Error()) } // TestFIIntermediaryFIAdviceLineThreeAlphaNumeric validates FIIntermediaryFIAdvice LineThree is alphanumeric func TestFIIntermediaryFIAdviceLineThreeAlphaNumeric(t *testing.T) { fiifia := mockFIIntermediaryFIAdvice() fiifia.Advice.LineThree = "®" - if err := fiifia.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fiifia.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineThree", ErrNonAlphanumeric, fiifia.Advice.LineThree).Error(), err.Error()) } // TestFIIntermediaryFIAdviceLineFourAlphaNumeric validates FIIntermediaryFIAdvice LineFour is alphanumeric func TestFIIntermediaryFIAdviceLineFourAlphaNumeric(t *testing.T) { fiifia := mockFIIntermediaryFIAdvice() fiifia.Advice.LineFour = "®" - if err := fiifia.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fiifia.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineFour", ErrNonAlphanumeric, fiifia.Advice.LineFour).Error(), err.Error()) } // TestFIIntermediaryFIAdviceLineFiveAlphaNumeric validates FIIntermediaryFIAdvice LineFive is alphanumeric func TestFIIntermediaryFIAdviceLineFiveAlphaNumeric(t *testing.T) { fiifia := mockFIIntermediaryFIAdvice() fiifia.Advice.LineFive = "®" - if err := fiifia.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fiifia.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineFive", ErrNonAlphanumeric, fiifia.Advice.LineFive).Error(), err.Error()) } // TestFIIntermediaryFIAdviceLineSixAlphaNumeric validates FIIntermediaryFIAdvice LineSix is alphanumeric func TestFIIntermediaryFIAdviceLineSixAlphaNumeric(t *testing.T) { fiifia := mockFIIntermediaryFIAdvice() fiifia.Advice.LineSix = "®" - if err := fiifia.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fiifia.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineSix", ErrNonAlphanumeric, fiifia.Advice.LineSix).Error(), err.Error()) } // TestParseFIIntermediaryFIAdviceWrongLength parses a wrong FIIntermediaryFIAdvice record length @@ -109,15 +109,9 @@ func TestParseFIIntermediaryFIAdviceWrongLength(t *testing.T) { var line = "{6210}LTRLine One Line Two Line Three Line Four Line Five Line Six " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - fiifia := mockFIIntermediaryFIAdvice() - fwm.SetFIIntermediaryFIAdvice(fiifia) + err := r.parseFIIntermediaryFIAdvice() - if err != nil { - if !base.Match(err, NewTagWrongLengthErr(200, len(r.line))) { - t.Errorf("%T: %s", err, err) - } - } + require.Contains(t, err.Error(), NewTagWrongLengthErr(200, len(r.line)).Error()) } // TestParseFIIntermediaryFIAdviceReaderParseError parses a wrong FIIntermediaryFIAdvice reader parse error @@ -125,30 +119,25 @@ func TestParseFIIntermediaryFIAdviceReaderParseError(t *testing.T) { var line = "{6210}LTRLine ®ne Line Two Line Three Line Four Line Five Line Six " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - fiifia := mockFIIntermediaryFIAdvice() - fwm.SetFIIntermediaryFIAdvice(fiifia) + err := r.parseFIIntermediaryFIAdvice() - if err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + _, err = r.Read() - if err != nil { - if !base.Has(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) } // TestFIIntermediaryFIAdviceTagError validates a FIIntermediaryFIAdvice tag func TestFIIntermediaryFIAdviceTagError(t *testing.T) { fiifia := mockFIIntermediaryFI() fiifia.tag = "{9999}" - if err := fiifia.Validate(); err != nil { - if !base.Match(err, ErrValidTagForType) { - t.Errorf("%T: %s", err, err) - } - } + + err := fiifia.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("tag", ErrValidTagForType, fiifia.tag).Error(), err.Error()) } diff --git a/fiIntermediaryFI_test.go b/fiIntermediaryFI_test.go index 2014c520..e532f37c 100644 --- a/fiIntermediaryFI_test.go +++ b/fiIntermediaryFI_test.go @@ -1,9 +1,10 @@ package wire import ( - "github.com/moov-io/base" "strings" "testing" + + "github.com/stretchr/testify/require" ) // mockFIIntermediaryFI creates a FIIntermediaryFI @@ -21,75 +22,74 @@ func mockFIIntermediaryFI() *FIIntermediaryFI { // TestMockFIIntermediaryFI validates mockFIIntermediaryFI func TestMockFIIntermediaryFI(t *testing.T) { fiifi := mockFIIntermediaryFI() - if err := fiifi.Validate(); err != nil { - t.Error("mockFIIntermediaryFI does not validate and will break other tests") - } + + 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 = "®" - if err := fiifi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fiifi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineOne", ErrNonAlphanumeric, fiifi.FIToFI.LineOne).Error(), err.Error()) } // TestFIIntermediaryFILineTwoAlphaNumeric validates FIIntermediaryFI LineTwo is alphanumeric func TestFIIntermediaryFILineTwoAlphaNumeric(t *testing.T) { fiifi := mockFIIntermediaryFI() fiifi.FIToFI.LineTwo = "®" - if err := fiifi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fiifi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineTwo", ErrNonAlphanumeric, fiifi.FIToFI.LineTwo).Error(), err.Error()) } // TestFIIntermediaryFILineThreeAlphaNumeric validates FIIntermediaryFI LineThree is alphanumeric func TestFIIntermediaryFILineThreeAlphaNumeric(t *testing.T) { fiifi := mockFIIntermediaryFI() fiifi.FIToFI.LineThree = "®" - if err := fiifi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fiifi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineThree", ErrNonAlphanumeric, fiifi.FIToFI.LineThree).Error(), err.Error()) } // TestFIIntermediaryFILineFourAlphaNumeric validates FIIntermediaryFI LineFour is alphanumeric func TestFIIntermediaryFILineFourAlphaNumeric(t *testing.T) { fiifi := mockFIIntermediaryFI() fiifi.FIToFI.LineFour = "®" - if err := fiifi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fiifi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineFour", ErrNonAlphanumeric, fiifi.FIToFI.LineFour).Error(), err.Error()) } // TestFIIntermediaryFILineFiveAlphaNumeric validates FIIntermediaryFI LineFive is alphanumeric func TestFIIntermediaryFILineFiveAlphaNumeric(t *testing.T) { fiifi := mockFIIntermediaryFI() fiifi.FIToFI.LineFive = "®" - if err := fiifi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fiifi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineFive", ErrNonAlphanumeric, fiifi.FIToFI.LineFive).Error(), err.Error()) } // TestFIIntermediaryFILineSixAlphaNumeric validates FIIntermediaryFI LineSix is alphanumeric func TestFIIntermediaryFILineSixAlphaNumeric(t *testing.T) { fiifi := mockFIIntermediaryFI() fiifi.FIToFI.LineSix = "®" - if err := fiifi.Validate(); err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + err := fiifi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("LineSix", ErrNonAlphanumeric, fiifi.FIToFI.LineSix).Error(), err.Error()) } // TestParseFIIntermediaryFIWrongLength parses a wrong FIIntermediaryFI record length @@ -97,15 +97,11 @@ func TestParseFIIntermediaryFIWrongLength(t *testing.T) { var line = "{6200}Line ®ix " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - fiifi := mockFIIntermediaryFI() - fwm.SetFIIntermediaryFI(fiifi) + err := r.parseFIIntermediaryFI() - if err != nil { - if !base.Match(err, NewTagWrongLengthErr(201, len(r.line))) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), NewTagWrongLengthErr(201, len(r.line)).Error()) } // TestParseFIIntermediaryFIReaderParseError parses a wrong FIIntermediaryFI reader parse error @@ -113,30 +109,25 @@ func TestParseFIIntermediaryFIReaderParseError(t *testing.T) { var line = "{6200}Line ®ix " r := NewReader(strings.NewReader(line)) r.line = line - fwm := new(FEDWireMessage) - fiifi := mockFIIntermediaryFI() - fwm.SetFIIntermediaryFI(fiifi) + err := r.parseFIIntermediaryFI() - if err != nil { - if !base.Match(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) + _, err = r.Read() - if err != nil { - if !base.Has(err, ErrNonAlphanumeric) { - t.Errorf("%T: %s", err, err) - } - } + + require.NotNil(t, err) + require.Contains(t, err.Error(), ErrNonAlphanumeric.Error()) } // TestFIIntermediaryFITagError validates a FIIntermediaryFI tag func TestFIIntermediaryFITagError(t *testing.T) { fiifi := mockFIIntermediaryFI() fiifi.tag = "{9999}" - if err := fiifi.Validate(); err != nil { - if !base.Match(err, ErrValidTagForType) { - t.Errorf("%T: %s", err, err) - } - } + + err := fiifi.Validate() + + require.NotNil(t, err) + require.Equal(t, fieldError("tag", ErrValidTagForType, fiifi.tag).Error(), err.Error()) }