(t *testing.T)
| 778 | } |
| 779 | |
| 780 | func TestVFSFile_NewDatabase_WriteAndSync(t *testing.T) { |
| 781 | // Test writing to a new database and syncing to remote |
| 782 | client := newWriteTestReplicaClient() |
| 783 | |
| 784 | tmpDir := t.TempDir() |
| 785 | bufferPath := tmpDir + "/.litestream-write-buffer" |
| 786 | |
| 787 | logger := slog.Default() |
| 788 | f := NewVFSFile(client, "new.db", logger) |
| 789 | f.writeEnabled = true |
| 790 | f.dirty = make(map[uint32]int64) |
| 791 | f.syncInterval = 0 |
| 792 | f.bufferPath = bufferPath |
| 793 | |
| 794 | if err := f.Open(); err != nil { |
| 795 | t.Fatal(err) |
| 796 | } |
| 797 | defer f.Close() |
| 798 | |
| 799 | // Write data to page 1 |
| 800 | writeData := []byte("new database content") |
| 801 | n, err := f.WriteAt(writeData, 0) |
| 802 | if err != nil { |
| 803 | t.Fatal(err) |
| 804 | } |
| 805 | if n != len(writeData) { |
| 806 | t.Errorf("expected %d bytes written, got %d", len(writeData), n) |
| 807 | } |
| 808 | |
| 809 | // Verify dirty page exists |
| 810 | if len(f.dirty) != 1 { |
| 811 | t.Errorf("expected 1 dirty page, got %d", len(f.dirty)) |
| 812 | } |
| 813 | |
| 814 | // Sync to remote |
| 815 | if err := f.Sync(0); err != nil { |
| 816 | t.Fatal(err) |
| 817 | } |
| 818 | |
| 819 | // Verify TXID advanced |
| 820 | if f.expectedTXID != 1 { |
| 821 | t.Errorf("expected expectedTXID 1 after sync, got %d", f.expectedTXID) |
| 822 | } |
| 823 | if f.pendingTXID != 2 { |
| 824 | t.Errorf("expected pendingTXID 2 after sync, got %d", f.pendingTXID) |
| 825 | } |
| 826 | |
| 827 | // Verify LTX file was written |
| 828 | client.mu.Lock() |
| 829 | if len(client.ltxFiles[0]) != 1 { |
| 830 | t.Errorf("expected 1 LTX file after sync, got %d", len(client.ltxFiles[0])) |
| 831 | } |
| 832 | if len(client.ltxFiles[0]) > 0 { |
| 833 | info := client.ltxFiles[0][0] |
| 834 | if info.MinTXID != 1 || info.MaxTXID != 1 { |
| 835 | t.Errorf("expected TXID 1, got min=%d max=%d", info.MinTXID, info.MaxTXID) |
| 836 | } |
| 837 | } |
nothing calls this directly
no test coverage detected