Skip to content

Commit

Permalink
add test verifying client works
Browse files Browse the repository at this point in the history
  • Loading branch information
jarlah committed Oct 11, 2023
1 parent 1224769 commit a8f9ba4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
3 changes: 2 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
# General application configuration
import Config

config :docker_engine_api, base_url: "http://localhost/v1.43"
config :tesla, DockerEngineAPI.Connection,
adapter: Tesla.Adapter.Hackney

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
Expand Down
17 changes: 14 additions & 3 deletions lib/docker_engine_api/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ defmodule DockerEngineAPI.Connection do
"""
@spec new() :: Tesla.Env.client()
def new do
Tesla.client(middleware(), Tesla.Adapter.Hackney)
Tesla.client(middleware(), adapter())
end

@doc """
Expand All @@ -67,7 +67,7 @@ defmodule DockerEngineAPI.Connection do
def new(options) when is_list(options) do
options
|> middleware()
|> Tesla.client(Tesla.Adapter.Hackney)
|> Tesla.client(adapter())
end


Expand All @@ -85,7 +85,7 @@ defmodule DockerEngineAPI.Connection do
Application.get_env(:docker_engine_api, :base_url, @default_base_url)
)

tesla_options = Application.get_env(:tesla, __MODULE__, [])
tesla_options = get_tesla_options()
middleware = Keyword.get(tesla_options, :middleware, [])
json_engine = Keyword.get(tesla_options, :json, Jason)

Expand All @@ -109,4 +109,15 @@ defmodule DockerEngineAPI.Connection do
| middleware
]
end


def get_tesla_options, do: Application.get_env(:tesla, __MODULE__, [])

@doc """
Returns the default adapter for this API.
"""
def adapter do
get_tesla_options()
|> Keyword.get(:adapter, nil)
end
end
11 changes: 11 additions & 0 deletions test/connection_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
defmodule DockerEngineAPI.ConnectionTest do
use ExUnit.Case

test "can list images" do
{:ok, list} = DockerEngineAPI.Connection.new(
base_url: "http+unix://%2Fvar%2Frun%2Fdocker.sock/v1.43"
)
|> DockerEngineAPI.Api.Image.image_list()
assert is_list(list)
end
end

0 comments on commit a8f9ba4

Please sign in to comment.