Commit 4a6d1e92 authored by Guilherme Andrade's avatar Guilherme Andrade

Add test coverage of HTTP loads of newly supported file formats

parent 83e2fb0f
......@@ -54,16 +54,19 @@ all() ->
[{group, GroupName} || {GroupName, _Options, _TestCases} <- groups()].
groups() ->
LocalTests =
[{filesystem_tests, [], test_cases("_fstest")},
{'local_http_tests_tar.gz', [], test_cases("_httptest")},
{local_http_tests_tgz, [], test_cases("_httptest")},
{local_http_tests_tar, [], test_cases("_httptest")},
{local_http_tests_mmdb, [], test_cases("_httptest")},
{'local_http_tests_mmdb.gz', [], test_cases("_httptest")}
],
case should_run_remote_http_tests() of
false ->
[{filesystem_tests, [], test_cases("_fstest")},
{local_http_tests, [], test_cases("_httptest")}
];
false -> LocalTests;
true ->
[{filesystem_tests, [], test_cases("_fstest")},
{local_http_tests, [], test_cases("_httptest")},
{remote_http_tests, [], test_cases("_httptest")}
]
LocalTests ++ [{remote_http_tests, [], test_cases("_httptest")}]
end.
-ifdef(RUNNING_ON_CI).
......@@ -94,68 +97,74 @@ exported_functions() ->
Exports.
%%%%%%%%%%%%%%%
init_per_group(filesystem_tests, Config) ->
{ok, _} = application:ensure_all_started(locus),
ok = locus_logger:set_loglevel(debug),
BaseURL = ?PATH_WITH_TEST_TARBALLS,
DatabasePath = filename:join(?PATH_WITH_TEST_TARBALLS, "GeoLite2-Country.tar.gz"),
CorruptPath = filename:join(?PATH_WITH_TEST_TARBALLS, "corruption.tar.gz"),
[{is_http, false},
{url, DatabasePath},
{path, DatabasePath},
{corrupt_url, CorruptPath},
{base_url, BaseURL}
| Config];
init_per_group(local_http_tests, Config) ->
{ok, _} = application:ensure_all_started(locus),
ok = locus_logger:set_loglevel(debug),
{ok, HttpdPid, BaseURL} = locus_httpd:start(?PATH_WITH_TEST_TARBALLS),
DatabasePath = filename:join(?PATH_WITH_TEST_TARBALLS, "GeoLite2-Country.tar.gz"),
RandomAnchor = integer_to_list(rand:uniform(1 bsl 64), 36),
DatabaseURL = BaseURL ++ "/GeoLite2-Country.tar.gz" ++ "#" ++ RandomAnchor,
CorruptURL = BaseURL ++ "/corruption.tar.gz",
ok = set_file_mtime(DatabasePath, ?VERSION1_TIMESTAMP),
[{is_http, true},
{is_remote, false},
{httpd_pid, HttpdPid},
{url, DatabaseURL},
{path, DatabasePath},
{corrupt_url, CorruptURL},
{base_url, BaseURL}
| Config];
init_per_group(remote_http_tests, Config) ->
{ok, _} = application:ensure_all_started(locus),
ok = locus_logger:set_loglevel(debug),
RandomAnchor = integer_to_list(rand:uniform(1 bsl 64), 36),
URL = ?REMOTE_COUNTRY_URL ++ "#" ++ RandomAnchor,
CorruptURL = ?REMOTE_COUNTRY_CORRUPT_URL,
BaseURL = ?REMOTE_COUNTRY_BASE_URL,
[{is_http, true},
{is_remote, true},
{url, URL},
{base_url, BaseURL},
{corrupt_url, CorruptURL}
| Config].
end_per_group(filesystem_tests, Config) ->
ok = application:stop(locus),
Config;
end_per_group(local_http_tests, Config) ->
URL = proplists:get_value(url, Config),
CacheFilename = locus_loader:cached_database_path_for_url(URL),
HttpdPid = proplists:get_value(httpd_pid, Config),
ok = application:stop(locus),
ok = locus_httpd:stop(HttpdPid),
_ = file:delete(CacheFilename),
Config;
end_per_group(remote_http_tests, Config) ->
URL = proplists:get_value(url, Config),
CacheFilename = locus_loader:cached_database_path_for_url(URL),
init_per_group(GroupName, Config) ->
case atom_to_list(GroupName) of
"filesystem_tests" ->
{ok, _} = application:ensure_all_started(locus),
ok = locus_logger:set_loglevel(debug),
BaseURL = ?PATH_WITH_TEST_TARBALLS,
DatabasePath = filename:join(?PATH_WITH_TEST_TARBALLS, "GeoLite2-Country.tar.gz"),
CorruptPath = filename:join(?PATH_WITH_TEST_TARBALLS, "corruption.tar.gz"),
[{is_http, false},
{url, DatabasePath},
{path, DatabasePath},
{corrupt_url, CorruptPath},
{base_url, BaseURL}
| Config];
"local_http_tests_" ++ FileExtension ->
{ok, _} = application:ensure_all_started(locus),
ok = locus_logger:set_loglevel(debug),
{ok, HttpdPid, BaseURL} = locus_httpd:start(?PATH_WITH_TEST_TARBALLS),
DatabasePath = filename:join(?PATH_WITH_TEST_TARBALLS, "GeoLite2-Country." ++ FileExtension),
RandomAnchor = integer_to_list(rand:uniform(1 bsl 64), 36),
DatabaseURL = BaseURL ++ "/GeoLite2-Country." ++ FileExtension ++ "#" ++ RandomAnchor,
CorruptURL = BaseURL ++ "/corruption." ++ FileExtension,
ok = set_file_mtime(DatabasePath, ?VERSION1_TIMESTAMP),
[{is_http, true},
{is_remote, false},
{httpd_pid, HttpdPid},
{url, DatabaseURL},
{path, DatabasePath},
{corrupt_url, CorruptURL},
{base_url, BaseURL}
| Config];
"remote_http_tests" ->
{ok, _} = application:ensure_all_started(locus),
ok = locus_logger:set_loglevel(debug),
RandomAnchor = integer_to_list(rand:uniform(1 bsl 64), 36),
URL = ?REMOTE_COUNTRY_URL ++ "#" ++ RandomAnchor,
CorruptURL = ?REMOTE_COUNTRY_CORRUPT_URL,
BaseURL = ?REMOTE_COUNTRY_BASE_URL,
[{is_http, true},
{is_remote, true},
{url, URL},
{base_url, BaseURL},
{corrupt_url, CorruptURL}
| Config]
end.
ok = application:stop(locus),
_ = file:delete(CacheFilename),
Config.
end_per_group(GroupName, Config) ->
case atom_to_list(GroupName) of
"filesystem_tests" ->
ok = application:stop(locus),
Config;
"local_http_tests_" ++ _FileExtension ->
URL = proplists:get_value(url, Config),
CacheFilename = locus_loader:cached_database_path_for_url(URL),
HttpdPid = proplists:get_value(httpd_pid, Config),
ok = application:stop(locus),
ok = locus_httpd:stop(HttpdPid),
_ = file:delete(CacheFilename),
Config;
"remote_http_tests" ->
URL = proplists:get_value(url, Config),
CacheFilename = locus_loader:cached_database_path_for_url(URL),
ok = application:stop(locus),
_ = file:delete(CacheFilename),
Config
end.
%% ------------------------------------------------------------------
%% Filesystem Test Cases
......
GeoLite2-Country_20180206/GeoLite2-Country.mmdb
\ No newline at end of file
GeoLite2-Country_20180206/GeoLite2-Country.mmdb.gz
\ No newline at end of file
GeoLite2-Country.tar.gz
\ No newline at end of file
Database and Contents Copyright (c) 2018 MaxMind, Inc.
This work is licensed under the Creative Commons Attribution-ShareAlike 4.0 International License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/4.0/.
This database incorporates GeoNames [http://www.geonames.org] geographical data, which is made available under the Creative Commons Attribution 3.0 License. To view a copy of this license, visit http://www.creativecommons.org/licenses/by/3.0/us/.
corruption.tar.gz
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment