-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cluster controller to publish namespace
- Loading branch information
Showing
9 changed files
with
111 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
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
Empty file.
Empty file.
11 changes: 11 additions & 0 deletions
11
lib/polar_web/controllers/publish/testing/cluster_controller.ex
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,11 @@ | ||
defmodule PolarWeb.Publish.Testing.ClusterController do | ||
use PolarWeb, :controller | ||
|
||
alias Polar.Machines | ||
|
||
def index(conn, _params) do | ||
clusters = Machines.list_clusters(:for_testing) | ||
|
||
render(conn, :index, %{clusters: clusters}) | ||
end | ||
end |
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,17 @@ | ||
defmodule PolarWeb.Publish.Testing.ClusterJSON do | ||
alias Polar.Machines.Cluster | ||
|
||
def index(%{clusters: clusters}) do | ||
%{ | ||
data: Enum.map(clusters, &data/1) | ||
} | ||
end | ||
|
||
def data(%Cluster{} = cluster) do | ||
%{ | ||
id: cluster.id, | ||
credential: cluster.credential, | ||
current_state: cluster.current_state | ||
} | ||
end | ||
end |
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
67 changes: 67 additions & 0 deletions
67
test/polar_web/controllers/publish/testing/cluster_controller_test.exs
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,67 @@ | ||
defmodule PolarWeb.Publish.Testing.ClusterControllerTest do | ||
use PolarWeb.ConnCase | ||
|
||
alias Polar.Accounts | ||
alias Polar.Machines | ||
|
||
import Polar.AccountsFixtures | ||
|
||
setup do | ||
password = Accounts.generate_automation_password() | ||
|
||
bot = bot_fixture(%{password: password}) | ||
|
||
user = Accounts.get_user_by_email_and_password(bot.email, password) | ||
|
||
session_token = | ||
Accounts.generate_user_session_token(user) | ||
|> Base.encode64() | ||
|
||
conn = | ||
build_conn() | ||
|> put_req_header("authorization", session_token) | ||
|
||
{:ok, cluster} = | ||
Machines.create_cluster(%{ | ||
name: "example", | ||
type: "lxd", | ||
arch: "amd64", | ||
credential_endpoint: "some.cluster.com:8443", | ||
credential_password: "sometoken", | ||
credential_password_confirmation: "sometoken" | ||
}) | ||
|
||
{:ok, _created_cluster} = | ||
Machines.create_cluster(%{ | ||
name: "example2", | ||
type: "lxd", | ||
arch: "amd64", | ||
credential_endpoint: "some.cluster.com:8443", | ||
credential_password: "sometoken", | ||
credential_password_confirmation: "sometoken" | ||
}) | ||
|
||
{:ok, conn: conn, cluster: cluster, user: user} | ||
end | ||
|
||
describe "GET /publish/testing/clusters" do | ||
setup %{cluster: cluster, user: user} do | ||
{:ok, %{resource: connecting_cluster}} = | ||
Eventful.Transit.perform(cluster, user, "connect") | ||
|
||
{:ok, %{resource: _healthy_cluster}} = | ||
Eventful.Transit.perform(connecting_cluster, user, "healthy") | ||
|
||
{:ok, cluster: cluster} | ||
end | ||
|
||
test "list healthy clusters", %{conn: conn, cluster: cluster} do | ||
conn = | ||
get(conn, "/publish/testing/clusters") | ||
|
||
assert %{"data" => data} = json_response(conn, 200) | ||
|
||
assert cluster.id in Enum.map(data, & &1["id"]) | ||
end | ||
end | ||
end |