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
|
|
|
|
%Livebook.Hubs.Metadata{
|
|
|
|
id: "fly-foo-bar-baz",
|
|
|
|
name: "My Personal Hub",
|
|
|
|
color: "#FF00FF",
|
|
|
|
provider: build(:fly)
|
|
|
|
}
|
|
|
|
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-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-09-17 07:37:01 +08:00
|
|
|
Livebook.Storage.current().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
|