1
0
mirror of https://github.com/aclindsa/ofxgo.git synced 2025-07-01 11:48:38 -04:00

Add test for banking responses

This also adds a generic response equality testing framework, a missing
Status field to all current responses, and Equal() methods to all basic
types.
This commit is contained in:
2017-03-30 07:04:54 -04:00
parent 6d6ee3ea1b
commit 6efd3ae921
8 changed files with 302 additions and 1 deletions

View File

@ -33,6 +33,10 @@ func (i *Int) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
return nil
}
func (i Int) Equal(o Int) bool {
return i == o
}
type Amount big.Rat
func (a *Amount) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
@ -66,6 +70,11 @@ func (a *Amount) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
return e.EncodeElement(a.String(), start)
}
func (a Amount) Equal(o Amount) bool {
ratA := (*big.Rat)(&a)
return ratA.Cmp((*big.Rat)(&o)) == 0
}
type Date time.Time
var ofxDateFormats = []string{
@ -167,6 +176,10 @@ func (od *Date) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
return e.EncodeElement(od.String(), start)
}
func (od Date) Equal(o Date) bool {
return time.Time(od).Equal(time.Time(o))
}
type String string
func (os *String) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
@ -183,6 +196,10 @@ func (os *String) String() string {
return string(*os)
}
func (os String) Equal(o String) bool {
return os == o
}
type Boolean bool
func (ob *Boolean) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
@ -214,6 +231,10 @@ func (ob *Boolean) String() string {
return fmt.Sprintf("%v", *ob)
}
func (ob Boolean) Equal(o Boolean) bool {
return ob == o
}
type UID string
// The OFX specification recommends that UIDs follow the standard UUID
@ -228,6 +249,10 @@ func (ou UID) RecommendedFormat() (bool, error) {
return true, nil
}
func (ou UID) Equal(o UID) bool {
return ou == o
}
func RandomUID() (*UID, error) {
uidbytes := make([]byte, 16)
n, err := rand.Read(uidbytes[:])