-
Notifications
You must be signed in to change notification settings - Fork 0
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
Zoey de Souza Pessanha
committed
Jul 24, 2023
1 parent
cf83695
commit dae9c2a
Showing
6 changed files
with
151 additions
and
7 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
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
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,26 @@ | ||
defmodule Nexus.RuntimeStorageTest do | ||
use ExUnit.Case, async: true | ||
|
||
setup do | ||
start_supervised!({Nexus.RuntimeStorage, :nexus_test_storage}) | ||
:ok | ||
end | ||
|
||
describe "read/1" do | ||
test "reading a non existing value should return nil" do | ||
refute Nexus.RuntimeStorage.read(:do_not_exists) | ||
end | ||
|
||
test "reading an existing value should return it" do | ||
assert :ets.insert(:nexus_test_storage, {:teste, true}) | ||
assert Nexus.RuntimeStorage.read(:teste) | ||
end | ||
end | ||
|
||
describe "insert/2" do | ||
test "inserting a value should persist it into ETS" do | ||
assert :ok = Nexus.RuntimeStorage.insert(:teste, true) | ||
assert Nexus.RuntimeStorage.read(:teste) | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
defmodule NexusTest do | ||
use ExUnit.Case, async: true | ||
|
||
import Nexus | ||
|
||
setup do | ||
start_supervised!({Nexus.RuntimeStorage, :nexus_test_storage}) | ||
:ok | ||
end | ||
|
||
describe "defcommand/2" do | ||
test "defining a command should insert it into ETS" do | ||
defcommand(:hello, required: false, type: :atom) | ||
assert Nexus.RuntimeStorage.read(:hello) | ||
end | ||
|
||
test "defining multiple command should insert all into ETS" do | ||
defcommand(:foo, required: false, type: :string) | ||
defcommand(:bar, []) | ||
assert length(Nexus.fetch_cli_commands(__MODULE__)) == 2 | ||
end | ||
end | ||
|
||
describe "fetch_cli_commands/1" do | ||
test "when there's no command for supplied module" do | ||
assert Enum.empty?(Nexus.fetch_cli_commands(DoNotExist)) | ||
end | ||
|
||
test "when module exists but do not define any command" do | ||
assert Enum.empty?(Nexus.fetch_cli_commands(Nexus)) | ||
end | ||
|
||
test "when module exists and define some command" do | ||
defcommand(:teste, type: :string, required: false) | ||
assert length(Nexus.fetch_cli_commands(__MODULE__)) == 1 | ||
end | ||
end | ||
end |