Skip to content

Commit

Permalink
Apply mix format
Browse files Browse the repository at this point in the history
  • Loading branch information
arbulu89 committed Mar 29, 2022
1 parent e081c6e commit 432620a
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 134 deletions.
1 change: 1 addition & 0 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ config :trento, Trento.Scheduler,
]

config :trento, Trento.Integration.Telemetry, adapter: Trento.Integration.Telemetry.ToLogger

config :trento, Trento.Integration.Checks,
adapter: Trento.Integration.Checks.MockRunner,
runner_url: ""
Expand Down
3 changes: 1 addition & 2 deletions config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ config :trento, TrentoWeb.Endpoint,
cache_static_manifest: "priv/static/cache_manifest.json",
server: true

config :trento, Trento.Integration.Checks,
runner_url: System.get_env("RUNNER_URL")
config :trento, Trento.Integration.Checks, runner_url: System.get_env("RUNNER_URL")

# Do not print debug messages in production
# config :logger, level: :info
3 changes: 1 addition & 2 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ if config_env() == :prod do
For example: http://localhost:8080
"""

config :trento, Trento.Integration.Checks,
runner_url: runner_url
config :trento, Trento.Integration.Checks, runner_url: runner_url

# ## Using releases
#
Expand Down
13 changes: 7 additions & 6 deletions lib/trento/application/integration/checks/checks.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
defmodule Trento.Integration.Checks do

alias Trento.Integration.Checks.Models.Catalog

@moduledoc """
Expand All @@ -16,6 +15,7 @@ defmodule Trento.Integration.Checks do
case is_catalog_ready(runner_url()) do
:ok ->
get_catalog_content(runner_url())

{:error, reason} ->
{:error, reason}
end
Expand Down Expand Up @@ -49,12 +49,14 @@ defmodule Trento.Integration.Checks do

defp handle_catalog_ready(%{"ready" => true}), do: :ok

defp handle_catalog_ready(%{"ready" => false}), do: {:error, "The catalog is still being built."}
defp handle_catalog_ready(%{"ready" => false}),
do: {:error, "The catalog is still being built."}

defp normalize_catalog(catalog_raw) do
normalized_catalog = catalog_raw
|> Enum.group_by(&Map.take(&1, ["provider"]), &Map.drop(&1, ["provider"]))
|> Enum.map(fn {key, value} -> Map.put(key, "groups", group_by_groups(value)) end)
normalized_catalog =
catalog_raw
|> Enum.group_by(&Map.take(&1, ["provider"]), &Map.drop(&1, ["provider"]))
|> Enum.map(fn {key, value} -> Map.put(key, "groups", group_by_groups(value)) end)

Catalog.new(%{providers: normalized_catalog})
end
Expand All @@ -70,5 +72,4 @@ defmodule Trento.Integration.Checks do

defp runner_url,
do: Application.fetch_env!(:trento, __MODULE__)[:runner_url]

end
2 changes: 1 addition & 1 deletion lib/trento/application/integration/checks/models/group.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ defmodule Trento.Integration.Checks.Models.Group do
deftype do
field :group, :string

embeds_many :checks, Check
embeds_many :checks, Check
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ defmodule Trento.Integration.Checks.Models.Provider do
deftype do
field :provider, Ecto.Enum, values: [:azure, :aws, :gcp, :dev, :unknown]

embeds_many :groups, Group
embeds_many :groups, Group
end
end
2 changes: 1 addition & 1 deletion lib/trento_web/controllers/catalog_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ defmodule TrentoWeb.CatalogController do
conn
|> put_status(:bad_request)
|> json(%{error: reason})
end
end
end
end
4 changes: 1 addition & 3 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ Application.put_env(:trento, Trento.Integration.Telemetry,
adapter: Trento.Integration.Telemetry.Mock
)

Application.put_env(:trento, Trento.Integration.Checks,
adapter: Trento.Integration.Checks.Mock
)
Application.put_env(:trento, Trento.Integration.Checks, adapter: Trento.Integration.Checks.Mock)

ExUnit.start()
Ecto.Adapters.SQL.Sandbox.mode(Trento.Repo, :manual)
Expand Down
236 changes: 118 additions & 118 deletions test/trento/application/integration/checks/checks_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule Trento.Integration.ChecksTest do
import Mox

alias Trento.Integration.Checks

alias Trento.Integration.Checks.Models.{
Catalog,
Provider,
Expand Down Expand Up @@ -52,132 +53,131 @@ defmodule Trento.Integration.ChecksTest do
|> expect(:get_runner_ready_content, fn _runner_url -> {:ok, %{"ready" => true}} end)
|> expect(:get_catalog_content, fn _runner_url -> {:ok, raw_catalog} end)

normalized_catalog =
%Catalog{
providers: [
%Provider{
groups: [
%Group{
checks: [
%Check{
description: "description 1",
id: "1",
implementation: "implementation 1",
labels: "labels",
name: "test 1",
remediation: "remediation 1"
},
%Check{
description: "description 2",
id: "2",
implementation: "implementation 2",
labels: "labels",
name: "test 2",
remediation: "remediation 2"
}
],
group: "Group 1"
},
%Group{
checks: [
%Check{
description: "description 3",
id: "3",
implementation: "implementation 3",
labels: "labels",
name: "test 3",
remediation: "remediation 3"
},
%Check{
description: "description 4",
id: "4",
implementation: "implementation 4",
labels: "labels",
name: "test 4",
remediation: "remediation 4"
}
],
group: "Group 2"
},
%Group{
checks: [
%Check{
description: "description 5",
id: "5",
implementation: "implementation 5",
labels: "labels",
name: "test 5",
remediation: "remediation 5"
}
],
group: "Group 3"
}
normalized_catalog = %Catalog{
providers: [
%Provider{
groups: [
%Group{
checks: [
%Check{
description: "description 1",
id: "1",
implementation: "implementation 1",
labels: "labels",
name: "test 1",
remediation: "remediation 1"
},
%Check{
description: "description 2",
id: "2",
implementation: "implementation 2",
labels: "labels",
name: "test 2",
remediation: "remediation 2"
}
],
group: "Group 1"
},
%Group{
checks: [
%Check{
description: "description 3",
id: "3",
implementation: "implementation 3",
labels: "labels",
name: "test 3",
remediation: "remediation 3"
},
%Check{
description: "description 4",
id: "4",
implementation: "implementation 4",
labels: "labels",
name: "test 4",
remediation: "remediation 4"
}
],
provider: :aws
group: "Group 2"
},
%Provider{
groups: [
%Group{
checks: [
%Check{
description: "description 1",
id: "1",
implementation: "implementation 1",
labels: "labels",
name: "test 1",
remediation: "remediation 1"
},
%Check{
description: "description 2",
id: "2",
implementation: "implementation 2",
labels: "labels",
name: "test 2",
remediation: "remediation 2"
}
],
group: "Group 1"
%Group{
checks: [
%Check{
description: "description 5",
id: "5",
implementation: "implementation 5",
labels: "labels",
name: "test 5",
remediation: "remediation 5"
}
],
group: "Group 3"
}
],
provider: :aws
},
%Provider{
groups: [
%Group{
checks: [
%Check{
description: "description 1",
id: "1",
implementation: "implementation 1",
labels: "labels",
name: "test 1",
remediation: "remediation 1"
},
%Group{
checks: [
%Check{
description: "description 3",
id: "3",
implementation: "implementation 3",
labels: "labels",
name: "test 3",
remediation: "remediation 3"
},
%Check{
description: "description 4",
id: "4",
implementation: "implementation 4",
labels: "labels",
name: "test 4",
remediation: "remediation 4"
}
],
group: "Group 2"
%Check{
description: "description 2",
id: "2",
implementation: "implementation 2",
labels: "labels",
name: "test 2",
remediation: "remediation 2"
}
],
group: "Group 1"
},
%Group{
checks: [
%Check{
description: "description 3",
id: "3",
implementation: "implementation 3",
labels: "labels",
name: "test 3",
remediation: "remediation 3"
},
%Group{
checks: [
%Check{
description: "description 5",
id: "5",
implementation: "implementation 5",
labels: "labels",
name: "test 5",
remediation: "remediation 5"
}
],
group: "Group 3"
%Check{
description: "description 4",
id: "4",
implementation: "implementation 4",
labels: "labels",
name: "test 4",
remediation: "remediation 4"
}
],
group: "Group 2"
},
%Group{
checks: [
%Check{
description: "description 5",
id: "5",
implementation: "implementation 5",
labels: "labels",
name: "test 5",
remediation: "remediation 5"
}
],
provider: :azure
group: "Group 3"
}
]
],
provider: :azure
}
]
}

assert {:ok, normalized_catalog} == Checks.get_catalog()
assert {:ok, normalized_catalog} == Checks.get_catalog()
end
end

0 comments on commit 432620a

Please sign in to comment.