Add tests for GameCoordinator
Some checks failed
Build & Test / nix-build (push) Failing after 17s

This commit is contained in:
Kodi Craft 2024-08-19 00:15:29 +02:00
parent 450ca4d53a
commit c7d3b139fe
Signed by: kodi
GPG Key ID: 69D9EED60B242822

View File

@ -0,0 +1,43 @@
defmodule GameCoordinatorTestGame do
use Amethyst.API.Game
@moduledoc """
This module is a sample game for the purpose of
testing the GameCoordinator
"""
@impl true
def instantiate() do
{:ok, :example_state}
end
@impl true
def login(_connection_process, _player_cfg, state) do
{:ok, state}
end
end
defmodule GameCoordinatorTest do
use ExUnit.Case, async: true
@moduledoc """
This module includes tests for Amethyst.GameCoordinator
"""
test "Create an instance of a game with create/1 then kill it" do
pid = Amethyst.GameCoordinator.create(GameCoordinatorTestGame)
assert Process.alive?(pid)
assert Amethyst.GameCoordinator.find(GameCoordinatorTestGame) == pid
Process.exit(pid, :kill)
assert Amethyst.GameCoordinator.find(GameCoordinatorTestGame) == nil
end
test "Create new instance with find_or_create/1 if one doesn't exist, otherwise use it" do
pid = Amethyst.GameCoordinator.find_or_create(GameCoordinatorTestGame)
assert Process.alive?(pid)
assert Amethyst.GameCoordinator.find_or_create(GameCoordinatorTestGame) == pid
Process.exit(pid, :kill)
assert Amethyst.GameCoordinator.find_or_create(GameCoordinatorTestGame) != pid
Amethyst.GameCoordinator.find(GameCoordinatorTestGame) |> Process.exit(:kill)
end
end