Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a clear operation to suma service #2386

Merged
merged 1 commit into from
Mar 7, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,6 @@ defmodule Trento.Infrastructure.SoftwareUpdates.MockSuma do
update_date: "2024-02-26"
}
]}

def clear, do: :ok
end
9 changes: 9 additions & 0 deletions lib/trento/infrastructure/software_updates/suma.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ defmodule Trento.Infrastructure.SoftwareUpdates.Suma do
|> process_identifier
|> GenServer.call(:setup)

def clear(server_name \\ @default_name),
do:
server_name
|> process_identifier
|> GenServer.call(:clear)

@impl true
def get_system_id(fully_qualified_domain_name, server_name \\ @default_name),
do:
Expand All @@ -59,6 +65,9 @@ defmodule Trento.Infrastructure.SoftwareUpdates.Suma do
end
end

@impl true
def handle_call(:clear, _, _), do: {:reply, :ok, %State{}}

@impl true
def handle_call(request, _, %State{auth: nil} = state),
do: authenticate_and_handle(request, state)
Expand Down
52 changes: 52 additions & 0 deletions test/trento/infrastructure/software_updates/suma_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,58 @@ defmodule Trento.Infrastructure.SoftwareUpdates.SumaTest do
end
end

describe "clearing up integration service" do
test "should clear service state", %{
settings: %Settings{url: url, username: username, password: password, ca_cert: ca_cert}
} do
{:ok, _} = start_supervised({Suma, @test_integration_name})

expect(SumaApiMock, :login, fn _, _, _ -> successful_login_response() end)

assert :ok = Suma.setup(@test_integration_name)

expected_state = %State{
url: url,
username: username,
password: password,
ca_cert: ca_cert,
auth: "pxt-session-cookie=4321"
}

assert @test_integration_name
|> Suma.identify()
|> :sys.get_state() == expected_state

assert :ok = Suma.clear(@test_integration_name)

assert @test_integration_name
|> Suma.identify()
|> :sys.get_state() == %State{}
end

test "should support clearing an already empty service state" do
{:ok, _} = start_supervised({Suma, @test_integration_name})

empty_state = %State{
url: nil,
username: nil,
password: nil,
ca_cert: nil,
auth: nil
}

assert @test_integration_name
|> Suma.identify()
|> :sys.get_state() == empty_state

assert :ok = Suma.clear(@test_integration_name)

assert @test_integration_name
|> Suma.identify()
|> :sys.get_state() == empty_state
end
end

describe "Integration service" do
test "should return an error when a system id was not found for a given fqdn" do
{:ok, _} = start_supervised({Suma, @test_integration_name})
Expand Down
Loading