mirror of
https://github.com/aclindsa/ofxgo.git
synced 2025-06-30 19:28:39 -04:00
Add the ability to marshal a Response to SGML/XML and test it
This allows for ofxgo to be used to create well-formatted OFX from poor OFX, or even be used to generate OFX from other formats for easier importing into financial management software. Test this functionality by adding "round trip" testing to all existing tests - ensure that responses' content is the same after a round trip of marshalling and unmarshalling them.
This commit is contained in:
@ -136,6 +136,20 @@ func checkResponsesEqual(t *testing.T, expected, actual *ofxgo.Response) {
|
||||
checkEqual(t, "", reflect.ValueOf(expected), reflect.ValueOf(actual))
|
||||
}
|
||||
|
||||
func checkResponseRoundTrip(t *testing.T, response *ofxgo.Response) {
|
||||
b, err := response.Marshal()
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error re-marshaling OFX response: %s\n", err)
|
||||
}
|
||||
roundtripped, err := ofxgo.ParseResponse(b)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error re-parsing OFX response: %s\n", err)
|
||||
}
|
||||
checkResponsesEqual(t, response, roundtripped)
|
||||
}
|
||||
|
||||
// Ensure that these samples both parse without errors, and can be converted
|
||||
// back and forth without changing.
|
||||
func TestValidSamples(t *testing.T) {
|
||||
fn := func(path string, info os.FileInfo, err error) error {
|
||||
if info.IsDir() {
|
||||
@ -147,10 +161,11 @@ func TestValidSamples(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error opening %s: %s\n", path, err)
|
||||
}
|
||||
_, err = ofxgo.ParseResponse(file)
|
||||
response, err := ofxgo.ParseResponse(file)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error parsing OFX response in %s: %s\n", path, err)
|
||||
}
|
||||
checkResponseRoundTrip(t, response)
|
||||
return nil
|
||||
}
|
||||
filepath.Walk("samples/valid_responses", fn)
|
||||
|
Reference in New Issue
Block a user