Skip to content

Commit

Permalink
create hex_repo:get_installs/1 function
Browse files Browse the repository at this point in the history
  • Loading branch information
cgerling committed May 3, 2023
1 parent 455556f commit aa4ccde
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/hex_repo.erl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
get_package/2,
get_tarball/3,
get_docs/3,
get_public_key/1
get_public_key/1,
get_installs/1
]).

%%====================================================================
Expand Down Expand Up @@ -144,6 +145,27 @@ get_public_key(Config) ->
Other
end.

%% @doc
%% Gets a CSV with the installs for Hex 1.x.
%%
%% Examples:
%%
%% ```
%% > hex_repo:get_installs(hex_core:default_config())
%% {ok, {200, _, Installs}}
%% '''
get_installs(Config) ->
ReqHeaders = make_headers(Config),
URI = build_url(Config, <<"installs/hex-1.x.csv">>),

case get(Config, URI, ReqHeaders) of
{ok, {200, RespHeaders, Installs}} ->
{ok, {200, RespHeaders, Installs}};

Other ->
Other
end.

%%====================================================================
%% Internal functions
%%====================================================================
Expand Down
7 changes: 7 additions & 0 deletions test/hex_repo_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ all() ->
get_tarball_test,
get_docs_test,
get_public_key_test,
get_installs_test,
repo_org_not_set
].

Expand Down Expand Up @@ -76,6 +77,12 @@ get_public_key_test(_Config) ->
{ok, {403, _, _}} = hex_repo:get_public_key(maps:put(repo_url, <<"https://repo.test/not_found">>, ?CONFIG)),
ok.

get_installs_test(_Config) ->
{ok, {200, #{<<"etag">> := ETag}, _}} = hex_repo:get_installs(?CONFIG),

{ok, {304, _, _}} = hex_repo:get_installs(maps:put(http_etag, ETag, ?CONFIG)),
ok.

repo_org_not_set(_Config) ->
Config = maps:remove(repo_organization, ?CONFIG),
{ok, {200, _, #{repository := <<"hexpm">>, releases := Releases}}} = hex_repo:get_package(Config, <<"ecto">>),
Expand Down
6 changes: 6 additions & 0 deletions test/support/hex_http_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ fixture(get, <<?TEST_REPO_URL, "/public_key">>, _, _) ->
},
{ok, {200, Headers, ?PUBLIC_KEY}};

fixture(get, <<?TEST_REPO_URL, "/installs/hex-1.x.csv">>, _, _) ->
Headers = #{
<<"etag">> => <<"\"dummy\"">>
},
{ok, {200, Headers, <<"installs_csv">>}};

fixture(get, <<?TEST_REPO_URL, _/binary>>, _, _) ->
{ok, {403, #{}, <<"not found">>}};

Expand Down

0 comments on commit aa4ccde

Please sign in to comment.