2022-08-23 05:12:54 +08:00
|
|
|
defmodule Livebook.Factory do
|
|
|
|
@moduledoc false
|
|
|
|
|
|
|
|
def build(:user) do
|
|
|
|
%Livebook.Users.User{
|
|
|
|
id: Livebook.Utils.random_id(),
|
|
|
|
name: "Jose Valim",
|
|
|
|
hex_color: Livebook.EctoTypes.HexColor.random()
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def build(:fly_metadata) do
|
2022-11-29 07:47:25 +08:00
|
|
|
:fly |> build() |> Livebook.Hubs.Provider.normalize()
|
2022-08-23 05:12:54 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def build(:fly) do
|
|
|
|
%Livebook.Hubs.Fly{
|
|
|
|
id: "fly-foo-bar-baz",
|
|
|
|
hub_name: "My Personal Hub",
|
|
|
|
hub_color: "#FF00FF",
|
|
|
|
access_token: Livebook.Utils.random_cookie(),
|
|
|
|
organization_id: Livebook.Utils.random_id(),
|
|
|
|
organization_type: "PERSONAL",
|
|
|
|
organization_name: "Foo",
|
|
|
|
application_id: "foo-bar-baz"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2022-10-11 22:27:27 +08:00
|
|
|
def build(:enterprise_metadata) do
|
2022-11-29 07:47:25 +08:00
|
|
|
:enterprise |> build() |> Livebook.Hubs.Provider.normalize()
|
2022-10-11 22:27:27 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def build(:enterprise) do
|
2023-01-07 03:14:44 +08:00
|
|
|
id = Livebook.Utils.random_id()
|
2022-10-11 22:27:27 +08:00
|
|
|
|
|
|
|
%Livebook.Hubs.Enterprise{
|
|
|
|
id: "enterprise-#{id}",
|
|
|
|
hub_name: "Enterprise",
|
|
|
|
hub_color: "#FF0000",
|
|
|
|
external_id: id,
|
|
|
|
token: Livebook.Utils.random_cookie(),
|
|
|
|
url: "http://localhost"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2022-09-12 22:34:39 +08:00
|
|
|
def build(:env_var) do
|
|
|
|
%Livebook.Settings.EnvVar{
|
2022-09-17 07:37:01 +08:00
|
|
|
name: "BAR",
|
2022-09-12 22:34:39 +08:00
|
|
|
value: "foo"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2022-08-23 05:12:54 +08:00
|
|
|
def build(factory_name, attrs \\ %{}) do
|
|
|
|
factory_name |> build() |> struct!(attrs)
|
|
|
|
end
|
|
|
|
|
2022-09-12 22:34:39 +08:00
|
|
|
def params_for(factory_name, attrs \\ %{}) do
|
|
|
|
factory_name |> build() |> struct!(attrs) |> Map.from_struct()
|
|
|
|
end
|
|
|
|
|
2022-08-23 05:12:54 +08:00
|
|
|
def insert_hub(factory_name, attrs \\ %{}) do
|
|
|
|
factory_name
|
|
|
|
|> build(attrs)
|
|
|
|
|> Livebook.Hubs.save_hub()
|
|
|
|
end
|
2022-09-12 22:34:39 +08:00
|
|
|
|
|
|
|
def insert_env_var(factory_name, attrs \\ %{}) do
|
|
|
|
env_var = build(factory_name, attrs)
|
|
|
|
attributes = env_var |> Map.from_struct() |> Map.to_list()
|
2022-10-07 01:53:37 +08:00
|
|
|
Livebook.Storage.insert(:env_vars, env_var.name, attributes)
|
2022-09-12 22:34:39 +08:00
|
|
|
|
|
|
|
env_var
|
|
|
|
end
|
2022-08-23 05:12:54 +08:00
|
|
|
end
|