I have the following at the top of my test suit which currently throws an error
use Raxx.Verify.RequestCase
import ExUnit.CaptureLog, only: [capture_log: 1]
setup do
raxx_app = {Raxx.Verify.Forwarder, %{target: self()}}
capture_log fn() ->
{:ok, endpoint} = Ace.HTTP.start_link(raxx_app, port: 0)
{:ok, port} = Ace.HTTP.port(endpoint)
end
{:ok, %{port: port}} # I want to return from my setup the value of the port.
end
Is there a simple way to get the value of that port out of the function.
In my case starting up a server is quite noisy and I do not want the startup messages in my test logs.
Maybe easier to quieten the log? I don’t know the log level that Ace logs at but something like this in your config/test.exs:
config :logger
compile_time_purge_level :info. # or :warn, or :error
Which may allow you to simply:
import ExUnit.CaptureLog, only: [capture_log: 1]
setup do
raxx_app = {Raxx.Verify.Forwarder, %{target: self()}>
{:ok, endpoint} = Ace.HTTP.start_link(raxx_app, port: 0)
{:ok, port} = Ace.HTTP.port(endpoint)
{:ok, %{port: port}} # I want to return from my setup the value of the port.
end
Could also do this without changing the config file:
import ExUnit.CaptureLog, only: [capture_log: 1]
setup do
Logger.configure(level: :error)
raxx_app = {Raxx.Verify.Forwarder, %{target: self()}>
{:ok, endpoint} = Ace.HTTP.start_link(raxx_app, port: 0)
{:ok, port} = Ace.HTTP.port(endpoint)
{:ok, %{port: port}} # I want to return from my setup the value of the port.
end
I don’t want to quieten the logs globally as I see stdout output as part of the interface an I have other tests to check that the correct content is written in some cases.
The second option looks good cheers.
At the moment I have a solution where I send the config I want to self() and pick it up from the mailbox but that might not be the best solution