diff --git a/apps/amethyst/test/game_coordinator_test.exs b/apps/amethyst/test/game_coordinator_test.exs new file mode 100644 index 0000000..4af8e7e --- /dev/null +++ b/apps/amethyst/test/game_coordinator_test.exs @@ -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