Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
rbino committed Nov 6, 2023
1 parent fd80c28 commit 78654eb
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 35 deletions.
2 changes: 1 addition & 1 deletion backend/config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ config :edgehog, Edgehog.Repo,
database: "edgehog_test#{System.get_env("MIX_TEST_PARTITION")}",
hostname: "localhost",
pool: Ecto.Adapters.SQL.Sandbox,
pool_size: 10
pool_size: 40

# We don't run a server during test. If one is required,
# you can enable the server option below.
Expand Down
32 changes: 25 additions & 7 deletions backend/lib/edgehog/astarte.ex
Original file line number Diff line number Diff line change
Expand Up @@ -601,10 +601,16 @@ defmodule Edgehog.Astarte do
end

def fetch_interface(%RealmManagement{} = client, interface_name, interface_major) do
with {:error, %APIError{status: 404}} <-
@interfaces_module.get(client, interface_name, interface_major) do
# We just convert a 404 status to :not_found, and return everything else as-is
{:error, :not_found}
case @interfaces_module.get(client, interface_name, interface_major) do
{:ok, %{"data" => interface_map}} ->
{:ok, interface_map}

{:error, %APIError{status: 404}} ->
# We just convert a 404 status to :not_found, and return all other errors as-is
{:error, :not_found}

{:error, other} ->
{:error, other}
end
end

Expand All @@ -622,9 +628,21 @@ defmodule Edgehog.Astarte do
end

def fetch_trigger(%RealmManagement{} = client, trigger_name) do
with {:error, %APIError{status: 404}} <- @triggers_module.get(client, trigger_name) do
# We just convert a 404 status to :not_found, and return everything else as-is
{:error, :not_found}
case @triggers_module.get(client, trigger_name) do
{:ok, %{"data" => trigger_map}} ->
{:ok, trigger_map}

{:error, %APIError{status: 404}} ->
# We just convert a 404 status to :not_found, and return all other errors as-is
{:error, :not_found}

# TODO: workaround due to the fact that currently Astarte RM API returns 500 for a
# non-existing trigger
{:error, %APIError{status: 500}} ->
{:error, :not_found}

{:error, other} ->
{:error, other}
end
end

Expand Down
2 changes: 1 addition & 1 deletion backend/lib/edgehog/astarte/realm/interfaces/behaviour.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ defmodule Edgehog.Astarte.Realm.Interfaces.Behaviour do
client :: RealmManagement.t(),
interface_name :: String.t(),
interface_major :: non_neg_integer
) :: {:ok, term()} | {:error, term()}
) :: {:ok, map()} | {:error, term()}

@callback create(client :: RealmManagement.t(), interface_json :: map()) ::
:ok | {:error, term()}
Expand Down
2 changes: 1 addition & 1 deletion backend/lib/edgehog/astarte/realm/triggers/behaviour.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule Edgehog.Astarte.Realm.Triggers.Behaviour do
alias Astarte.Client.RealmManagement

@callback get(client :: RealmManagement.t(), trigger_name :: String.t()) ::
{:ok, term()} | {:error, term()}
{:ok, map()} | {:error, term()}

@callback create(client :: RealmManagement.t(), trigger_json :: map()) ::
:ok | {:error, term()}
Expand Down
2 changes: 1 addition & 1 deletion backend/lib/edgehog/tenants/reconciler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ defmodule Edgehog.Tenants.Reconciler do
@reconcile_interval :timer.minutes(10)

def start_link(opts) do
GenServer.start_link(__MODULE__, opts)
GenServer.start_link(__MODULE__, opts, name: __MODULE__)
end

def reconcile_tenant(%Tenant{} = tenant) do
Expand Down

This file was deleted.

8 changes: 4 additions & 4 deletions backend/test/edgehog/tenants/reconciler/core_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ defmodule Edgehog.Tenants.Reconciler.CoreTest do

Edgehog.Astarte.Realm.InterfacesMock
|> expect(:get, fn ^client, ^interface_name, ^major ->
{:ok, interface_map}
{:ok, %{"data" => interface_map}}
end)
|> expect(:create, 0, fn _client, _interface_map -> :ok end)
|> expect(:update, 0, fn _client, _interface_name, _major, _interface_map -> :ok end)
Expand All @@ -146,7 +146,7 @@ defmodule Edgehog.Tenants.Reconciler.CoreTest do

Edgehog.Astarte.Realm.InterfacesMock
|> expect(:get, fn ^client, ^interface_name, ^major ->
{:ok, put_minor_version(interface_map, minor + 1)}
{:ok, %{"data" => put_minor_version(interface_map, minor + 1)}}
end)
|> expect(:create, 0, fn _client, _interface_map -> :ok end)
|> expect(:update, 0, fn _client, _interface_name, _major, _interface_map -> :ok end)
Expand All @@ -165,7 +165,7 @@ defmodule Edgehog.Tenants.Reconciler.CoreTest do

Edgehog.Astarte.Realm.InterfacesMock
|> expect(:get, fn ^client, ^interface_name, ^major ->
{:ok, put_minor_version(interface_map, minor - 1)}
{:ok, %{"data" => put_minor_version(interface_map, minor - 1)}}
end)
|> expect(:update, fn ^client, ^interface_name, ^major, ^interface_map ->
:ok
Expand Down Expand Up @@ -274,7 +274,7 @@ defmodule Edgehog.Tenants.Reconciler.CoreTest do

Edgehog.Astarte.Realm.TriggersMock
|> expect(:get, fn _client, _trigger_name ->
{:error, api_error(status: 500)}
{:error, api_error(status: 502)}
end)

assert_raise CaseClauseError, fn ->
Expand Down
2 changes: 1 addition & 1 deletion backend/test/support/mocks/astarte/realm/interfaces.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ defmodule Edgehog.Mocks.Astarte.Realm.Interfaces do

@impl true
def get(%RealmManagement{} = _client, interface_name, interface_major) do
{:ok, interface_map_fixture(name: interface_name, major: interface_major)}
{:ok, %{"data" => interface_map_fixture(name: interface_name, major: interface_major)}}
end

@impl true
Expand Down

0 comments on commit 78654eb

Please sign in to comment.