From 7fcfbb265901d1b4a35652e745400255aca22fc2 Mon Sep 17 00:00:00 2001 From: arbulu89 Date: Mon, 22 Apr 2024 16:07:11 +0200 Subject: [PATCH] Dispatch unknown health on batch auth error --- lib/trento/software_updates/discovery.ex | 12 ++++++++++-- .../software_updates/discovery_test.exs | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/trento/software_updates/discovery.ex b/lib/trento/software_updates/discovery.ex index 5c11a3d068..73f6f1caca 100644 --- a/lib/trento/software_updates/discovery.ex +++ b/lib/trento/software_updates/discovery.ex @@ -106,8 +106,16 @@ defmodule Trento.SoftwareUpdates.Discovery do end end - defp discover_host_software_updates(_, _, {:error, error}), - do: {:error, error} + defp discover_host_software_updates(host_id, _, {:error, error}) do + commanded().dispatch( + CompleteSoftwareUpdatesDiscovery.new!(%{ + host_id: host_id, + health: SoftwareUpdatesHealth.unknown() + }) + ) + + {:error, error} + end defp discover_host_software_updates(host_id, fully_qualified_domain_name, _), do: discover_host_software_updates(host_id, fully_qualified_domain_name) diff --git a/test/trento/software_updates/discovery_test.exs b/test/trento/software_updates/discovery_test.exs index 2ccbf8cc2c..94f7ee5b06 100644 --- a/test/trento/software_updates/discovery_test.exs +++ b/test/trento/software_updates/discovery_test.exs @@ -158,6 +158,25 @@ defmodule Trento.SoftwareUpdates.DiscoveryTest do [%{id: host_id1}, %{id: host_id2}] = insert_list(2, :host) + expect( + Trento.Commanded.Mock, + :dispatch, + 2, + fn + %CompleteSoftwareUpdatesDiscovery{ + host_id: ^host_id1, + health: SoftwareUpdatesHealth.unknown() + } -> + :ok + + %CompleteSoftwareUpdatesDiscovery{ + host_id: ^host_id2, + health: SoftwareUpdatesHealth.unknown() + } -> + :ok + end + ) + {:ok, {[], errored_discoveries}} = Discovery.discover_software_updates() Enum.each([host_id1, host_id2], fn host_id ->