-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from upmaru/feature/ops-639-use-balancer-addre…
…ss-if-exists Add test for LXD client creation
- Loading branch information
Showing
2 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
defmodule Uplink.Clients.LXDTest do | ||
use ExUnit.Case | ||
|
||
alias Uplink.Cache | ||
|
||
alias Uplink.Clients.LXD | ||
|
||
describe "balancer is nil" do | ||
setup do | ||
Cache.put(:self, %{ | ||
"balancer" => nil, | ||
"credential" => %{ | ||
"endpoint" => "http://localhost:8443" | ||
} | ||
}) | ||
end | ||
|
||
test "use credential endpoint" do | ||
assert %Tesla.Client{pre: pre} = LXD.client() | ||
|
||
{_, _, [base_url]} = | ||
Enum.find(pre, fn {middleware, _, _} -> | ||
middleware == Tesla.Middleware.BaseUrl | ||
end) | ||
|
||
assert base_url == "http://localhost:8443" | ||
end | ||
end | ||
|
||
describe "client without balancer" do | ||
setup do | ||
Cache.put(:self, %{ | ||
"credential" => %{ | ||
"endpoint" => "http://localhost:8443" | ||
} | ||
}) | ||
end | ||
|
||
test "use credential endpoint" do | ||
assert %Tesla.Client{pre: pre} = LXD.client() | ||
|
||
{_, _, [base_url]} = | ||
Enum.find(pre, fn {middleware, _, _} -> | ||
middleware == Tesla.Middleware.BaseUrl | ||
end) | ||
|
||
assert base_url == "http://localhost:8443" | ||
end | ||
end | ||
|
||
describe "client with blaancer" do | ||
setup do | ||
Cache.put(:self, %{ | ||
"balancer" => %{ | ||
"address" => "some.address.com", | ||
"current_state" => "active" | ||
}, | ||
"credential" => %{ | ||
"endpoint" => "http://localhost:8443" | ||
} | ||
}) | ||
end | ||
|
||
test "use balancer address" do | ||
assert %Tesla.Client{pre: pre} = LXD.client() | ||
|
||
{_, _, [base_url]} = | ||
Enum.find(pre, fn {middleware, _, _} -> | ||
middleware == Tesla.Middleware.BaseUrl | ||
end) | ||
|
||
assert base_url == "http://some.address.com:8443" | ||
end | ||
end | ||
end |