From c1b2cd2d36e166ef511414dda0083d3324833c15 Mon Sep 17 00:00:00 2001 From: Luka Camus Date: Wed, 11 Feb 2026 18:55:50 +0100 Subject: [PATCH 1/2] feat(workflows): try to launch tests in actions --- .github/workflows/back-end.yml | 37 +++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/.github/workflows/back-end.yml b/.github/workflows/back-end.yml index 134b01d..8452ad1 100644 --- a/.github/workflows/back-end.yml +++ b/.github/workflows/back-end.yml @@ -8,16 +8,27 @@ on: jobs: run-tests: runs-on: ubuntu-latest + + services: + postgres: + image: postgres:15 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: back_test + ports: + - 5432:5432 + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + + env: + MIX_ENV: test + DATABASE_URL: postgresql://postgres:postgres@localhost:5432/my_app_test + steps: - uses: actions/checkout@v4 - name: create .env file needed run: | - echo "System.put_env(\"DATABASE_URL\", \"${{ secrets.DATABASE_URL }}\")" > .env.dev.exs - echo "System.put_env(\"DB_USER\", \"${{ secrets.DB_USER }}\")" >> .env.dev.exs - echo "System.put_env(\"DB_PASSWORD\", \"${{ secrets.DB_PASSWORD }}\")" >> .env.dev.exs - echo "System.put_env(\"DB_NAME\", \"${{ secrets.DB_NAME }}\")" >> .env.dev.exs - echo "System.put_env(\"DB_HOST\", \"${{ secrets.DB_HOST }}\")" >> .env.dev.exs - echo "System.put_env(\"DB_PORT\", \"${{ secrets.DB_PORT }}\")" >> .env.dev.exs + echo "System.put_env(\"DATABASE_URL\", \"${{ env.DATABASE_URL }}\")" > .env.dev.exs - uses: erlef/setup-beam@v1 with: otp-version: "27" @@ -27,11 +38,17 @@ jobs: elixir --version mix local.hex --force # needed to get phoenix mix local.rebar --force # for telemetry - mix deps.get - # mix setup # should install dependencies and set migrations + mix setup # should install dependencies and set migrations - name: Check coding style run: mix format --check-formatted - name: Check if can compile run: mix compile - # - name: Run tests - # run: mix test + + - name: Run tests + run: mix test + + # - name: Upload coverage reports to Codecov + # uses: codecov/codecov-action@v5 + # with: + # token: ${{ secrets.CODECOV_TOKEN }} + # slug: Cellular-Automaton/back From 3bf79d82774d7a48b54c050cc7abb912efa9b5eb Mon Sep 17 00:00:00 2001 From: Luka Camus Date: Wed, 11 Feb 2026 19:09:24 +0100 Subject: [PATCH 2/2] feat(workflows): add coverage ? --- .github/workflows/back-end.yml | 17 +++++++++++------ config/test.exs | 7 +++++++ lib/back/users.ex | 2 -- mix.exs | 18 +++++++++++++++++- mix.lock | 3 ++- .../controllers/automaton_controller_test.exs | 1 - 6 files changed, 37 insertions(+), 11 deletions(-) diff --git a/.github/workflows/back-end.yml b/.github/workflows/back-end.yml index 8452ad1..0a1af15 100644 --- a/.github/workflows/back-end.yml +++ b/.github/workflows/back-end.yml @@ -45,10 +45,15 @@ jobs: run: mix compile - name: Run tests - run: mix test + run: mix test --cover --export-coverage default - # - name: Upload coverage reports to Codecov - # uses: codecov/codecov-action@v5 - # with: - # token: ${{ secrets.CODECOV_TOKEN }} - # slug: Cellular-Automaton/back + - name: Generate coverage + run: mix coveralls.json + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v5 + with: + token: ${{ secrets.CODECOV_TOKEN }} + slug: Cellular-Automaton/back + files: cover/cov_report.json + flags: unittests diff --git a/config/test.exs b/config/test.exs index 64c6f28..08dee59 100644 --- a/config/test.exs +++ b/config/test.exs @@ -20,6 +20,13 @@ config :back, BackWeb.Endpoint, secret_key_base: "i0YecfCJSKiPE86DscrFx0+YAfKJ78rCyRqeWj8XmiLrEynCN1DwKLhbHseJ42se", server: false +config :excoveralls, :excoveralls, + exclude: [ + "lib/back_web/**/*", + "lib/back_web/controllers/**/*", + "test/**/*" + ] + # In test we don't send emails config :back, Back.Mailer, adapter: Swoosh.Adapters.Test diff --git a/lib/back/users.ex b/lib/back/users.ex index 8cd1863..b0ed112 100644 --- a/lib/back/users.ex +++ b/lib/back/users.ex @@ -52,8 +52,6 @@ defmodule Back.Users do """ def create_user(attrs \\ %{}) do - IO.inspect(attrs, label: "Creating user with attrs") - # note: create user first, then add user_id to image {res, user} = diff --git a/mix.exs b/mix.exs index 3e9f07a..a603346 100644 --- a/mix.exs +++ b/mix.exs @@ -11,6 +11,21 @@ defmodule Back.MixProject do aliases: aliases(), deps: deps(), + # tests + test_coverage: [ + tool: ExCoveralls, + ignore_modules: [ + ~r/\.BackWeb\./ + ], + export: "cov_report" + ], + preferred_cli_env: [ + coveralls: :test, + "coveralls.detail": :test, + "coveralls.html": :test, + "coveralls.json": :test + ], + # Docs name: "CAMI-Back", source_url: "https://github.com/Cellular-Automaton/back", @@ -63,7 +78,8 @@ defmodule Back.MixProject do {:gettext, "~> 0.20"}, {:jason, "~> 1.2"}, {:dns_cluster, "~> 0.1.1"}, - {:bandit, "~> 1.5"} + {:bandit, "~> 1.5"}, + {:excoveralls, "~> 0.18", only: :test} ] end diff --git a/mix.lock b/mix.lock index 4464a31..06a0300 100644 --- a/mix.lock +++ b/mix.lock @@ -1,7 +1,7 @@ %{ "argon2_elixir": {:hex, :argon2_elixir, "2.4.1", "edb27bdd326bc738f3e4614eddc2f73507be6fedc9533c6bcc6f15bbac9c85cc", [:make, :mix], [{:comeonin, "~> 5.3", [hex: :comeonin, repo: "hexpm", optional: false]}, {:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "0e21f52a373739d00bdfd5fe6da2f04eea623cb4f66899f7526dd9db03903d9f"}, "bandit": {:hex, :bandit, "1.6.11", "2fbadd60c95310eefb4ba7f1e58810aa8956e18c664a3b2029d57edb7d28d410", [:mix], [{:hpax, "~> 1.0", [hex: :hpax, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:thousand_island, "~> 1.0", [hex: :thousand_island, repo: "hexpm", optional: false]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "543f3f06b4721619a1220bed743aa77bf7ecc9c093ba9fab9229ff6b99eacc65"}, - "castore": {:hex, :castore, "1.0.12", "053f0e32700cbec356280c0e835df425a3be4bc1e0627b714330ad9d0f05497f", [:mix], [], "hexpm", "3dca286b2186055ba0c9449b4e95b97bf1b57b47c1f2644555879e659960c224"}, + "castore": {:hex, :castore, "1.0.17", "4f9770d2d45fbd91dcf6bd404cf64e7e58fed04fadda0923dc32acca0badffa2", [:mix], [], "hexpm", "12d24b9d80b910dd3953e165636d68f147a31db945d2dcb9365e441f8b5351e5"}, "comeonin": {:hex, :comeonin, "5.5.1", "5113e5f3800799787de08a6e0db307133850e635d34e9fab23c70b6501669510", [:mix], [], "hexpm", "65aac8f19938145377cee73973f192c5645873dcf550a8a6b18187d17c13ccdb"}, "cors_plug": {:hex, :cors_plug, "3.0.3", "7c3ac52b39624bc616db2e937c282f3f623f25f8d550068b6710e58d04a0e330", [:mix], [{:plug, "~> 1.13", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "3f2d759e8c272ed3835fab2ef11b46bddab8c1ab9528167bd463b6452edf830d"}, "db_connection": {:hex, :db_connection, "2.7.0", "b99faa9291bb09892c7da373bb82cba59aefa9b36300f6145c5f201c7adf48ec", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "dcf08f31b2701f857dfc787fbad78223d61a32204f217f15e881dd93e4bdd3ff"}, @@ -14,6 +14,7 @@ "elixir_make": {:hex, :elixir_make, "0.9.0", "6484b3cd8c0cee58f09f05ecaf1a140a8c97670671a6a0e7ab4dc326c3109726", [:mix], [], "hexpm", "db23d4fd8b757462ad02f8aa73431a426fe6671c80b200d9710caf3d1dd0ffdb"}, "ex_doc": {:hex, :ex_doc, "0.38.2", "504d25eef296b4dec3b8e33e810bc8b5344d565998cd83914ffe1b8503737c02", [:mix], [{:earmark_parser, "~> 1.4.44", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "732f2d972e42c116a70802f9898c51b54916e542cc50968ac6980512ec90f42b"}, "ex_json_schema": {:hex, :ex_json_schema, "0.7.4", "09eb5b0c8184e5702bc89625a9d0c05c7a0a845d382e9f6f406a0fc1c9a8cc3f", [:mix], [], "hexpm", "45c67fa840f0d719a2b5578126dc29bcdc1f92499c0f61bcb8a3bcb5935f9684"}, + "excoveralls": {:hex, :excoveralls, "0.18.5", "e229d0a65982613332ec30f07940038fe451a2e5b29bce2a5022165f0c9b157e", [:mix], [{:castore, "~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "523fe8a15603f86d64852aab2abe8ddbd78e68579c8525ae765facc5eae01562"}, "expo": {:hex, :expo, "1.1.0", "f7b9ed7fb5745ebe1eeedf3d6f29226c5dd52897ac67c0f8af62a07e661e5c75", [:mix], [], "hexpm", "fbadf93f4700fb44c331362177bdca9eeb8097e8b0ef525c9cc501cb9917c960"}, "finch": {:hex, :finch, "0.19.0", "c644641491ea854fc5c1bbaef36bfc764e3f08e7185e1f084e35e0672241b76d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.6.2 or ~> 1.7", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 1.1", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "fc5324ce209125d1e2fa0fcd2634601c52a787aff1cd33ee833664a5af4ea2b6"}, "gettext": {:hex, :gettext, "0.26.2", "5978aa7b21fada6deabf1f6341ddba50bc69c999e812211903b169799208f2a8", [:mix], [{:expo, "~> 0.5.1 or ~> 1.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "aa978504bcf76511efdc22d580ba08e2279caab1066b76bb9aa81c4a1e0a32a5"}, diff --git a/test/back_web/controllers/automaton_controller_test.exs b/test/back_web/controllers/automaton_controller_test.exs index 70659db..2529159 100644 --- a/test/back_web/controllers/automaton_controller_test.exs +++ b/test/back_web/controllers/automaton_controller_test.exs @@ -24,7 +24,6 @@ defmodule BackWeb.AutomatonControllerTest do end describe "index" do - @tag :skip test "lists all automaton", %{conn: conn} do conn = get(conn, ~p"/api/automaton") assert json_response(conn, 200)["data"] == []