package dmarc import ( "testing" "strings" //"fmt" "time" ) var reportXML = ` Yahoo! Inc. postmaster@dmarc.yahoo.com 1405588706.570207 1405468800 1405555199 example.com r r

none

100
127.0.0.1 2 none fail pass example.com example.com neutral example.com pass 127.0.0.2 988 none fail fail idfactor.example.com idfactor.example.com neutral idfactor.example.com none
` func TestInvalidDocument(t *testing.T) { xml := `` report, err := ParseReader(strings.NewReader(xml)) if err == nil { t.Errorf("Expected error, but got none") } if report != nil { t.Errorf("Report should have been but wasn't") } } func TestUnmarshalling(t *testing.T) { report, err := ParseReader(strings.NewReader(reportXML)) if err != nil { t.Errorf("Got error: %s:", err.Error()) } begin := time.Unix(1405468800, 0).UTC() if report.Metadata.DateRange.Begin != begin { t.Errorf("report.Metadata.DateRange.Begin did not match expected date") } end := time.Unix(1405555199, 0).UTC() if report.Metadata.DateRange.End != end { t.Errorf("report.Metadata.DateRange.end did not match expected date") } if report.PolicyPublished.Domain != "example.com" { t.Errorf("report.PolicyPublished.Domain was '%s', expected 'example.com'", report.PolicyPublished.Domain) } if len(report.Record) != 2 { t.Errorf("report.Record was expected to contain 2 items, only got: %d", len(report.Record)) } }