@@ -376,6 +376,54 @@ function tests.test_backup()
376376 print (" PASS: test_backup" )
377377end
378378
379+ function tests .test_checkpoint ()
380+ local path = " ./test_db_checkpoint"
381+ local checkpoint_path = " ./test_db_checkpoint_snap"
382+ cleanup_db (path )
383+ cleanup_db (checkpoint_path )
384+
385+ local db = tidesdb .TidesDB .open (path )
386+ db :create_column_family (" test_cf" )
387+ local cf = db :get_column_family (" test_cf" )
388+
389+ -- Insert data
390+ local txn = db :begin_txn ()
391+ txn :put (cf , " key1" , " value1" )
392+ txn :put (cf , " key2" , " value2" )
393+ txn :commit ()
394+ txn :free ()
395+
396+ -- Create checkpoint
397+ db :checkpoint (checkpoint_path )
398+
399+ db :close ()
400+
401+ -- Open checkpoint and verify data
402+ local cp_db = tidesdb .TidesDB .open (checkpoint_path )
403+ local cp_cf = cp_db :get_column_family (" test_cf" )
404+ local read_txn = cp_db :begin_txn ()
405+ local v1 = read_txn :get (cp_cf , " key1" )
406+ local v2 = read_txn :get (cp_cf , " key2" )
407+ assert_eq (v1 , " value1" , " checkpoint should contain key1" )
408+ assert_eq (v2 , " value2" , " checkpoint should contain key2" )
409+ read_txn :free ()
410+
411+ -- Verify checkpoint to existing non-empty dir fails
412+ cp_db :close ()
413+
414+ local db2 = tidesdb .TidesDB .open (path )
415+ local cf2 = db2 :get_column_family (" test_cf" )
416+
417+ local err = assert_error (function ()
418+ db2 :checkpoint (checkpoint_path )
419+ end , " checkpoint to non-empty dir should fail" )
420+
421+ db2 :close ()
422+ cleanup_db (path )
423+ cleanup_db (checkpoint_path )
424+ print (" PASS: test_checkpoint" )
425+ end
426+
379427function tests .test_update_runtime_config ()
380428 local path = " ./test_db_runtime_config"
381429 cleanup_db (path )
0 commit comments