Hi everyone!
I’m trying to run my integration test suite with Docker. I’m using Hound. And I have configured it this way:
docker-compose.yml
version: '2'
services:
db:
image: postgres:9.5
phantomjs:
image: wernight/phantomjs:latest
command: phantomjs --wd
web:
build: .
command: mix phx.server
volumes:
- .:/app
ports:
- "4000:4000"
- "4001:4001"
depends_on:
- db
links:
- phantomjs
test.exs:
config :app, App.Endpoint,
http: [port: 4001],
server: true
[...]
config :hound,
driver: "phantomjs",
host: "http://phantomjs",
app_host: "http://web",
app_port: 4001
Then I’ve this simple test, in order to check that it works:
test_hound.exs
defmodule App.TestHound do
use App.IntegrationCase
defp login_index do
session_url(App.Endpoint, :new)
end
test "dummy test" do
login_index() |> navigate_to()
assert element?(:class, "site") == true
end
end
Then I run the test:
$ docker-compose run web env MIX_ENV=test mix test test/integration/test_hound.exs
but it didn’t pass:
Assertion with == failed
code: element?(:class, "site") == true
left: false
right: true
I inspected with IO.inspect current_url()
after execute the login_index() |> navigate_to()
and it returns about:blank
.
So the problem, I think, it’s that the test can’t connect properly with the phantomjs container in order to visit the web. It’s like it doesn’t launch the server. I inspected the login_index()
too, and it returns the login URL.
My integration case, look like this:
integration_case.ex
defmodule App.IntegrationCase do
use Hound.Helpers
use ExUnit.CaseTemplate
using do
quote do
use Hound.Helpers
import Ecto
import Ecto.Query
import App.Router.Helpers
import App.Factory
import App.IntegrationCase
alias App.Repo
# The default endpoint for testing
@endpoint App.Endpoint
hound_session()
end
end
setup tags do
:ok = Ecto.Adapters.SQL.Sandbox.checkout(App.Repo)
unless tags[:async] do
Ecto.Adapters.SQL.Sandbox.mode(App.Repo, {:shared, self()})
end
:ok
end
end
I’ve tried with different ports in the hound config, just in case, but I can’t make it work.
Any help would be appreciated. Thanks in advance!