tests pass again.

pull/194/head
connor rigby 2016-10-28 22:03:45 -07:00
parent 8cb5bee0e8
commit ec534ec300
11 changed files with 63 additions and 56 deletions

1
.gitignore vendored
View File

@ -12,3 +12,4 @@ erl_crash.dump
npm-debug.log
# this isnt ready yet
/lib/extras/my*
/lib/extras/raspi_*

View File

@ -3,8 +3,7 @@ config :uart,
baud: 115200
config :fb,
ro_path: "/tmp",
bot_state_save_file: "/tmp/botstatus.txt"
state_path: "/tmp/state"
config :json_rpc,
transport: MqttHandler

View File

@ -34,14 +34,20 @@ defmodule SequenceInstructionSet_0 do
lhs != rhs
end
def do_if(lhs, _, rhs)
when is_integer lhs and is_integer(rhs) do
RPCMessageHandler.log(\" Bad operator for if_statement \", [:error_toast], [\"SequenceInstructionSet\", \"ERROR\"])
:error
end
def do_if(:error, _op, _rhs) do
RPCMessageHandler.log(\" Could not locate value for LHS \", [], [\"SequenceInstructionSet\"])
:false
:error
end
def do_if(_lhs, _op, _rhs) do
RPCMessageHandler.log(\" Bad type for if_statement \", [], [\"SequenceInstructionSet\"])
:false
RPCMessageHandler.log(\" Bad type for if_statement \", [:error_toast], [\"SequenceInstructionSet\", \"ERROR\"])
:error
end
"
Module.create(SiS, create_instructions(initial, allowed_args_list, allowed_nodes_list ), Macro.Env.location(__ENV__))
@ -98,7 +104,7 @@ defmodule SequenceInstructionSet_0 do
end
def #{name}(value) do
RPCMessageHandler.log(\" Bad type for value: #{value} \", [], [\"Sequence Error\"])
RPCMessageHandler.log(\" Bad type \", [], [\"Sequence Error\"])
end
"
create_arg_instruction(name, types -- [type], old<>new)

11
mix.exs
View File

@ -58,7 +58,11 @@ defmodule Fw.Mixfile do
# test
def apps(:test) do
apps
apps ++ [
:plug,
:cors_plug,
:cowboy
]
end
def deps do
@ -84,7 +88,10 @@ defmodule Fw.Mixfile do
end
def deps(:test) do
deps ++ deps(:dev)
deps ++ deps(:dev) ++
[ {:plug, "~> 1.0"},
{:cors_plug, "~> 1.1"},
{:cowboy, "~> 1.0.0"} ]
end
def deps(:dev) do

View File

@ -8,6 +8,7 @@
"erlware_commons": {:hex, :erlware_commons, "0.21.0", "a04433071ad7d112edefc75ac77719dd3e6753e697ac09428fc83d7564b80b15", [:rebar3], [{:cf, "0.2.1", [hex: :cf, optional: false]}]},
"exjsx": {:hex, :exjsx, "3.2.1", "1bc5bf1e4fd249104178f0885030bcd75a4526f4d2a1e976f4b428d347614f0f", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, optional: false]}]},
"exrm": {:hex, :exrm, "1.0.8", "5aa8990cdfe300282828b02cefdc339e235f7916388ce99f9a1f926a9271a45d", [:mix], [{:relx, "~> 3.5", [hex: :relx, optional: false]}]},
"fake_nerves": {:git, "https://github.com/ConnorRigby/fake_nerves.git", "9bbf56f3e538580f9e7e09d08d77021b907f2a44", []},
"farmbot_configurator": {:git, "https://github.com/FarmBot/farmbot_configurator.git", "c47caa05298146d14411dac52413b2fe554d99b2", []},
"gen_stage": {:hex, :gen_stage, "0.8.0", "a76e3f0530f86fae8b8a1021c06527b1ec171cf4c0bdfecd8d5ad0376d1205af", [:mix], []},
"getopt": {:hex, :getopt, "0.8.2", "b17556db683000ba50370b16c0619df1337e7af7ecbf7d64fbf8d1d6bce3109b", [:rebar], []},

View File

@ -2,19 +2,12 @@ ExUnit.start
defmodule AuthTest do
require IEx
Code.require_file "test/test_router.exs"
@path Application.get_env(:fb, :ro_path)
@path Application.get_env(:fb, :state_path)
use ExUnit.Case, async: true
setup do
HTTPotion.start
Plug.Adapters.Cowboy.http(TestRouter, [])
Auth.start_link(:normal)
on_exit fn ->
case File.read("#{@path}/secretes.txt") do
{:ok, _contents} -> File.rm("#{@path}/secretes.txt")
_ -> nil
end
:ok
end
:ok
end
@ -34,8 +27,6 @@ defmodule AuthTest do
secret = Auth.encrypt("fred_flinstone@tehflinstones.co.uk", "johnGoodman_is+GR8", server)
assert(secret != nil)
assert(is_bitstring(secret))
contents = File.read!("#{@path}/secretes.txt") |> :erlang.binary_to_term
assert(contents.secret == secret)
end
test "gets a token" do

View File

@ -3,53 +3,27 @@ defmodule BotStateTest do
use ExUnit.Case, async: true
test "gets the current status" do
{:ok, status} = BotState.init(:hello)
{:reply, current_status, current_status} = BotState.handle_call({:get_status}, self(), status)
{:ok, status} = BotState.init(:normal)
{:reply, current_status, current_status} = BotState.handle_call(:state, self(), status)
# We havent changed anything so the status should be in its initial state.
assert(status == current_status)
# just a sanity check
assert(Map.get(current_status, :busy) == true)
end
test "sets a pin value on and then off again." do
BotState.set_pin(13, 1)
BotState.set_pin_mode(13, 0)
BotState.set_pin_value(13, 1)
status1 = BotState.get_status
assert(Map.get(status1, "pin13") == 1)
a = BotState.get_pin(13)
assert(a == %{mode: 0, value: 1})
BotState.set_pin(13, 0)
status2 = BotState.get_status
assert(Map.get(status2, "pin13") == 0)
assert(BotState.get_pin(13) == 0)
end
test "checks and Sets busy" do
status = BotState.get_status
assert(Map.get(status, :busy) == true)
BotState.busy false
assert(BotState.busy? == false)
BotState.set_pin_value(13, 0)
b = BotState.get_pin(13)
assert(b == %{mode: 0, value: 0})
end
test "checks and sets bot position" do
assert(BotState.get_current_pos == [0,0,0])
BotState.set_pos(1,2,3)
assert(BotState.get_current_pos == [1,2,3])
# set just x
BotState.set_pos({:x, 55})
assert(BotState.get_current_pos == [55,2,3])
BotState.set_pos({:y, 15000})
assert(BotState.get_current_pos == [55,15000,3])
BotState.set_pos({:z, -45})
assert(BotState.get_current_pos == [55,15000,-45])
end
test "gets the current version" do
version = Path.join(__DIR__ <> "/../../", "VERSION")
|> File.read!
|> String.strip
assert(BotState.get_current_version == version)
end
end

View File

@ -12,7 +12,7 @@ defmodule RPCMessageManagerTest do
{:ok, decoded} = Poison.decode(msg)
assert(Map.get(decoded, "id") == "long uuid string")
assert(Map.get(decoded, "error") == nil)
assert(Map.get(decoded, "result") == "OK")
assert(Map.get(decoded, "result") == %{"OK" => "OK"})
end
test("it creates a JsonRpc compliant farmbot error message") do

View File

@ -0,0 +1,21 @@
defmodule TestGenServer do
use GenServer
def start_link(name) do
GenServer.start_link(__MODULE__, :ok, name: name)
end
def init(:ok) do
{:ok, :fake_state}
end
def hadnle_call(:am_i_connected, _, state) do
{:reply, :true, state}
end
def handle_call(_,_,state) do
{:reply, :ok, state}
end
def handle_cast(_, state) do
{:noreply, state}
end
def handle_info(_,state) do
{:noreply, state}
end
end

View File

@ -1,3 +1,9 @@
ExUnit.start
# Maybe we will need a "test supervision tree" LOL
{:ok, _pid} = BotState.start_link(:nothing)
IO.puts "starting test genserver"
Code.load_file("test_genserver.ex", "./test")
Code.ensure_loaded(TestGenServer)
Code.load_file("fake_mqtt.ex", "./test")
Code.ensure_loaded(FakeMqtt)
{:ok, _} = TestGenServer.start_link(SafeStorage)
{:ok, _} = TestGenServer.start_link(Wifi)
{:ok, _botState} = BotState.start_link(:nothing)

View File

@ -1,4 +1,5 @@
defmodule TestRouter do
require Plug.Router
use Plug.Router
plug CORSPlug
plug Plug.Parsers, parsers: [:urlencoded, :json],