Ensure that Copy handles write errors right.
(t *testing.T)
| 617 | |
| 618 | // Ensure that Copy handles write errors right. |
| 619 | func TestTx_CopyFile_Error_Normal(t *testing.T) { |
| 620 | db := btesting.MustCreateDB(t) |
| 621 | if err := db.Update(func(tx *bolt.Tx) error { |
| 622 | b, err := tx.CreateBucket([]byte("widgets")) |
| 623 | if err != nil { |
| 624 | t.Fatal(err) |
| 625 | } |
| 626 | if err := b.Put([]byte("foo"), []byte("bar")); err != nil { |
| 627 | t.Fatal(err) |
| 628 | } |
| 629 | if err := b.Put([]byte("baz"), []byte("bat")); err != nil { |
| 630 | t.Fatal(err) |
| 631 | } |
| 632 | return nil |
| 633 | }); err != nil { |
| 634 | t.Fatal(err) |
| 635 | } |
| 636 | |
| 637 | if err := db.View(func(tx *bolt.Tx) error { |
| 638 | return tx.Copy(&failWriter{3 * db.Info().PageSize}) |
| 639 | }); err == nil || err.Error() != "error injected for tests" { |
| 640 | t.Fatalf("unexpected error: %v", err) |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | // TestTx_Rollback ensures there is no error when tx rollback whether we sync freelist or not. |
| 645 | func TestTx_Rollback(t *testing.T) { |
nothing calls this directly
no test coverage detected