Skip to content

Commit

Permalink
Add test case for size profile assignment on bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
zacksiri committed Jul 17, 2024
1 parent dfe6023 commit 27b496d
Show file tree
Hide file tree
Showing 3 changed files with 429 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/fixtures/lxd/profiles/not_found.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "error",
"status": "",
"status_code": 0,
"operation": "",
"error_code": 404,
"error": "Profile not found",
"metadata": null
}
114 changes: 114 additions & 0 deletions test/scenarios/deployment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,70 @@ defmodule Uplink.Scenarios.Deployment do
}
}

@deployment_params_with_package_size %{
"hash" => "some-hash-with-package-size",
"archive_url" => "http://localhost/archives/packages.zip",
"stack" => "alpine/3.14",
"channel" => "develop",
"metadata" => %{
"id" => 1,
"slug" => "uplink-web",
"package_size" => %{
"slug" => "medium",
"allocation" => %{
"cpu" => 1,
"cpu_allowance" => "100%",
"cpu_priority" => 10,
"memory" => 1,
"memory_unit" => "GiB",
"memory_swap" => false,
"memory_enforce" => "hard"
}
},
"main_port" => %{
"slug" => "web",
"source" => 49152,
"target" => 4000,
"routing" => %{
"router_id" => 1,
"paths" => ["/configure*"]
}
},
"ports" => [
%{
"slug" => "grpc",
"source" => 49153,
"target" => 6000
}
],
"hosts" => ["something.com"],
"variables" => [
%{"key" => "SOMETHING", "value" => "blah"}
],
"channel" => %{
"slug" => "develop",
"package" => %{
"slug" => "something-1640927800",
"credential" => %{
"public_key" => "public_key"
},
"organization" => %{
"slug" => "upmaru"
}
}
},
"instances" => [
%{
"id" => 1,
"slug" => "something-1",
"node" => %{
"slug" => "some-node"
}
}
]
}
}

def setup_endpoints(_context) do
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Uplink.Repo)

Expand Down Expand Up @@ -157,4 +221,54 @@ defmodule Uplink.Scenarios.Deployment do
deployment: deployment,
install: executing_install}
end

def setup_base_with_package_size(_context) do
{:ok, actor} =
Members.get_or_create_actor(%{
"identifier" => "zacksiri",
"provider" => "instellar",
"id" => "1"
})

metadata = Map.get(@deployment_params_with_package_size, "metadata")

{:ok, metadata} = Packages.parse_metadata(metadata)

app =
metadata
|> Metadata.app_slug()
|> Packages.get_or_create_app()

{:ok, deployment} =
Packages.get_or_create_deployment(
app,
@deployment_params_with_package_size
)

{:ok, install} =
Packages.create_install(deployment, %{
"installation_id" => 1,
"deployment" => @deployment_params_with_package_size
})

signature = Secret.Signature.compute_signature(deployment.hash)

Cache.put(
{:deployment, signature, install.instellar_installation_id},
metadata
)

{:ok, %{resource: validating_install}} =
Packages.transition_install_with(install, actor, "validate")

{:ok, %{resource: executing_install}} =
Packages.transition_install_with(validating_install, actor, "execute")

{:ok,
actor: actor,
metadata: metadata,
app: app,
deployment: deployment,
install: executing_install}
end
end
Loading

0 comments on commit 27b496d

Please sign in to comment.