No supervisor children when in test env for FarmbotExt.Bootstrap.Supervisor
parent
e6b0f53224
commit
128ed8ec43
|
@ -2,4 +2,5 @@ use Mix.Config
|
|||
|
||||
if Mix.env() == :test do
|
||||
config :farmbot_ext, FarmbotExt, children: []
|
||||
config :farmbot_ext, FarmbotExt.Bootstrap.Supervisor, children: []
|
||||
end
|
||||
|
|
|
@ -16,7 +16,7 @@ defmodule FarmbotExt.API.ImageUploader do
|
|||
GenServer.start_link(__MODULE__, args, name: __MODULE__)
|
||||
end
|
||||
|
||||
def force_checkup do
|
||||
def force_checkup() do
|
||||
GenServer.cast(__MODULE__, :force_checkup)
|
||||
end
|
||||
|
||||
|
|
|
@ -12,14 +12,17 @@ defmodule FarmbotExt.Bootstrap.Supervisor do
|
|||
|
||||
@impl Supervisor
|
||||
def init([]) do
|
||||
children = [
|
||||
Supervisor.init(children(), strategy: :one_for_one)
|
||||
end
|
||||
|
||||
def children() do
|
||||
config = Application.get_env(:farmbot_ext, __MODULE__) || []
|
||||
Keyword.get(config, :children, [
|
||||
FarmbotExt.API.EagerLoader.Supervisor,
|
||||
FarmbotExt.API.DirtyWorker.Supervisor,
|
||||
FarmbotExt.AMQP.Supervisor,
|
||||
FarmbotExt.API.ImageUploader,
|
||||
FarmbotExt.Bootstrap.DropPasswordTask
|
||||
]
|
||||
|
||||
Supervisor.init(children, strategy: :one_for_one)
|
||||
])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
defmodule FarmbotExt.API.ImageUploaderTest do
|
||||
use ExUnit.Case
|
||||
use Mimic
|
||||
alias FarmbotExt.API.ImageUploader
|
||||
setup :verify_on_exit!
|
||||
|
||||
test "force checkup" do
|
||||
Helpers.NamedProcess.start_link({ImageUploader, "force_checkup_test"})
|
||||
# TODO: Get some single pixel jpg, jpeg, png, gif files.
|
||||
# TODO: Stub `API.upload_image`
|
||||
|
||||
# upload_image_mock = fn _fname ->
|
||||
# raise "HMMM...."
|
||||
# end
|
||||
|
||||
mapper = fn fname ->
|
||||
File.touch!("/tmp/images/#{fname}")
|
||||
end
|
||||
|
||||
# expect(FarmbotExt.API, :upload_image, 3, upload_image_mock)
|
||||
["a.jpg", "b.jpeg", "c.png", "d.gif"] |> Enum.map(mapper)
|
||||
ImageUploader.force_checkup()
|
||||
Process.sleep(100)
|
||||
assert_receive :lol
|
||||
end
|
||||
end
|
|
@ -31,3 +31,36 @@ defmodule Helpers do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
defmodule Helpers.NamedProcess do
|
||||
@moduledoc """
|
||||
NOTE: Inspired by ex_venture test suite. Thanks! -RC
|
||||
|
||||
Register a globaly named process that fakes out a normally real process.
|
||||
|
||||
Any messages this process receives will forward them to the test process via `send`.
|
||||
"""
|
||||
|
||||
use GenServer
|
||||
|
||||
@doc """
|
||||
Link a new process to the test process
|
||||
|
||||
This takes place outside of the supervision tree, so the process does
|
||||
not hang around.
|
||||
"""
|
||||
def start_link(name) do
|
||||
GenServer.start_link(__MODULE__, [caller: self(), name: name], [name: {:global, name}])
|
||||
end
|
||||
|
||||
@impl true
|
||||
def init(state) do
|
||||
{:ok, Enum.into(state, %{})}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_cast(message, state) do
|
||||
send(state.caller, {state.name, {:cast, message}})
|
||||
{:noreply, state}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue