noahsettersten commited on
Commit
82cacde
1 Parent(s): ee18265

ci: Configure test environment for Postgres on CI

Browse files
Files changed (2) hide show
  1. .github/workflows/test.yml +10 -0
  2. config/test.exs +12 -5
.github/workflows/test.yml CHANGED
@@ -6,6 +6,9 @@ on:
6
  pull_request:
7
  branches: ["main"]
8
 
 
 
 
9
  jobs:
10
  test:
11
  name: Test codebase
@@ -14,11 +17,16 @@ jobs:
14
  services:
15
  postgres:
16
  image: postgres
 
 
 
17
  options: >-
18
  --health-cmd pg_isready
19
  --health-interval 10s
20
  --health-timeout 5s
21
  --health-retries 5
 
 
22
 
23
  steps:
24
  - name: Checkout code
@@ -41,4 +49,6 @@ jobs:
41
  run: mix deps.get
42
 
43
  - name: Run tests
 
 
44
  run: mix test
 
6
  pull_request:
7
  branches: ["main"]
8
 
9
+ env:
10
+ MIX_ENV: test
11
+
12
  jobs:
13
  test:
14
  name: Test codebase
 
17
  services:
18
  postgres:
19
  image: postgres
20
+ env:
21
+ POSTGRES_USERNAME: postgres
22
+ POSTGRES_PASSWORD: postgres
23
  options: >-
24
  --health-cmd pg_isready
25
  --health-interval 10s
26
  --health-timeout 5s
27
  --health-retries 5
28
+ ports:
29
+ - 5432:5432
30
 
31
  steps:
32
  - name: Checkout code
 
49
  run: mix deps.get
50
 
51
  - name: Run tests
52
+ env:
53
+ DATABASE_URL: postgresql://postgres:postgres@localhost/medical_transcription_test
54
  run: mix test
config/test.exs CHANGED
@@ -5,11 +5,18 @@ import Config
5
  # The MIX_TEST_PARTITION environment variable can be used
6
  # to provide built-in test partitioning in CI environment.
7
  # Run `mix help test` for more information.
8
- config :medical_transcription, MedicalTranscription.Repo,
9
- hostname: "localhost",
10
- database: "medical_transcription_test#{System.get_env("MIX_TEST_PARTITION")}",
11
- pool: Ecto.Adapters.SQL.Sandbox,
12
- pool_size: 10
 
 
 
 
 
 
 
13
 
14
  # We don't run a server during test. If one is required,
15
  # you can enable the server option below.
 
5
  # The MIX_TEST_PARTITION environment variable can be used
6
  # to provide built-in test partitioning in CI environment.
7
  # Run `mix help test` for more information.
8
+ if System.get_env("DATABASE_URL") do
9
+ config :medical_transcription, MedicalTranscription.Repo,
10
+ url: System.get_env("DATABASE_URL"),
11
+ pool: Ecto.Adapters.SQL.Sandbox,
12
+ pool_size: 10
13
+ else
14
+ config :medical_transcription, MedicalTranscription.Repo,
15
+ hostname: "localhost",
16
+ database: "medical_transcription_test#{System.get_env("MIX_TEST_PARTITION")}",
17
+ pool: Ecto.Adapters.SQL.Sandbox,
18
+ pool_size: 10
19
+ end
20
 
21
  # We don't run a server during test. If one is required,
22
  # you can enable the server option below.