@@ -559,11 +559,81 @@ hierarchical_path_resolution_test(Store) ->
559559 hb_store :read (Store , [<<" test-link" >>, <<" test-file" >>])
560560 ).
561561
562+ % % @doc Test the hb_store:sync function by syncing from hb_store_fs to hb_store_lmdb
563+ hb_store_sync_test (_Store ) ->
564+ % Generate unique names to avoid conflicts
565+ TestId = integer_to_binary (erlang :system_time (microsecond )),
566+ % Set up FromStore (hb_store_fs) with resolve=false as specified
567+ FromStore = #{
568+ <<" store-module" >> => hb_store_fs ,
569+ <<" name" >> => <<" cache-sync-from-" , TestId /binary >>,
570+ <<" resolve" >> => false
571+ },
572+ % Set up ToStore (hb_store_lmdb)
573+ ToStore = #{
574+ <<" store-module" >> => hb_store_lmdb ,
575+ <<" name" >> => <<" cache-sync-to-" , TestId /binary >>
576+ },
577+
578+ % Clean up any existing data
579+ hb_store :reset (FromStore ),
580+ hb_store :reset (ToStore ),
581+
582+ % Start both stores
583+ hb_store :start (FromStore ),
584+ hb_store :start (ToStore ),
585+
586+ % Populate FromStore with directories, files, and links
587+ % Create a directory structure
588+ ok = hb_store :make_group (FromStore , <<" test-dir" >>),
589+ ok = hb_store :write (FromStore , <<" test-dir/file1.txt" >>, <<" Hello World" >>),
590+ ok = hb_store :write (FromStore , <<" test-dir/file2.txt" >>, <<" Test Data" >>),
591+
592+ % Create a nested directory
593+ ok = hb_store :make_group (FromStore , <<" test-dir/nested" >>),
594+ ok = hb_store :write (FromStore , <<" test-dir/nested/deep-file.txt" >>, <<" Deep Content" >>),
595+
596+ % Create some top-level files
597+ ok = hb_store :write (FromStore , <<" root-file.txt" >>, <<" Root Content" >>),
598+
599+ % Create a link
600+ ok = hb_store :make_link (FromStore , <<" root-file.txt" >>, <<" link-to-root" >>),
601+
602+ % Perform the sync operation
603+ Result = hb_store :sync (FromStore , ToStore ),
604+ ? assertEqual (ok , Result ),
605+
606+ % Verify that directories exist in ToStore
607+ ? assertEqual (composite , hb_store :type (ToStore , <<" test-dir" >>)),
608+ ? assertEqual (composite , hb_store :type (ToStore , <<" test-dir/nested" >>)),
609+
610+ % Verify that files exist in ToStore
611+ {ok , File1Content } = hb_store :read (ToStore , <<" test-dir/file1.txt" >>),
612+ ? assertEqual (<<" Hello World" >>, File1Content ),
613+
614+ {ok , File2Content } = hb_store :read (ToStore , <<" test-dir/file2.txt" >>),
615+ ? assertEqual (<<" Test Data" >>, File2Content ),
616+
617+ {ok , DeepContent } = hb_store :read (ToStore , <<" test-dir/nested/deep-file.txt" >>),
618+ ? assertEqual (<<" Deep Content" >>, DeepContent ),
619+
620+ {ok , RootContent } = hb_store :read (ToStore , <<" root-file.txt" >>),
621+ ? assertEqual (<<" Root Content" >>, RootContent ),
622+
623+ % Verify that links work in ToStore
624+ {ok , LinkContent } = hb_store :read (ToStore , <<" link-to-root" >>),
625+ ? assertEqual (<<" Root Content" >>, LinkContent ),
626+
627+ % Clean up
628+ hb_store :stop (FromStore ),
629+ hb_store :stop (ToStore ).
630+
562631store_suite_test_ () ->
563632 generate_test_suite ([
564633 {" simple path resolution" , fun simple_path_resolution_test /1 },
565634 {" resursive path resolution" , fun resursive_path_resolution_test /1 },
566- {" hierarchical path resolution" , fun hierarchical_path_resolution_test /1 }
635+ {" hierarchical path resolution" , fun hierarchical_path_resolution_test /1 },
636+ {" hb_store sync" , fun hb_store_sync_test /1 }
567637 ]).
568638
569639benchmark_suite_test_ () ->
0 commit comments