enoliglesias

enoliglesias

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! :blush:

Showing Posts 1 to 2

enoliglesias

enoliglesias OP

Rubber ducking debugging here! :smile:

It’s a little bit embarrassing to me. But the error was in the test.exs file. In the Endpoint configuration, I needed to add url: [host: "web"]. In order to change the default localhost endpoint to point to the web container:

config :hcmex, Hcmex.Endpoint,
  http: [port: 4001],
  url: [host: "web"],
  server: true 

Now if I run the tests (there are some IO.inspects):

"http://web:4001/sign_in"
{:ok,
%{browser: "phantomjs", driver: "phantomjs", host: "http://phantomjs",
  path_prefix: nil, port: 8910}}
{:ok, %{host: "http://web", port: 4001}}
.

Finished in 2.4 seconds
1 test, 0 failures

Randomized with seed 427281

And It works! I feel a little bit dumb right now. But I hope this post can help other people.

Cheers!

opinxit

opinxit

This helped a lot – thank you!

Though I’m finding I get CSRF errors when I post a form with a similar configuration – I can verify that the csrf token is included in the form, and if I run the test server manually I can post said form successfully, but hound/phantomjs does not like it. Any ideas?

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
psy-q
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews