<commit_before>-module (beehive_bee_object_test).
-include ("beehive.hrl").
-include_lib("eunit/include/eunit.hrl").

-define (DEBUG, false).
-define (CLEANUP, fun() ->
  case ?DEBUG of
    false -> 
      lists:map(fun(Dir) -> clean_up_dir(Dir) end, ["squashed", "run"]);
    true -> ok
  end
end()).

-define (DPRINT (Str), fun() ->
  case ?DEBUG of
    true -> erlang:display(Str);
    false -> ok
  end
end()).

setup() ->
  bh_test_util:setup([]),
  beehive_bee_object:init(),
  ok.
  
teardown(_X) ->
  ?CLEANUP,
  ok.

all_test_() ->
  Tests = {inorder,
    {setup,
      fun setup/0,
      fun teardown/1,
      [
        fun git_clone/0
        ,fun git_bundle/0
        ,fun git_bundle_with_errors/0
        ,fun responding_from/0
        ,fun ls_bee/0
        % Type tests
        ,fun bundle_type/0
        ,fun mount_t/0
        ,fun start_t/0
        ,fun stop_t/0
        ,fun cleanup_t/0
        ,fun send_t/0
        ,fun have_bee_t/0
        % ,fun git_clone_with_errors/0
      ]
    }
  },
  {timeout, 90, Tests}.

git_clone() ->
  ?DPRINT({starting, git_clone}),
  % Update the repos
  {{Year, Month, Day}, {Hour, Minute, Second}} = erlang:universaltime(),
  Ts = lists:flatten(io_lib:format("~w~2..0w~2..0w~2..0w~2..0w~2..0w", [Year, Month, Day, Hour, Minute, Second])),
  
  ReposDir = proplists:get_value(url, git_repos_props()),
  
  os:cmd([
    "cd ", ReposDir, " && echo '", Ts, "' > LATEST_REV && git commit -a -m 'updated time for beehive_bee_object_test_app purposes'"
  ]),
  % Pull one with a specific revision
  Pid = spawn(fun() -> responding_loop([]) end),
  beehive_bee_object:clone([{revision, "281580bc654138df2ca0d7665bc1ac84d4677fc8"}|git_repos_props()], Pid),
  ?assertEqual("281580bc654138df2ca0d7665bc1ac84d4677fc8", get_current_revision(git)),
  
  % Do run it with an after command
  beehive_bee_object:clone([{post, "touch NEW_FILE"}|git_repos_props()]),
  timer:sleep(200), % let it work
  ReposBundleDir = filename:join([related_dir(), "squashed", "beehive_bee_object_test_app"]),
  os:cmd(["ls ", ReposBundleDir]),
  ?assert(filelib:is_file(filename:join([ReposBundleDir, "NEW_FILE"]))),
  ?DPRINT({git_clone, passed}),
  passed.

git_bundle() ->
  rm_rf(filename:join([related_dir(), "squashed", "testing_bee_out"])),
  ?DPRINT({starting, git_bundle}),
  beehive_bee_object:bundle(git_repos_props()),
  BeeFile = filename:join([related_dir(), "squashed", "beehive_bee_object_test_app.bee"]),
  ?assert(filelib:is_file(BeeFile)),
  % Run it with a before
  beehive_bee_object:bundle([{pre, "touch DUMMY_FILE"}|git_repos_props()]),
  % Untar and ensure the file is there
  BeeDir = filename:join([related_dir(), "squashed", "testing_bee_out"]),
  file:make_dir(BeeDir),<commit_msg>Updated git version number on tests with new git clone<commit_after>-module (beehive_bee_object_test).
-include ("beehive.hrl").
-include_lib("eunit/include/eunit.hrl").

-define (DEBUG, false).
-define (CLEANUP, fun() ->
  case ?DEBUG of
    false -> 
      lists:map(fun(Dir) -> clean_up_dir(Dir) end, ["squashed", "run"]);
    true -> ok
  end
end()).

-define (DPRINT (Str), fun() ->
  case ?DEBUG of
    true -> erlang:display(Str);
    false -> ok
  end
end()).

setup() ->
  bh_test_util:setup([]),
  beehive_bee_object:init(),
  ok.
  
teardown(_X) ->
  ?CLEANUP,
  ok.

all_test_() ->
  Tests = {inorder,
    {setup,
      fun setup/0,
      fun teardown/1,
      [
        fun git_clone/0
        ,fun git_bundle/0
        ,fun git_bundle_with_errors/0
        ,fun responding_from/0
        ,fun ls_bee/0
        % Type tests
        ,fun bundle_type/0
        ,fun mount_t/0
        ,fun start_t/0
        ,fun stop_t/0
        ,fun cleanup_t/0
        ,fun send_t/0
        ,fun have_bee_t/0
        % ,fun git_clone_with_errors/0
      ]
    }
  },
  {timeout, 90, Tests}.

git_clone() ->
  ?DPRINT({starting, git_clone}),
  % Update the repos
  {{Year, Month, Day}, {Hour, Minute, Second}} = erlang:universaltime(),
  Ts = lists:flatten(io_lib:format("~w~2..0w~2..0w~2..0w~2..0w~2..0w", [Year, Month, Day, Hour, Minute, Second])),
  
  ReposDir = proplists:get_value(url, git_repos_props()),
  
  os:cmd([
    "cd ", ReposDir, " && echo '", Ts, "' > LATEST_REV && git commit -a -m 'updated time for beehive_bee_object_test_app purposes'"
  ]),
  % Pull one with a specific revision
  Pid = spawn(fun() -> responding_loop([]) end),
  beehive_bee_object:clone([{revision, "ab4b11e0587d8a0a70390099127ac6eac60d3768"}|git_repos_props()], Pid),
  ?assertEqual("ab4b11e0587d8a0a70390099127ac6eac60d3768", get_current_revision(git)),
  
  % Do run it with an after command
  beehive_bee_object:clone([{post, "touch NEW_FILE"}|git_repos_props()]),
  timer:sleep(200), % let it work
  ReposBundleDir = filename:join([related_dir(), "squashed", "beehive_bee_object_test_app"]),
  os:cmd(["ls ", ReposBundleDir]),
  ?assert(filelib:is_file(filename:join([ReposBundleDir, "NEW_FILE"]))),
  ?DPRINT({git_clone, passed}),
  passed.

git_bundle() ->
  rm_rf(filename:join([related_dir(), "squashed", "testing_bee_out"])),
  ?DPRINT({starting, git_bundle}),
  beehive_bee_object:bundle(git_repos_props()),
  BeeFile = filename:join([related_dir(), "squashed", "beehive_bee_object_test_app.bee"]),
  ?assert(filelib:is_file(BeeFile)),
  % Run it with a before
  beehive_bee_object:bundle([{pre, "touch DUMMY_FILE"}|git_repos_props()]),
  % Untar and ensure the file is there
  BeeDir = filename:join([related_dir(), "squashed", "testing_bee_out"]),
  file:make_dir(BeeDir),
{'fraction_non_alphanumeric': 0.16287947645882567, 'fraction_numerical': 0.030176331576077076, 'mean_word_length': 3.8094405594405596, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '980962', 'n_tokens_mistral': 2218, 'n_tokens_neox': 2119, 'n_words': 396}