TODO: Fix FarmbotCeleryScript.SchedulerTest
parent
9ba060c0f1
commit
d6ab57425b
|
@ -102,7 +102,8 @@ defmodule FarmbotCeleryScript.SysCalls.Stubs do
|
||||||
do: error(:point, [point_type, resource_id])
|
do: error(:point, [point_type, resource_id])
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def get_point_group(_ \\ nil, id_or_type), do: error(:get_point_group, [id_or_type])
|
def get_point_group(_ \\ nil, id_or_type),
|
||||||
|
do: error(:get_point_group, [id_or_type])
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def power_off(), do: error(:power_off, [])
|
def power_off(), do: error(:power_off, [])
|
||||||
|
|
|
@ -67,7 +67,8 @@ defmodule FarmbotCeleryScript.MixProject do
|
||||||
{:timex, "~> 3.4"},
|
{:timex, "~> 3.4"},
|
||||||
{:excoveralls, "~> 0.10", only: [:test], targets: [:host]},
|
{:excoveralls, "~> 0.10", only: [:test], targets: [:host]},
|
||||||
{:mimic, "~> 1.1", only: :test},
|
{:mimic, "~> 1.1", only: :test},
|
||||||
{:dialyxir, "~> 1.0.0-rc.3", only: [:dev], targets: [:host], runtime: false},
|
{:dialyxir, "~> 1.0.0-rc.3",
|
||||||
|
only: [:dev], targets: [:host], runtime: false},
|
||||||
{:ex_doc, "~> 0.21.2", only: [:dev], targets: [:host], runtime: false}
|
{:ex_doc, "~> 0.21.2", only: [:dev], targets: [:host], runtime: false}
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
|
@ -46,7 +46,8 @@ defmodule FarmbotCeleryScript.CompilerGroupsTest do
|
||||||
canary_actual = :crypto.hash(:sha, Macro.to_string(result))
|
canary_actual = :crypto.hash(:sha, Macro.to_string(result))
|
||||||
|
|
||||||
canary_expected =
|
canary_expected =
|
||||||
<<157, 69, 5, 38, 188, 78, 10, 183, 154, 99, 151, 193, 214, 208, 187, 130, 183, 73, 13, 48>>
|
<<157, 69, 5, 38, 188, 78, 10, 183, 154, 99, 151, 193, 214, 208, 187, 130,
|
||||||
|
183, 73, 13, 48>>
|
||||||
|
|
||||||
# READ THE NOTE ABOVE IF THIS TEST FAILS!!!
|
# READ THE NOTE ABOVE IF THIS TEST FAILS!!!
|
||||||
assert canary_expected == canary_actual
|
assert canary_expected == canary_actual
|
||||||
|
|
|
@ -123,9 +123,23 @@ defmodule FarmbotCeleryScript.SysCallsTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "named_pin" do
|
test "named_pin" do
|
||||||
|
err = {:error, "error finding resource"}
|
||||||
|
|
||||||
|
expect(Stubs, :named_pin, 5, fn kind, num ->
|
||||||
|
hmm = {kind, num}
|
||||||
|
|
||||||
|
case hmm do
|
||||||
|
{"Peripheral", 5} -> 44
|
||||||
|
{"Sensor", 1999} -> 55
|
||||||
|
{"BoxLed", 3} -> %{type: "BoxLed", id: 3}
|
||||||
|
{"BoxLed", 4} -> %{type: "BoxLed", id: 4}
|
||||||
|
{"Peripheral", 888} -> err
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
# Peripheral and Sensor are on the Arduino
|
# Peripheral and Sensor are on the Arduino
|
||||||
assert 44 == SysCalls.named_pin(Stubs, "Peripheral", 5)
|
assert 44 == SysCalls.named_pin(Stubs, "Peripheral", 5)
|
||||||
assert 44 == SysCalls.named_pin(Stubs, "Sensor", 1999)
|
assert 55 == SysCalls.named_pin(Stubs, "Sensor", 1999)
|
||||||
|
|
||||||
# BoxLed is on the GPIO
|
# BoxLed is on the GPIO
|
||||||
|
|
||||||
|
@ -135,34 +149,40 @@ defmodule FarmbotCeleryScript.SysCallsTest do
|
||||||
assert %{type: "BoxLed", id: 4} ==
|
assert %{type: "BoxLed", id: 4} ==
|
||||||
SysCalls.named_pin(Stubs, "BoxLed", 4)
|
SysCalls.named_pin(Stubs, "BoxLed", 4)
|
||||||
|
|
||||||
assert_receive {:named_pin, ["Peripheral", 5]}
|
assert err == SysCalls.named_pin(Stubs, "Peripheral", 888)
|
||||||
assert_receive {:named_pin, ["Sensor", 1999]}
|
|
||||||
assert_receive {:named_pin, ["BoxLed", 3]}
|
|
||||||
assert_receive {:named_pin, ["BoxLed", 4]}
|
|
||||||
|
|
||||||
assert {:error, "error finding resource"} ==
|
|
||||||
SysCalls.named_pin(Stubs, "Peripheral", 888)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "send_message" do
|
test "send_message" do
|
||||||
|
err = {:error, "email machine broke"}
|
||||||
|
|
||||||
|
expect(Stubs, :send_message, 2, fn type, _msg, _chans ->
|
||||||
|
if type == "error" do
|
||||||
|
err
|
||||||
|
else
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
assert :ok =
|
assert :ok =
|
||||||
SysCalls.send_message(Stubs, "success", "hello world", [
|
SysCalls.send_message(Stubs, "success", "hello world", ["email"])
|
||||||
"email"
|
|
||||||
])
|
|
||||||
|
|
||||||
assert_receive {:send_message, ["success", "hello world", ["email"]]}
|
assert err ==
|
||||||
|
SysCalls.send_message(Stubs, "error", "goodbye world", ["email"])
|
||||||
assert {:error, "email machine broke"} ==
|
|
||||||
SysCalls.send_message(Stubs, "error", "goodbye world", [
|
|
||||||
"email"
|
|
||||||
])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "find_home" do
|
test "find_home" do
|
||||||
assert :ok = SysCalls.find_home(Stubs, "x")
|
err = {:error, "home lost"}
|
||||||
assert_receive {:find_home, ["x"]}
|
|
||||||
|
|
||||||
assert {:error, "home lost"} == SysCalls.find_home(Stubs, "x")
|
expect(Stubs, :find_home, 2, fn axis ->
|
||||||
|
if axis == "x" do
|
||||||
|
:ok
|
||||||
|
else
|
||||||
|
err
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
assert :ok = SysCalls.find_home(Stubs, "x")
|
||||||
|
assert err == SysCalls.find_home(Stubs, "z")
|
||||||
end
|
end
|
||||||
|
|
||||||
test "execute_script" do
|
test "execute_script" do
|
||||||
|
@ -177,8 +197,6 @@ defmodule FarmbotCeleryScript.SysCallsTest do
|
||||||
end)
|
end)
|
||||||
|
|
||||||
assert :ok = SysCalls.execute_script(Stubs, "take-photo", %{})
|
assert :ok = SysCalls.execute_script(Stubs, "take-photo", %{})
|
||||||
assert_receive {:execute_script, ["take-photo", %{}]}
|
|
||||||
|
|
||||||
assert err == SysCalls.execute_script(Stubs, "take-photo", %{error: true})
|
assert err == SysCalls.execute_script(Stubs, "take-photo", %{error: true})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,8 @@ defmodule FarmbotCeleryScriptTest do
|
||||||
result = FarmbotCeleryScript.execute(execute_ast, execute_ast)
|
result = FarmbotCeleryScript.execute(execute_ast, execute_ast)
|
||||||
assert {:error, "failed to read pin!"} = result
|
assert {:error, "failed to read pin!"} = result
|
||||||
|
|
||||||
assert_receive {:step_complete, ^execute_ast, {:error, "failed to read pin!"}}
|
assert_receive {:step_complete, ^execute_ast,
|
||||||
|
{:error, "failed to read pin!"}}
|
||||||
end
|
end
|
||||||
|
|
||||||
test "regular exceptions still occur" do
|
test "regular exceptions still occur" do
|
||||||
|
|
Loading…
Reference in New Issue