Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: CI

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

permissions:
contents: read

jobs:
test:
name: Build and Test
runs-on: ubuntu-latest

env:
MIX_ENV: test
ELIXIR_VERSION: "1.17.3"
OTP_VERSION: "27.2"

steps:
- uses: actions/checkout@v4

- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: ${{ env.ELIXIR_VERSION }}
otp-version: ${{ env.OTP_VERSION }}

- name: Cache deps
uses: actions/cache@v4
with:
path: |
deps
_build
key: ${{ runner.os }}-mix-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ hashFiles('mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-

- name: Install dependencies
run: mix deps.get

- name: Compile
run: mix compile --warnings-as-errors

- name: Run tests
run: mix test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
/deps/
/data.db
/data.db-*
/test_data.db
/test_data.db-*
erl_crash.dump

# Generated files
Expand Down
2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Config

config :items_api, ItemsApi.Repo,
database: ":memory:",
database: "./test_data.db",
pool: Ecto.Adapters.SQL.Sandbox
7 changes: 5 additions & 2 deletions lib/items_api/repo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ defmodule ItemsApi.Repo do
adapter: Ecto.Adapters.SQLite3

def init(_type, config) do
config = Keyword.put(config, :database, "./data.db")
{:ok, config}
database =
System.get_env("DATABASE_PATH") ||
Keyword.get(config, :database, "./data.db")

{:ok, Keyword.put(config, :database, database)}
end
end
23 changes: 23 additions & 0 deletions test/items_api/repo_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
defmodule ItemsApi.RepoTest do
use ExUnit.Case, async: false

setup do
:ok = Ecto.Adapters.SQL.Sandbox.checkout(ItemsApi.Repo)
:ok
end

describe "Repo" do
test "is running and accepting queries" do
assert {:ok, %{rows: [[1]]}} = Ecto.Adapters.SQL.query(ItemsApi.Repo, "SELECT 1")
end

test "uses SQLite3 adapter" do
assert ItemsApi.Repo.__adapter__() == Ecto.Adapters.SQLite3
end

test "has otp_app set to :items_api" do
config = ItemsApi.Repo.config()
assert config[:otp_app] == :items_api
end
end
end
Loading