Skip to content

Commit dbc143f

Browse files
committed
test: add sync test case
1 parent 4395b4d commit dbc143f

File tree

1 file changed

+71
-1
lines changed

1 file changed

+71
-1
lines changed

src/hb_store.erl

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,11 +561,81 @@ hierarchical_path_resolution_test(Store) ->
561561
hb_store:read(Store, [<<"test-link">>, <<"test-file">>])
562562
).
563563

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

571641
benchmark_suite_test_() ->

0 commit comments

Comments
 (0)