mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-09-08 14:04:31 +08:00
Remove unused functions
This commit is contained in:
parent
c327111dfd
commit
9e2cf5166a
2 changed files with 31 additions and 166 deletions
|
@ -7,7 +7,7 @@ defmodule LivebookWeb.Integration.SessionLiveTest do
|
|||
@moduletag teams_for: :user
|
||||
setup :teams
|
||||
|
||||
@moduletag subscribe_to_hubs_topics: [:connection]
|
||||
@moduletag subscribe_to_hubs_topics: [:connection, :crud, :secrets]
|
||||
@moduletag subscribe_to_teams_topics: [:clients, :agents, :app_deployments, :app_server]
|
||||
|
||||
alias Livebook.FileSystem
|
||||
|
@ -26,9 +26,7 @@ defmodule LivebookWeb.Integration.SessionLiveTest do
|
|||
end
|
||||
|
||||
describe "hubs" do
|
||||
test "selects the notebook hub", %{conn: conn, user: user, node: node, session: session} do
|
||||
hub = create_team_hub(user, node)
|
||||
id = hub.id
|
||||
test "selects the notebook hub", %{team: %{id: id}, conn: conn, session: session} do
|
||||
personal_id = Livebook.Hubs.Personal.id()
|
||||
|
||||
{:ok, view, _} = live(conn, ~p"/sessions/#{session.id}")
|
||||
|
@ -40,21 +38,12 @@ defmodule LivebookWeb.Integration.SessionLiveTest do
|
|||
|> render_click()
|
||||
|
||||
assert_receive {:operation, {:set_notebook_hub, _, ^id}}
|
||||
assert Session.get_notebook(session.pid).hub_id == hub.id
|
||||
assert Session.get_notebook(session.pid).hub_id == id
|
||||
end
|
||||
|
||||
test "closes all sessions from notebooks that belongs to the org when the org deletes the user",
|
||||
%{conn: conn, user: user, node: node, session: session} do
|
||||
Livebook.Hubs.Broadcasts.subscribe([:connection, :crud, :secrets])
|
||||
Livebook.Teams.Broadcasts.subscribe([:clients])
|
||||
Session.subscribe(session.id)
|
||||
|
||||
hub = create_team_hub(user, node)
|
||||
id = hub.id
|
||||
|
||||
assert_receive {:hub_connected, ^id}
|
||||
assert_receive {:client_connected, ^id}, 10_000
|
||||
|
||||
%{team: team, conn: conn, user: user, node: node, session: session} do
|
||||
id = team.id
|
||||
Session.set_notebook_hub(session.pid, id)
|
||||
|
||||
assert_receive {:operation, {:set_notebook_hub, _, ^id}}
|
||||
|
@ -64,13 +53,13 @@ defmodule LivebookWeb.Integration.SessionLiveTest do
|
|||
assert has_element?(view, ~s/#select-hub-#{id}/)
|
||||
|
||||
# force user to be deleted from org
|
||||
TeamsRPC.delete_user_org(node, user.id, hub.org_id)
|
||||
reason = "#{hub.hub_name}: you were removed from the org"
|
||||
TeamsRPC.delete_user_org(node, user.id, team.org_id)
|
||||
reason = "#{team.hub_name}: you were removed from the org"
|
||||
|
||||
# checks if the hub received the `user_deleted` event and deleted the hub
|
||||
assert_receive {:hub_server_error, ^id, ^reason}
|
||||
assert_receive {:hub_deleted, ^id}
|
||||
refute hub in Livebook.Hubs.get_hubs()
|
||||
refute team in Livebook.Hubs.get_hubs()
|
||||
|
||||
# all sessions that uses the deleted hub must be closed
|
||||
assert_receive :session_closed
|
||||
|
@ -78,9 +67,7 @@ defmodule LivebookWeb.Integration.SessionLiveTest do
|
|||
end
|
||||
|
||||
describe "secrets" do
|
||||
test "creates a new secret", %{conn: conn, user: user, node: node, session: session} do
|
||||
team = create_team_hub(user, node)
|
||||
|
||||
test "creates a new secret", %{team: team, conn: conn, session: session} do
|
||||
# loads the session page
|
||||
{:ok, view, _} = live(conn, ~p"/sessions/#{session.id}")
|
||||
|
||||
|
@ -124,12 +111,7 @@ defmodule LivebookWeb.Integration.SessionLiveTest do
|
|||
end
|
||||
|
||||
test "redirects the user to update or delete a secret",
|
||||
%{conn: conn, user: user, node: node, session: session} do
|
||||
Livebook.Hubs.Broadcasts.subscribe([:secrets, :connection])
|
||||
team = create_team_hub(user, node)
|
||||
id = team.id
|
||||
assert_receive {:hub_connected, ^id}
|
||||
|
||||
%{team: team, conn: conn, session: session} do
|
||||
# creates a secret
|
||||
secret = insert_secret(hub_id: team.id)
|
||||
assert_receive {:secret_created, ^secret}
|
||||
|
@ -142,17 +124,15 @@ defmodule LivebookWeb.Integration.SessionLiveTest do
|
|||
|
||||
# clicks the button to edit a secret
|
||||
view
|
||||
|> element("#hub-#{id}-secret-#{secret.name}-edit-button")
|
||||
|> element("#hub-#{team.id}-secret-#{secret.name}-edit-button")
|
||||
|> render_click()
|
||||
|
||||
# redirects to hub page and loads the modal with
|
||||
# the secret name and value filled
|
||||
assert_redirect(view, ~p"/hub/#{id}/secrets/edit/#{secret.name}")
|
||||
assert_redirect(view, ~p"/hub/#{team.id}/secrets/edit/#{secret.name}")
|
||||
end
|
||||
|
||||
test "toggle a secret from team hub", %{conn: conn, session: session, user: user, node: node} do
|
||||
team = create_team_hub(user, node)
|
||||
|
||||
test "toggle a secret from team hub", %{team: team, conn: conn, session: session} do
|
||||
# loads the session page
|
||||
{:ok, view, _} = live(conn, ~p"/sessions/#{session.id}")
|
||||
|
||||
|
@ -174,9 +154,7 @@ defmodule LivebookWeb.Integration.SessionLiveTest do
|
|||
end
|
||||
|
||||
test "adding a missing secret using 'Add secret' button",
|
||||
%{conn: conn, user: user, node: node, session: session} do
|
||||
team = create_team_hub(user, node)
|
||||
|
||||
%{team: team, conn: conn, session: session} do
|
||||
secret = build(:secret, hub_id: team.id)
|
||||
|
||||
# selects the notebook's hub with team hub id
|
||||
|
@ -223,9 +201,7 @@ defmodule LivebookWeb.Integration.SessionLiveTest do
|
|||
end
|
||||
|
||||
test "granting access for missing secret using 'Add secret' button",
|
||||
%{conn: conn, user: user, node: node, session: session} do
|
||||
team = create_team_hub(user, node)
|
||||
|
||||
%{team: team, conn: conn, session: session} do
|
||||
secret = build(:secret, hub_id: team.id)
|
||||
|
||||
# selects the notebook's hub with team hub id
|
||||
|
@ -283,15 +259,13 @@ defmodule LivebookWeb.Integration.SessionLiveTest do
|
|||
end
|
||||
|
||||
describe "files" do
|
||||
test "shows only hub's file systems",
|
||||
%{conn: conn, user: user, node: node, session: session} do
|
||||
Livebook.Hubs.Broadcasts.subscribe([:file_systems])
|
||||
@describetag subscribe_to_hubs_topics: [:connection, :file_systems]
|
||||
|
||||
test "shows only hub's file systems", %{team: team, conn: conn, session: session} do
|
||||
personal_id = Livebook.Hubs.Personal.id()
|
||||
personal_file_system = build(:fs_s3)
|
||||
Livebook.Hubs.Personal.save_file_system(personal_file_system)
|
||||
|
||||
team = create_team_hub(user, node)
|
||||
team_id = team.id
|
||||
|
||||
bucket_url = "https://my-own-bucket.s3.amazonaws.com"
|
||||
|
@ -332,8 +306,6 @@ defmodule LivebookWeb.Integration.SessionLiveTest do
|
|||
end
|
||||
|
||||
test "shows file system from offline hub", %{conn: conn, session: session} do
|
||||
Livebook.Hubs.Broadcasts.subscribe([:file_systems])
|
||||
|
||||
hub = offline_hub()
|
||||
hub_id = hub.id
|
||||
bucket_url = "https://#{hub.id}-file-system.s3.amazonaws.com"
|
||||
|
@ -369,8 +341,7 @@ defmodule LivebookWeb.Integration.SessionLiveTest do
|
|||
describe "offline deployment with docker" do
|
||||
@tag :tmp_dir
|
||||
test "show deployment group on app deployment",
|
||||
%{conn: conn, user: user, node: node, session: session, tmp_dir: tmp_dir} do
|
||||
team = create_team_hub(user, node)
|
||||
%{team: team, conn: conn, session: session, tmp_dir: tmp_dir} do
|
||||
team_id = team.id
|
||||
|
||||
insert_deployment_group(
|
||||
|
@ -398,8 +369,7 @@ defmodule LivebookWeb.Integration.SessionLiveTest do
|
|||
|
||||
@tag :tmp_dir
|
||||
test "set deployment group on app deployment",
|
||||
%{conn: conn, user: user, node: node, session: session, tmp_dir: tmp_dir} do
|
||||
team = create_team_hub(user, node)
|
||||
%{team: team, conn: conn, session: session, tmp_dir: tmp_dir} do
|
||||
team_id = team.id
|
||||
|
||||
insert_deployment_group(
|
||||
|
@ -442,8 +412,7 @@ defmodule LivebookWeb.Integration.SessionLiveTest do
|
|||
|
||||
@tag :tmp_dir
|
||||
test "show no deployments groups available",
|
||||
%{conn: conn, user: user, node: node, session: session, tmp_dir: tmp_dir} do
|
||||
team = create_team_hub(user, node)
|
||||
%{team: team, conn: conn, session: session, tmp_dir: tmp_dir} do
|
||||
team_id = team.id
|
||||
|
||||
Session.set_notebook_hub(session.pid, team_id)
|
||||
|
@ -466,10 +435,15 @@ defmodule LivebookWeb.Integration.SessionLiveTest do
|
|||
end
|
||||
|
||||
describe "online deployment" do
|
||||
test "shows a message when non-teams hub is selected",
|
||||
%{conn: conn, user: user, node: node, session: session} do
|
||||
create_team_hub(user, node)
|
||||
@moduletag subscribe_to_teams_topics: [
|
||||
:clients,
|
||||
:agents,
|
||||
:app_deployments,
|
||||
:deployment_groups,
|
||||
:app_server
|
||||
]
|
||||
|
||||
test "shows a message when non-teams hub is selected", %{conn: conn, session: session} do
|
||||
{:ok, view, _} = live(conn, ~p"/sessions/#{session.id}")
|
||||
|
||||
view
|
||||
|
@ -481,8 +455,7 @@ defmodule LivebookWeb.Integration.SessionLiveTest do
|
|||
end
|
||||
|
||||
test "deployment flow with no deployment groups in the hub",
|
||||
%{conn: conn, user: user, node: node, session: session} do
|
||||
team = create_team_hub(user, node)
|
||||
%{team: team, conn: conn, session: session} do
|
||||
Session.set_notebook_hub(session.pid, team.id)
|
||||
|
||||
{:ok, view, _} = live(conn, ~p"/sessions/#{session.id}")
|
||||
|
@ -539,9 +512,7 @@ defmodule LivebookWeb.Integration.SessionLiveTest do
|
|||
end
|
||||
|
||||
test "deployment flow with existing deployment groups in the hub",
|
||||
%{conn: conn, user: user, node: node, session: session} do
|
||||
Livebook.Teams.Broadcasts.subscribe([:deployment_groups])
|
||||
team = create_team_hub(user, node)
|
||||
%{team: team, conn: conn, session: session} do
|
||||
Session.set_notebook_hub(session.pid, team.id)
|
||||
|
||||
id = insert_deployment_group(mode: :online, hub_id: team.id).id
|
||||
|
@ -601,9 +572,7 @@ defmodule LivebookWeb.Integration.SessionLiveTest do
|
|||
end
|
||||
|
||||
test "shows an error when the deployment size is higher than the maximum size of 20MB",
|
||||
%{conn: conn, user: user, node: node, session: session} do
|
||||
Livebook.Teams.Broadcasts.subscribe([:deployment_groups])
|
||||
team = create_team_hub(user, node)
|
||||
%{team: team, conn: conn, session: session} do
|
||||
Session.set_notebook_hub(session.pid, team.id)
|
||||
|
||||
slug = Livebook.Utils.random_short_id()
|
||||
|
|
|
@ -22,92 +22,6 @@ defmodule Livebook.HubHelpers do
|
|||
}
|
||||
}
|
||||
|
||||
def create_team_hub(user, node) do
|
||||
hub = build_team_hub(user, node)
|
||||
Livebook.Hubs.save_hub(hub)
|
||||
end
|
||||
|
||||
def create_agent_team_hub(node, opts \\ []) do
|
||||
{agent_key, org, deployment_group, hub} = build_agent_team_hub(node, opts)
|
||||
erpc_call(node, :create_org_key_pair, [[org: org]])
|
||||
^hub = Livebook.Hubs.save_hub(hub)
|
||||
|
||||
{agent_key, org, deployment_group, hub}
|
||||
end
|
||||
|
||||
def build_team_headers(user, node) do
|
||||
hub = build_team_hub(user, node)
|
||||
|
||||
headers = [
|
||||
{"x-user", to_string(hub.user_id)},
|
||||
{"x-org", to_string(hub.org_id)},
|
||||
{"x-org-key", to_string(hub.org_key_id)},
|
||||
{"x-session-token", hub.session_token}
|
||||
]
|
||||
|
||||
{hub, headers}
|
||||
end
|
||||
|
||||
def build_team_hub(user, node) do
|
||||
teams_org = build(:org)
|
||||
teams_key = teams_org.teams_key
|
||||
key_hash = Livebook.Teams.Org.key_hash(teams_org)
|
||||
|
||||
org = erpc_call(node, :create_org, [])
|
||||
org_key = erpc_call(node, :create_org_key, [[org: org, key_hash: key_hash]])
|
||||
org_key_pair = erpc_call(node, :create_org_key_pair, [[org: org]])
|
||||
token = erpc_call(node, :associate_user_with_org, [user, org])
|
||||
erpc_call(node, :create_billing_subscription, [org])
|
||||
|
||||
build(:team,
|
||||
id: "team-#{org.name}",
|
||||
hub_name: org.name,
|
||||
user_id: user.id,
|
||||
org_id: org.id,
|
||||
org_key_id: org_key.id,
|
||||
org_public_key: org_key_pair.public_key,
|
||||
session_token: token,
|
||||
teams_key: teams_key,
|
||||
billing_status: %{disabled: false, type: nil}
|
||||
)
|
||||
end
|
||||
|
||||
def build_agent_team_hub(node, opts \\ []) do
|
||||
teams_org = build(:org)
|
||||
teams_key = teams_org.teams_key
|
||||
key_hash = Livebook.Teams.Org.key_hash(teams_org)
|
||||
|
||||
org = erpc_call(node, :create_org, [])
|
||||
org_key = erpc_call(node, :create_org_key, [[org: org, key_hash: key_hash]])
|
||||
|
||||
deployment_group_attrs =
|
||||
opts
|
||||
|> Keyword.get(:deployment_group, [])
|
||||
|> Keyword.merge(
|
||||
name: "sleepy-cat-#{Ecto.UUID.generate()}",
|
||||
mode: :online,
|
||||
org: org
|
||||
)
|
||||
|
||||
deployment_group = erpc_call(node, :create_deployment_group, [deployment_group_attrs])
|
||||
|
||||
agent_key = erpc_call(node, :create_agent_key, [[deployment_group: deployment_group]])
|
||||
|
||||
team =
|
||||
build(:team,
|
||||
id: "team-#{org.name}",
|
||||
hub_name: org.name,
|
||||
user_id: nil,
|
||||
org_id: org.id,
|
||||
org_key_id: org_key.id,
|
||||
org_public_key: nil,
|
||||
session_token: agent_key.key,
|
||||
teams_key: teams_key
|
||||
)
|
||||
|
||||
{agent_key, org, deployment_group, team}
|
||||
end
|
||||
|
||||
def build_offline_team_hub(user, node) do
|
||||
teams_org = build(:org, teams_key: @offline_hub_key, name: @offline_hub_org_name)
|
||||
key_hash = Livebook.Teams.Org.key_hash(teams_org)
|
||||
|
@ -285,24 +199,6 @@ defmodule Livebook.HubHelpers do
|
|||
assert_receive {:agent_joined, ^agent}
|
||||
end
|
||||
|
||||
@doc """
|
||||
Creates a new Team hub from given user and node, and await the WebSocket to be connected.
|
||||
|
||||
test "my test", %{user: user, node: node} do
|
||||
team = connect_to_teams(user, node)
|
||||
assert "team-" <> _ = team.id
|
||||
end
|
||||
|
||||
"""
|
||||
@spec connect_to_teams(struct(), node()) :: Livebook.Hubs.Team.t()
|
||||
def connect_to_teams(user, node) do
|
||||
%{id: id} = team = create_team_hub(user, node)
|
||||
assert_receive {:hub_connected, ^id}, 3_000
|
||||
assert_receive {:client_connected, ^id}, 3_000
|
||||
|
||||
team
|
||||
end
|
||||
|
||||
defp hub_pid(hub) do
|
||||
if pid = Livebook.Hubs.TeamClient.get_pid(hub.id) do
|
||||
{:ok, pid}
|
||||
|
|
Loading…
Add table
Reference in a new issue