anchor.diff:  %%%-------------------------------------------------------------------
   
   -module(config).
  -
  --compile([{parse_transform, lager_transform}]).
   
   -include_lib("eunit/include/eunit.hrl").
   
  
positive.code: load_repos_adds_default_keys_test() ->
      RepoCfg = [
          #{domain => <<"test1.domain.org">>,
          keys => [<<"testkey1">>]},
          #{domain => <<"test2.domain.org">>,
          keys => [<<"testkey1">>, <<"testkey2">>]},
          <<"test3.domain.org">>
      ],
  
  
negative.code:     {value, #{domain := Name, keys := KeyIds}} = lists:search(
          fun(#{domain := D}) -> D =:= <<"test3.domain.org">> end, Repos),
      ?assert(Name =:= <<"test3.domain.org">>),
      ?assert(KeyIds =:= default).
  
  load_keys_adds_missing_key_definition_test() ->
      RepoCfg = [
          #{domain => <<"test1.domain.org">>,
            keys => [#{id => <<"testkey1">>, path => <<"/">>}]},
          #{domain => <<"test2.domain.org">>,
            keys => [#{id => <<"testkey1">>, path => <<"/">>},
                     #{id => <<"testkey2">>, path => <<"/">>}]},
          #{domain => <<"test3.domain.org">>,
            keys => default}
      ],
      KeyCfg = [
          #{type => <<"plain_text">>,
            id => <<"testkey1">>,
            secret => <<"SECRET1">>},
          #{type => <<"plain_text">>,
            id => <<"testkey2">>,
            secret => <<"SECRET2">>}
      ],
  
      {ok, Repos, Keys} = load_keys(KeyCfg, RepoCfg, fun(K) -> mock_load_key(K) end),
  
      {value, #{secret := Secret}} = lists:search(
          fun(#{id := Id}) -> Id =:= <<"test3.domain.org">> end, Keys),
      ?assert(Secret =:= <<"mocksecret">>),
  
      {value, #{keys := KeyIds}} = lists:search(
          fun(#{domain := D}) -> D =:= <<"test3.domain.org">> end, Repos),
      ?assert(KeyIds =:= [#{id => <<"test3.domain.org">>, path => <<"/">>}]).
  
  mock_load_key(#{type := <<"plain_text">>, id := Id, secret := Secret}) ->
      #{id => Id, secret => Secret};
  mock_load_key(#{type := <<"file">>, file_name := FileName}) ->
      [Id | _] = binary:split(lists:last(binary:split(FileName, <<"/">>, [global])), <<".gw">>),
      #{id => Id, secret => <<"mocksecret">>}.
  