(t *testing.T)
| 572 | } |
| 573 | |
| 574 | func TestFileSystemGetReader(t *testing.T) { |
| 575 | dir := createTestDir(t) |
| 576 | defer os.RemoveAll(dir) |
| 577 | |
| 578 | fsys, err := filesystem.NewLocal(dir) |
| 579 | if err != nil { |
| 580 | t.Fatal(err) |
| 581 | } |
| 582 | defer fsys.Close() |
| 583 | |
| 584 | scenarios := []struct { |
| 585 | file string |
| 586 | expectError bool |
| 587 | expectedContent string |
| 588 | }{ |
| 589 | {"test/missing.txt", true, ""}, |
| 590 | {"test/sub1.txt", false, "sub1"}, |
| 591 | } |
| 592 | |
| 593 | for _, s := range scenarios { |
| 594 | t.Run(s.file, func(t *testing.T) { |
| 595 | f, err := fsys.GetReader(s.file) |
| 596 | defer func() { |
| 597 | if f != nil { |
| 598 | f.Close() |
| 599 | } |
| 600 | }() |
| 601 | |
| 602 | hasErr := err != nil |
| 603 | if hasErr != s.expectError { |
| 604 | t.Fatalf("Expected hasErr %v, got %v", s.expectError, hasErr) |
| 605 | } |
| 606 | |
| 607 | if hasErr { |
| 608 | if !errors.Is(err, filesystem.ErrNotFound) { |
| 609 | t.Fatalf("Expected ErrNotFound error, got %v", err) |
| 610 | } |
| 611 | return |
| 612 | } |
| 613 | |
| 614 | raw, err := io.ReadAll(f) |
| 615 | if err != nil { |
| 616 | t.Fatal(err) |
| 617 | } |
| 618 | |
| 619 | if str := string(raw); str != s.expectedContent { |
| 620 | t.Fatalf("Expected content\n%s\ngot\n%s", s.expectedContent, str) |
| 621 | } |
| 622 | }) |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | func TestFileSystemGetReuploadableFile(t *testing.T) { |
| 627 | dir := createTestDir(t) |
nothing calls this directly
no test coverage detected
searching dependent graphs…