Skip to content

Commit

Permalink
Split the host event upcasting test to individual files
Browse files Browse the repository at this point in the history
  • Loading branch information
arbulu89 committed Sep 12, 2022
1 parent a449b53 commit 3374eac
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 22 deletions.
46 changes: 46 additions & 0 deletions test/trento/domain/host/events/host_details_updated_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
defmodule Trento.Domain.Events.HostDetailsUpdatedTest do
use Trento.AggregateCase, aggregate: Trento.Domain.Host, async: true

alias Trento.Domain.Events.HostDetailsUpdated

describe "HostDetailsUpdated event upcasting" do
test "should upcast HostDetailsUpdated event properly from version 1" do
host_id = Faker.UUID.v4()
hostname = Faker.StarWars.character()
ip_addresses = [Faker.Internet.ip_v4_address()]
ssh_address = Faker.Internet.ip_v4_address()
agent_version = Faker.Internet.slug()
cpu_count = Enum.random(1..16)
total_memory_mb = Enum.random(1..128)
socket_count = Enum.random(1..16)
os_version = Faker.App.version()

assert %HostDetailsUpdated{
version: 2,
host_id: host_id,
hostname: hostname,
ip_addresses: ip_addresses,
ssh_address: ssh_address,
agent_version: agent_version,
cpu_count: cpu_count,
total_memory_mb: total_memory_mb,
socket_count: socket_count,
os_version: os_version,
installation_source: :unknown
} ==
%{
"host_id" => host_id,
"hostname" => hostname,
"ip_addresses" => ip_addresses,
"ssh_address" => ssh_address,
"agent_version" => agent_version,
"cpu_count" => cpu_count,
"total_memory_mb" => total_memory_mb,
"socket_count" => socket_count,
"os_version" => os_version
}
|> HostDetailsUpdated.upcast(%{})
|> HostDetailsUpdated.new!()
end
end
end
46 changes: 46 additions & 0 deletions test/trento/domain/host/events/host_registered_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
defmodule Trento.Domain.Events.HostRegisteredTest do
use Trento.AggregateCase, aggregate: Trento.Domain.Host, async: true

alias Trento.Domain.Events.HostRegistered

describe "HostRegistered event upcasting" do
test "should upcast HostRegistered event properly from version 1" do
host_id = Faker.UUID.v4()
hostname = Faker.StarWars.character()
ip_addresses = [Faker.Internet.ip_v4_address()]
ssh_address = Faker.Internet.ip_v4_address()
agent_version = Faker.Internet.slug()
cpu_count = Enum.random(1..16)
total_memory_mb = Enum.random(1..128)
socket_count = Enum.random(1..16)
os_version = Faker.App.version()

assert %HostRegistered{
version: 2,
host_id: host_id,
hostname: hostname,
ip_addresses: ip_addresses,
ssh_address: ssh_address,
agent_version: agent_version,
cpu_count: cpu_count,
total_memory_mb: total_memory_mb,
socket_count: socket_count,
os_version: os_version,
installation_source: :unknown
} ==
%{
"host_id" => host_id,
"hostname" => hostname,
"ip_addresses" => ip_addresses,
"ssh_address" => ssh_address,
"agent_version" => agent_version,
"cpu_count" => cpu_count,
"total_memory_mb" => total_memory_mb,
"socket_count" => socket_count,
"os_version" => os_version
}
|> HostRegistered.upcast(%{})
|> HostRegistered.new!()
end
end
end
22 changes: 0 additions & 22 deletions test/trento/domain/host/host_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -531,26 +531,4 @@ defmodule Trento.HostTest do
)
end
end

describe "event upcasting" do
test "should upcast HostRegistered event properly" do
assert %HostRegistered{
version: 2,
installation_source: :unknown
} ==
%{}
|> HostRegistered.upcast(%{})
|> HostRegistered.new!()
end

test "should upcast HostDetailsUpdated event properly" do
assert %HostDetailsUpdated{
version: 2,
installation_source: :unknown
} ==
%{}
|> HostDetailsUpdated.upcast(%{})
|> HostDetailsUpdated.new!()
end
end
end

0 comments on commit 3374eac

Please sign in to comment.