implement test stubs. Not sure what to do about the token

pull/363/head
Connor Rigby 2017-08-10 22:02:40 -07:00
parent 478597b971
commit 8469a573a4
7 changed files with 85 additions and 40 deletions

View File

@ -1,28 +0,0 @@
if Code.ensure_loaded? Farmbot do
alias Farmbot.{
Auth,
Context,
EventSupervisor,
HTTP,
Regimen,
SysFormatter,
BotState,
Database,
FarmEvent,
ImageWatcher,
Regimen.Runner,
CeleryScript,
DebugLog,
FarmEvent.Runner,
Lib,
Sequence.Runner,
Token,
Configurator,
EasterEggs,
Farmware,
Serial,
Transport
}
context = Context.new()
end

View File

@ -1 +1,16 @@
use Mix.Config
config :farmbot, :authorization, [
email: "admin@admin.com",
password: "password123",
server: "http://localhost:3000",
token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJhZG1pbkBhZG1pbi5jb20iLCJpYXQiOjE1MDI0Mjc2MDUsImp0aSI6IjA3ZDk1MmRjLWQ2MDktNGRiYi04NTcwLTIxMTNkM2Q2ZWMzOSIsImlzcyI6Ii8vMTkyLjE2OC4yOS4yMDQ6MzAwMCIsImV4cCI6MTUwNTg4MzYwNSwibXF0dCI6IjE5Mi4xNjguMjkuMjA0Iiwib3NfdXBkYXRlX3NlcnZlciI6Imh0dHBzOi8vYXBpLmdpdGh1Yi5jb20vcmVwb3MvZmFybWJvdC9mYXJtYm90X29zL3JlbGVhc2VzL2xhdGVzdCIsImZ3X3VwZGF0ZV9zZXJ2ZXIiOiJodHRwczovL2FwaS5naXRodWIuY29tL3JlcG9zL0Zhcm1ib3QvZmFybWJvdC1hcmR1aW5vLWZpcm13YXJlL3JlbGVhc2VzL2xhdGVzdCIsImJvdCI6ImRldmljZV8yIn0.twtAOS9PXtkSB-a3Qjm3HrJSM7Nfm7oWOc8d4BFb7nBOaB3eGDUB4sb5u7pjAgMo37egIbAatKKkHlh_o9uNDJvrs9aPsLAn6O8dN_CDCkenjNyrbQjI8i_hjtL28X9AyHLOe1G0A8V8nRs4hZ8x5AcQSH8DkhaaRaBuh-0u1Yesfo7nwFIl34LTCoZ9amrdzHvIn0xP35BaPoEGziqolqtNJ5an2Bps4JGBV_kNSlODwGxPFESHO3uL1PrTgaXkM3_FSZpY7NxbgxC50ok9TspeMRLjluqntzyJG1EadxgHkbVOG0kuPH6R3Pa6UfkDNzBv7DWDHk4mOYPcDdABbQ"
]
config :farmbot, :init, [
]
config :farmbot, :behaviour, [
authorization: Farmbot.Test.Authorization,
system_tasks: Farmbot.Test.SystemTasks
]

View File

@ -1,10 +0,0 @@
{
"custom_stop_words": [],
"skip_files": [
"lib/mix",
"lib/farmbot/system/",
"lib/farmbot/easter_eggs.ex",
"lib/farmbot/debug_log.ex",
"lib/farmbot/debug_log"
]
}

View File

@ -98,8 +98,8 @@ defmodule Farmbot.Bootstrap.Supervisor do
case @auth_task.authorize(email, pass, server) do
{:ok, token} ->
children = [
supervisor(Farmbot.HTTP.Supervisor, [token, [name: Farmbot.HTTP.Supervisor]]),
supervisor(Farmbot.Transport.Supervisor, [token, [name: Farmbot.Transport.Supervisor]])
# supervisor(Farmbot.HTTP.Supervisor, [token, [name: Farmbot.HTTP.Supervisor]]),
# supervisor(Farmbot.Transport.Supervisor, [token, [name: Farmbot.Transport.Supervisor]])
]
opts = [strategy: :one_for_all]
supervise(children, opts)

View File

@ -0,0 +1,12 @@
defmodule Farmbot.Test.Authorization do
@moduledoc "Implementation for authorization."
@behaviour Farmbot.Bootstrap.Authorization
def authorize(_email, _password, _server) do
tkn = Application.get_env(:farmbot, :authorization)[:token]
case tkn do
token when is_binary(tkn) -> {:ok, token}
_ -> {:error, "no token"}
end
end
end

View File

@ -0,0 +1,55 @@
defmodule Farmbot.Test.SystemTasks do
@moduledoc "Test implementation for system tasks"
@behaviour Farmbot.System
# System Implementation.
def factory_reset(reason) do
pid = fetch_pid()
GenServer.call(pid, {:factory_reset, reason})
end
def reboot(reason) do
pid = fetch_pid()
GenServer.call(pid, {:reboot, reason})
end
def shutdown(reason) do
pid = fetch_pid()
GenServer.call(pid, {:shutdown, reason})
end
# Test Helpers.
use GenServer
@doc "Fetches the last action and reason"
@spec fetch_last() :: {:factory_reset | :reboot | :shutdown, any} | nil
def fetch_last do
pid = fetch_pid()
GenServer.call(pid, :fetch_last)
end
defp fetch_pid do
maybe_pid = Process.whereis(__MODULE__)
if is_pid(maybe_pid) do
maybe_pid
else
{:ok, pid} = GenServer.start_link(__MODULE__, [], [name: __MODULE__])
pid
end
end
def init([]) do
{:ok, []}
end
def handle_call({action, reason} = thing, _, state) do
{:reply, :ok, [thing | state]}
end
def handle_call(:fetch_last, _, [last | _rest] = state) do
{:reply, last, state}
end
end

View File

@ -0,0 +1 @@
ExUnit.start()