-
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.
- Loading branch information
Showing
1 changed file
with
64 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,73 @@ | ||
defmodule Uplink.Packages.Instance.PlacementTest do | ||
use ExUnit.Case | ||
|
||
import Uplink.Scenarios.Deployment | ||
|
||
alias Uplink.Packages.Instance.Placement | ||
|
||
setup [:setup_endpoints, :setup_base] | ||
|
||
test "name" do | ||
assert Placement.name("instellar-0e43123-01") == "instellar-0e43123" | ||
end | ||
|
||
describe "spread placement" do | ||
setup do | ||
node_name = "instellar-0e43123-01" | ||
|
||
existing_instances = | ||
File.read!("test/fixtures/lxd/instances/list/existing.json") | ||
|
||
cluster_members = | ||
File.read!("test/fixtures/lxd/cluster/members/list.json") | ||
|
||
{:ok, | ||
existing_instances: existing_instances, | ||
cluster_members: cluster_members, | ||
node_name: node_name} | ||
end | ||
|
||
test "calls lxd api when availability is nil", %{ | ||
bypass: bypass, | ||
existing_instances: existing_instances, | ||
node_name: node_name | ||
} do | ||
Bypass.expect_once(bypass, "GET", "/1.0/instances", fn conn -> | ||
assert %{"recursion" => "1", "all-projects" => _} = conn.query_params | ||
|
||
conn | ||
|> Plug.Conn.put_resp_header("content-type", "application/json") | ||
|> Plug.Conn.resp(200, existing_instances) | ||
end) | ||
|
||
assert {:ok, %Placement{}} = Placement.find(node_name, "spread") | ||
end | ||
|
||
test "fallback to auto when no availability", %{ | ||
bypass: bypass, | ||
existing_instances: existing_instances, | ||
cluster_members: cluster_members, | ||
node_name: node_name | ||
} do | ||
placement_name = Placement.name(node_name) | ||
|
||
Uplink.Cache.put({:available_nodes, placement_name}, []) | ||
|
||
Bypass.expect_once(bypass, "GET", "/1.0/instances", fn conn -> | ||
assert %{"recursion" => "1", "all-projects" => _} = conn.query_params | ||
|
||
conn | ||
|> Plug.Conn.put_resp_header("content-type", "application/json") | ||
|> Plug.Conn.resp(200, existing_instances) | ||
end) | ||
|
||
Bypass.expect_once(bypass, "GET", "/1.0/cluster/members", fn conn -> | ||
conn | ||
|> Plug.Conn.put_resp_header("content-type", "application/json") | ||
|> Plug.Conn.resp(200, cluster_members) | ||
end) | ||
|
||
assert {:ok, %Placement{}} = Placement.find(node_name, "spread") | ||
end | ||
end | ||
end |