Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dottorblaster committed Aug 25, 2023
1 parent d7f08dc commit 79789a1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
6 changes: 5 additions & 1 deletion test/demo/fake_server_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ defmodule Wanda.Executions.FakeServerTest do
test "start_execution publishes execution started and completed messages" do
execution_id = UUID.uuid4()
group_id = UUID.uuid4()
target_type = Faker.Person.first_name()
targets = build_list(2, :target, checks: ["expect_check"])
env = build(:env)

Expand All @@ -30,7 +31,10 @@ defmodule Wanda.Executions.FakeServerTest do
:ok
end)

assert :ok = FakeServer.start_execution(execution_id, group_id, targets, env, sleep: 0)
assert :ok =
FakeServer.start_execution(execution_id, group_id, targets, target_type, env,
sleep: 0
)

assert %Execution{execution_id: ^execution_id, status: :completed} = Repo.one!(Execution)
end
Expand Down
19 changes: 16 additions & 3 deletions test/wanda/executions/server_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ defmodule Wanda.Executions.ServerTest do
)

assert {:error, :already_running} =
Server.start_execution(UUID.uuid4(), group_id, targets, %{})
Server.start_execution(UUID.uuid4(), group_id, targets, :cluster, %{})
end

test "should exit when all facts are sent by all agents", context do
Expand Down Expand Up @@ -267,7 +267,13 @@ defmodule Wanda.Executions.ServerTest do
targets = build_list(2, :target, checks: [])

assert {:error, :no_checks_selected} =
Server.start_execution(UUID.uuid4(), UUID.uuid4(), targets, %{})
Server.start_execution(
UUID.uuid4(),
UUID.uuid4(),
targets,
Faker.Person.first_name(),
%{}
)
end

test "should execute existing checks if non-existent checks are selected" do
Expand All @@ -279,7 +285,14 @@ defmodule Wanda.Executions.ServerTest do
build(:target, checks: ["expect_same_check", "non_existing"])
]

assert :ok = Server.start_execution(UUID.uuid4(), group_id, targets, %{})
assert :ok =
Server.start_execution(
UUID.uuid4(),
group_id,
targets,
Faker.Person.first_name(),
%{}
)

pid = :global.whereis_name({Server, group_id})
%{targets: actual_targets} = :sys.get_state(pid)
Expand Down
3 changes: 3 additions & 0 deletions test/wanda/policy_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ defmodule Wanda.PolicyTest do
execution_id = UUID.uuid4()
group_id = UUID.uuid4()
agent_id = UUID.uuid4()
target_type = Faker.Person.first_name()

expect(Wanda.Executions.ServerMock, :start_execution, fn ^execution_id,
^group_id,
Expand All @@ -25,6 +26,7 @@ defmodule Wanda.PolicyTest do
checks: ["check_id"]
}
],
^target_type,
%{
"key" => "value",
"other_key" => "other_value"
Expand All @@ -37,6 +39,7 @@ defmodule Wanda.PolicyTest do
execution_id: execution_id,
group_id: group_id,
targets: [%{agent_id: agent_id, checks: ["check_id"]}],
target_type: target_type,
env: %{
"key" => %{kind: {:string_value, "value"}},
"other_key" => %{kind: {:string_value, "other_value"}}
Expand Down
8 changes: 7 additions & 1 deletion test/wanda_web/controllers/v1/execution_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ defmodule WandaWeb.V1.ExecutionControllerTest do
test "should start an execution", %{conn: conn} do
execution_id = UUID.uuid4()
group_id = UUID.uuid4()
target_type = Faker.Person.first_name()

targets = [
%{
Expand All @@ -200,6 +201,7 @@ defmodule WandaWeb.V1.ExecutionControllerTest do
checks: ^checks
}
],
^target_type,
^env ->
:ok
end)
Expand All @@ -211,6 +213,7 @@ defmodule WandaWeb.V1.ExecutionControllerTest do
"execution_id" => execution_id,
"group_id" => group_id,
"targets" => targets,
"target_type" => target_type,
"env" => env
})
|> json_response(202)
Expand All @@ -224,6 +227,7 @@ defmodule WandaWeb.V1.ExecutionControllerTest do
} do
execution_id = UUID.uuid4()
group_id = UUID.uuid4()
target_type = Faker.Person.first_name()

targets = [
%{
Expand All @@ -242,6 +246,7 @@ defmodule WandaWeb.V1.ExecutionControllerTest do
checks: ^checks
}
],
^target_type,
^env ->
{:error, :already_running}
end)
Expand All @@ -253,6 +258,7 @@ defmodule WandaWeb.V1.ExecutionControllerTest do
"execution_id" => execution_id,
"group_id" => group_id,
"targets" => targets,
"target_type" => target_type,
"env" => env
})
|> json_response(422)
Expand All @@ -265,7 +271,7 @@ defmodule WandaWeb.V1.ExecutionControllerTest do
end

test "should return an error if no checks were selected", %{conn: conn} do
expect(Wanda.Executions.ServerMock, :start_execution, fn _, _, _, _ ->
expect(Wanda.Executions.ServerMock, :start_execution, fn _, _, _, _, _ ->
{:error, :no_checks_selected}
end)

Expand Down

0 comments on commit 79789a1

Please sign in to comment.