Skip to content

Commit 8420c40

Browse files
starbellywojtekmach
authored andcommitted
Default to undefined repo_organization when key does not exist (#66)
1 parent 46b4a44 commit 8420c40

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/hex_repo.erl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ tarball_url(Config, Name, Version) ->
159159
build_url(#{repo_url := URI, repo_organization := Org}, Path) when is_binary(Org) ->
160160
<<URI/binary, "/repos/", Org/binary, "/", Path/binary>>;
161161
build_url(#{repo_url := URI, repo_organization := undefined}, Path) ->
162-
<<URI/binary, "/", Path/binary>>.
162+
<<URI/binary, "/", Path/binary>>;
163+
build_url(Config, Path) ->
164+
build_url(Config#{repo_organization => undefined}, Path).
163165

164166
tarball_filename(Name, Version) ->
165167
<<Name/binary, "-", Version/binary, ".tar">>.

test/hex_repo_SUITE.erl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ suite() ->
1717
[{require, {ssl_certs, test_pub}}].
1818

1919
all() ->
20-
[get_names_test, get_versions_test, get_package_test, get_tarball_test].
20+
[get_names_test, get_versions_test, get_package_test, get_tarball_test, repo_org_not_set].
2121

2222
get_names_test(_Config) ->
2323
{ok, {200, _, Packages}} = hex_repo:get_names(?CONFIG),
@@ -47,3 +47,12 @@ get_tarball_test(_Config) ->
4747

4848
{ok, {403, _, _}} = hex_repo:get_tarball(?CONFIG, <<"ecto">>, <<"9.9.9">>),
4949
ok.
50+
51+
repo_org_not_set(_Config) ->
52+
Config = maps:remove(repo_organization, ?CONFIG),
53+
{ok, {200, _, Releases}} = hex_repo:get_package(Config, <<"ecto">>),
54+
[#{version := <<"1.0.0">>}] =
55+
lists:filter(fun(#{version := Version}) -> Version == <<"1.0.0">> end, Releases),
56+
57+
{ok, {403, _, _}} = hex_repo:get_package(Config, <<"nonexisting">>),
58+
ok.

0 commit comments

Comments
 (0)