Geolix v1.1.0 Geolix.Adapter.Fake View Source
Fake adapter for testing environments.
Usage
This adapter is intended to be used only with static data you can provide when the adapter is started, i.e. when performing unit tests.
iex> Geolix.load_database(%{
...> id: :fake_sample,
...> adapter: Geolix.Adapter.Fake,
...> data: %{
...> {127, 0, 0, 1} => "IPv4",
...> {0, 0, 0, 0, 0, 0, 0, 1} => "IPv6"
...> }
...> })
:ok
iex> Geolix.lookup("127.0.0.1", where: :fake_sample)
"IPv4"
iex> Geolix.lookup("::1", where: :fake_sample)
"IPv6"
iex> Geolix.lookup("255.255.255.255", where: :fake_sample)
nil
The lookup is done by exactly matching the IP address tuple received and will return the predefined result as is.
Metadata
The adapter provides access to the time the database was loaded:
metadata = %{load_epoch: System.os_time(:second)}