MCPcopy
hub / github.com/benbjohnson/litestream / TestSetWriteEnabled_ColdEnable

Function TestSetWriteEnabled_ColdEnable

vfs_write_test.go:1157–1214  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1155}
1156
1157func TestSetWriteEnabled_ColdEnable(t *testing.T) {
1158 client := newWriteTestReplicaClient()
1159
1160 pageSize := uint32(4096)
1161 initialPage := make([]byte, pageSize)
1162 createTestLTXFile(t, client, 1, pageSize, 1, map[uint32][]byte{1: initialPage})
1163
1164 // Create VFSFile WITHOUT write enabled initially
1165 logger := slog.Default()
1166 f := NewVFSFile(client, "test.db", logger)
1167 f.writeEnabled = false
1168 // Note: dirty, bufferPath, etc. are NOT set - simulating cold start
1169
1170 if err := f.Open(); err != nil {
1171 t.Fatal(err)
1172 }
1173 defer f.Close()
1174
1175 // Verify writes are disabled
1176 if f.writeEnabled {
1177 t.Error("expected writeEnabled to be false initially")
1178 }
1179
1180 // Enable writes via SetWriteEnabled (cold enable)
1181 if err := f.SetWriteEnabled(true); err != nil {
1182 t.Fatal(err)
1183 }
1184
1185 // Verify writes are now enabled
1186 if !f.writeEnabled {
1187 t.Error("expected writeEnabled to be true after cold enable")
1188 }
1189
1190 // Verify buffer was initialized
1191 if f.bufferFile == nil {
1192 t.Error("expected bufferFile to be initialized")
1193 }
1194
1195 // Verify dirty map was initialized
1196 if f.dirty == nil {
1197 t.Error("expected dirty map to be initialized")
1198 }
1199
1200 // Verify TXID state was initialized
1201 if f.pendingTXID == 0 {
1202 t.Error("expected pendingTXID to be initialized")
1203 }
1204
1205 // Verify we can write
1206 writeData := []byte("cold enable test")
1207 if _, err := f.WriteAt(writeData, 0); err != nil {
1208 t.Fatal(err)
1209 }
1210
1211 if len(f.dirty) == 0 {
1212 t.Error("expected dirty pages after write")
1213 }
1214}

Callers

nothing calls this directly

Calls 8

OpenMethod · 0.95
CloseMethod · 0.95
SetWriteEnabledMethod · 0.95
WriteAtMethod · 0.95
NewVFSFileFunction · 0.85
createTestLTXFileFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected