(t *testing.T)
| 457 | } |
| 458 | |
| 459 | func TestExtractDomains(t *testing.T) { |
| 460 | type tCase struct { |
| 461 | hdr string |
| 462 | |
| 463 | fromDomain string |
| 464 | } |
| 465 | test := func(i int, c tCase) { |
| 466 | hdr, err := textproto.ReadHeader(bufio.NewReader(strings.NewReader(c.hdr + "\n\n"))) |
| 467 | if err != nil { |
| 468 | panic(err) |
| 469 | } |
| 470 | |
| 471 | domain, err := ExtractFromDomain(hdr) |
| 472 | if c.fromDomain == "" && err == nil { |
| 473 | t.Errorf("%d: expected failure, got fromDomain = %s", i, domain) |
| 474 | return |
| 475 | } |
| 476 | if c.fromDomain != "" && err != nil { |
| 477 | t.Errorf("%d: unexpected error: %v", i, err) |
| 478 | return |
| 479 | } |
| 480 | if domain != c.fromDomain { |
| 481 | t.Errorf("%d: want fromDomain = %v but got %s", i, c.fromDomain, domain) |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | cases := []tCase{ |
| 486 | { |
| 487 | hdr: `From: <test@example.org>`, |
| 488 | fromDomain: "example.org", |
| 489 | }, |
| 490 | { |
| 491 | hdr: `From: <test@foo.example.org>`, |
| 492 | fromDomain: "foo.example.org", |
| 493 | }, |
| 494 | { |
| 495 | hdr: `From: <test@foo.example.org>, <test@bar.example.org>`, |
| 496 | }, |
| 497 | { |
| 498 | hdr: `From: <test@foo.example.org>, |
| 499 | From: <test@bar.example.org>`, |
| 500 | }, |
| 501 | { |
| 502 | hdr: `From: <test@>`, |
| 503 | }, |
| 504 | { |
| 505 | hdr: `From: `, |
| 506 | }, |
| 507 | { |
| 508 | hdr: `From: foo`, |
| 509 | }, |
| 510 | } |
| 511 | for i, case_ := range cases { |
| 512 | test(i, case_) |
| 513 | } |
| 514 | } |
nothing calls this directly
no test coverage detected