Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Travis and Docker acceptance case #40

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ script:
- RUNNING_CONTAINERS=`docker ps | wc -l`;
- if [ "${RUNNING_CONTAINERS//[[:space:]]/}" == "1" ]; then echo "[E] Container is not started\!"; docker logs prm --details --since 5h; exit 1; fi;
# Run acceptance tests on Docker container
- "MIX_TEST_HOST=localhost MIX_TEST_PORT=4000 mix test test/acceptance"
- CONTAINER_HTTP_HOST=localhost CONTAINER_HTTP_PORT=4000 mix test test/acceptance
Copy link
Contributor

@gmile gmile Mar 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not a blocking comment)

Here CONTAINER_HTTP_HOST looks weird in isolation. It's hard to get what is it used for, unless you know what you're looking for (one has to look up the eview sources for it).

Opened an issue in eview – Nebo15/eview#6.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually ignore this, my bad. I was searching for usage of CONTAINER_HTTP_HOST and found it in eview. But it appears it's no other that a name clash.

after_failure:
- docker logs prm --details --since 5h
after_success:
Expand Down
2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ config :prm, PRM.Repo,
adapter: Ecto.Adapters.Postgres,
username: "postgres",
password: "postgres",
database: "prm_test",
database: System.get_env("MIX_TEST_DATABASE") || "prm_test",
hostname: "localhost",
pool: Ecto.Adapters.SQL.Sandbox
1 change: 1 addition & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ defmodule PRM.Mixfile do
{:cowboy, "~> 1.0"},
{:confex, "~> 1.4"},
{:poison, "~> 3.1", override: true},
{:httpoison, "~> 0.11.1"},
{:eview, ">= 0.0.0"},
{:postgrex, ">= 0.0.0"},
{:phoenix, "~> 1.3.0-rc"},
Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"excoveralls": {:hex, :excoveralls, "0.6.2", "0e993d096f1fbb6e70a3daced5c89aac066bda6bce57829622aa2d1e2b338cfb", [:mix], [{:exjsx, "~> 3.0", [hex: :exjsx, optional: false]}, {:hackney, ">= 0.12.0", [hex: :hackney, optional: false]}]},
"exjsx": {:hex, :exjsx, "3.2.1", "1bc5bf1e4fd249104178f0885030bcd75a4526f4d2a1e976f4b428d347614f0f", [:mix], [{:jsx, "~> 2.8.0", [hex: :jsx, optional: false]}]},
"hackney": {:hex, :hackney, "1.7.1", "e238c52c5df3c3b16ce613d3a51c7220a784d734879b1e231c9babd433ac1cb4", [:rebar3], [{:certifi, "1.0.0", [hex: :certifi, optional: false]}, {:idna, "4.0.0", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, optional: false]}]},
"httpoison": {:hex, :httpoison, "0.11.1", "d06c571274c0e77b6cc50e548db3fd7779f611fbed6681fd60a331f66c143a0b", [:mix], [{:hackney, "~> 1.7.0", [hex: :hackney, optional: false]}]},
"idna": {:hex, :idna, "4.0.0", "10aaa9f79d0b12cf0def53038547855b91144f1bfcc0ec73494f38bb7b9c4961", [:rebar3], []},
"jsx": {:hex, :jsx, "2.8.2", "7acc7d785b5abe8a6e9adbde926a24e481f29956dd8b4df49e3e4e7bcc92a018", [:mix, :rebar3], []},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], []},
Expand Down
9 changes: 9 additions & 0 deletions test/acceptance/dummy_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule PRM.DummyAcceptanceTest do
use PRM.Support.AcceptanceCase

test "api" do
"/api"
|> get!()
|> assert_status(404)
Copy link
Contributor

@gmile gmile Mar 21, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PavelVesnin can we make this check stronger and assert on an API that returns 200? I think /api/doctors should do exactly that.

end
end
47 changes: 47 additions & 0 deletions test/support/acceptance_case.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
defmodule PRM.Support.AcceptanceCase do
@moduledoc """
Acceptance test helper
"""
use ExUnit.CaseTemplate

using do
repo =
case System.get_env("CONTAINER_HTTP_PORT") do
nil -> PRM.Repo
_ -> nil
end

quote do
@tag acceptance: true
use EView.AcceptanceCase,
async: false,
otp_app: :prm,
endpoint: PRM.Web.Endpoint,
repo: unquote(repo),
headers: [{"content-type", "application/json"}]

def assert_validation_error(%HTTPoison.Response{body: body} = response, entry, type) do
assert %{
"meta" => %{"code" => 422},
"error" => %{
"message" => _,
"type" => "validation_failed",
"invalid" => [%{
"entry" => ^entry,
"entry_type" => ^type,
"rules" => ["required"]
}]
},
} = body

response
end

def assert_status(%HTTPoison.Response{status_code: status_code} = response, status) do
assert status == status_code
response
end

end
end
end
7 changes: 5 additions & 2 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
ExUnit.start()
if System.get_env("CONTAINER_HTTP_PORT") == nil do
ExUnit.configure(exclude: [acceptance: true])
Ecto.Adapters.SQL.Sandbox.mode(PRM.Repo, :manual)
end

Ecto.Adapters.SQL.Sandbox.mode(PRM.Repo, :manual)
ExUnit.start()