Skip to content

Commit

Permalink
Add Github Workflow for testing with docker-compose (#299)
Browse files Browse the repository at this point in the history
* Add Github Workflow for testing with docker-compose

* Use docker-compose instead of docker compose in workflow

* Try failing test in workflow

* Revert to working tests

* Rename Docker to CI in test.yaml

Co-authored-by: Paul Cretu <[email protected]>

* Update actions checkout to v4 from v2

Co-authored-by: Paul Cretu <[email protected]>

* Run tests on push to main

Co-authored-by: Paul Cretu <[email protected]>

* Rename test.yaml to ci.yaml. Uncomment 3000 port mapping

---------

Co-authored-by: Paul Cretu <[email protected]>
  • Loading branch information
skanderm and paulcretu authored Jan 5, 2024
1 parent f140144 commit 6955ccf
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Build containers
run: docker-compose build --build-arg MIX_ENV=test

- name: Start containers
run: docker-compose up -d db cache

- name: Run tests
run: docker-compose run web bash -c 'cd server && mix test'
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ ENV APP_HOME /app
RUN mkdir -p $APP_HOME
WORKDIR $APP_HOME

ARG MIX_ENV=dev
EXPOSE 3000
EXPOSE 4000
ENV PORT=4000 UI_PORT=3000 MIX_ENV=dev
ENV PORT=4000 UI_PORT=3000 MIX_ENV=${MIX_ENV}

# Create a new stage so that local dev setup can stop here
# Local dev mounts into the container so there's no point in adding/compiling
Expand Down
11 changes: 7 additions & 4 deletions server/config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ config :logger, level: :warning
# Configure your database
config :orcasite, Orcasite.Repo,
adapter: Ecto.Adapters.Postgres,
username: "postgres",
password: "postgres",
database: "orcasite_test#{System.get_env("MIX_TEST_PARTITION")}",
hostname: "localhost",
username: System.get_env("POSTGRES_USER") || "postgres",
password: System.get_env("POSTGRES_PASSWORD") || "postgres",
database:
System.get_env("POSTGRES_DATABASE") || "orcasite_test#{System.get_env("MIX_TEST_PARTITION")}",
port: System.get_env("POSTGRES_PORT") || 5432,
hostname: System.get_env("POSTGRES_HOST") || "localhost",
pool: Ecto.Adapters.SQL.Sandbox,
types: Orcasite.PostgresTypes,
pool_size: 10
Expand All @@ -32,6 +34,7 @@ config :orcasite, :cache_adapter, Nebulex.Adapters.Local

config :hammer,
backend: {Hammer.Backend.ETS, [expiry_ms: 60_000 * 60 * 4, cleanup_interval_ms: 60_000 * 10]}

config :orcasite, OrcasiteWeb.BasicAuth, username: "admin", password: "password"
config :ash_graphql, :policies, show_policy_breakdowns?: true
config :orcasite, Orcasite.Radio, graphql: [show_raised_errors?: true]
Expand Down
7 changes: 3 additions & 4 deletions server/test/orcasite_web/graphql/moderator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ defmodule OrcasiteWeb.ModeratorTest do
playlist_timestamp: DateTime.to_unix(DateTime.utc_now()),
player_offset: 5.54,
description: "Test detection",
listener_count: 1
listener_count: 1,
send_notifications: false
})
|> Orcasite.Radio.load!(:candidate)

Expand Down Expand Up @@ -90,9 +91,7 @@ defmodule OrcasiteWeb.ModeratorTest do

assert %{
"data" => %{
"notificationsForCandidate" => [
%{"id" => _} | _
]
"notificationsForCandidate" => []
}
} =
json_response(conn, 200)
Expand Down

0 comments on commit 6955ccf

Please sign in to comment.