-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
129 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
lib/trento/application/integration/checks/adapter/wanda/policy/behaviour.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
defmodule Trento.Integration.Checks.Wanda.Behaviour do | ||
@moduledoc """ | ||
Wanda event policy behaviour | ||
""" | ||
|
||
alias Trento.Checks.V1.ExecutionCompleted | ||
|
||
@callback handle(event :: ExecutionCompleted.t()) :: | ||
{:ok, command :: any, opts :: Keyword.t()} | {:error, any} | ||
end |
32 changes: 32 additions & 0 deletions
32
lib/trento/application/integration/checks/adapter/wanda/policy/policy.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
defmodule Trento.Integration.Checks.Wanda.Policy do | ||
@moduledoc """ | ||
Wanda event policies | ||
""" | ||
|
||
@behaviour Trento.Integration.Checks.Wanda.Behaviour | ||
|
||
alias Trento.Checks.V1.ExecutionCompleted | ||
alias Trento.Domain.Commands.CompleteChecksExecutionWanda | ||
|
||
def handle(%ExecutionCompleted{ | ||
execution_id: execution_id, | ||
group_id: group_id, | ||
result: result | ||
}) do | ||
case CompleteChecksExecutionWanda.new(%{ | ||
cluster_id: group_id, | ||
health: map_health(result) | ||
}) do | ||
{:ok, command} -> | ||
opts = [correlation_id: execution_id] | ||
{:ok, command, opts} | ||
|
||
error -> | ||
error | ||
end | ||
end | ||
|
||
defp map_health(:CRITICAL), do: :critical | ||
defp map_health(:WARNING), do: :warning | ||
defp map_health(:PASSING), do: :passing | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
test/trento/application/integration/checks/wanda/policy/policy_test.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
defmodule Trento.Integration.Checks.Wanda.PolicyTest do | ||
@moduledoc false | ||
use ExUnit.Case | ||
|
||
alias Trento.Checks.V1.ExecutionCompleted | ||
alias Trento.Domain.Commands.CompleteChecksExecutionWanda | ||
alias Trento.Integration.Checks.Wanda.Policy | ||
|
||
require Trento.Domain.Enums.Health, as: Health | ||
|
||
describe "handle" do | ||
test "should handle ExecutionCompleted event" do | ||
execution_id = UUID.uuid4() | ||
cluster_id = UUID.uuid4() | ||
|
||
assert {:ok, | ||
%CompleteChecksExecutionWanda{ | ||
cluster_id: ^cluster_id, | ||
health: Health.passing() | ||
}, | ||
[correlation_id: ^execution_id]} = | ||
Policy.handle(%ExecutionCompleted{ | ||
execution_id: execution_id, | ||
group_id: cluster_id, | ||
result: :PASSING | ||
}) | ||
end | ||
end | ||
end |