Adds tests across previously-uncovered or under-covered modules: - Mix tasks: backfill_checks, copy_mibs, import_mibs (new test files) - Status pages: StatusIncident changeset (new file) - Webhook signature verification on AgentReleaseWebhookController - CloudflareBanWorker: HTTP-stubbed success / 5xx / transport-error paths - FirmwareVersionFetcherWorker: stubbed perform/0 success + non-200 + tx error - Geoip.Import: production --production code path (HTTP-stubbed) - AgentLive.Show: superuser restart_agent + update_agent + non-superuser paths - NetworkMapLive: node_clicked, deep-link node, topology_updated PubSub - PreseemInsightsLive: toggle_select, deselect_all, filter, dismiss-twice - AlertQuery: 1-arity defaults variants - ProfileWatcher: yaml + reload-trigger event passthrough - MobileAuthController: verify_qr_token success + get/revoke session - HealthController: redis-configured branch - RedisHealthCheck: un-tag :integration tests now that Redis is local - FourOhFourTracker: un-skip module (Redis available) - PingExecutor: un-tag local-only tests + KeyError surface + clamp branch - CheckExecutorWorker: dispatch tcp/dns/ssl/ping branches - UserResetPasswordController: drop dead edit/update + their template Also removes dead code: edit/update actions on UserResetPasswordController and the unused edit.html.heex template — both routed via LiveView.
85 lines
2.6 KiB
Elixir
85 lines
2.6 KiB
Elixir
defmodule Mix.Tasks.Backfill.ChecksTest do
|
|
use Towerops.DataCase, async: false
|
|
|
|
import ExUnit.CaptureIO
|
|
import Towerops.AccountsFixtures
|
|
|
|
alias Mix.Tasks.Backfill.Checks
|
|
alias Towerops.Repo
|
|
alias Towerops.Snmp
|
|
|
|
setup do
|
|
user = user_fixture()
|
|
{:ok, org} = Towerops.Organizations.create_organization(%{name: "BFC-Org"}, user.id)
|
|
{:ok, site} = Towerops.Sites.create_site(%{name: "BFC-Site", organization_id: org.id})
|
|
%{org: org, site: site}
|
|
end
|
|
|
|
describe "run/1" do
|
|
test "prints zero-device summary when no SNMP-enabled devices exist" do
|
|
output = capture_io(fn -> Checks.run([]) end)
|
|
assert output =~ "Found 0 SNMP-enabled devices"
|
|
assert output =~ "Backfill complete"
|
|
end
|
|
|
|
test "skips devices with no snmp_device record", %{site: site, org: org} do
|
|
{:ok, _device} =
|
|
Towerops.Devices.create_device(%{
|
|
name: "NoSnmp",
|
|
ip_address: "10.1.1.1",
|
|
site_id: site.id,
|
|
organization_id: org.id,
|
|
snmp_enabled: true
|
|
})
|
|
|
|
output = capture_io(fn -> Checks.run([]) end)
|
|
assert output =~ "Found 1 SNMP-enabled devices"
|
|
assert output =~ "Skipping NoSnmp - no SNMP discovery data"
|
|
end
|
|
|
|
test "skips devices with snmp_device but no discovered entities",
|
|
%{site: site, org: org} do
|
|
{:ok, device} =
|
|
Towerops.Devices.create_device(%{
|
|
name: "EmptySnmp",
|
|
ip_address: "10.1.1.2",
|
|
site_id: site.id,
|
|
organization_id: org.id,
|
|
snmp_enabled: true
|
|
})
|
|
|
|
{:ok, _snmp} = Repo.insert(%Snmp.Device{device_id: device.id, sys_descr: "x"})
|
|
|
|
output = capture_io(fn -> Checks.run([]) end)
|
|
assert output =~ "Skipping EmptySnmp - no discovered entities"
|
|
end
|
|
|
|
test "dry-run reports without creating checks",
|
|
%{site: site, org: org} do
|
|
{:ok, device} =
|
|
Towerops.Devices.create_device(%{
|
|
name: "WithSensor",
|
|
ip_address: "10.1.1.3",
|
|
site_id: site.id,
|
|
organization_id: org.id,
|
|
snmp_enabled: true
|
|
})
|
|
|
|
{:ok, snmp} = Repo.insert(%Snmp.Device{device_id: device.id, sys_descr: "x"})
|
|
|
|
{:ok, _sensor} =
|
|
Repo.insert(%Snmp.Sensor{
|
|
snmp_device_id: snmp.id,
|
|
sensor_index: "1",
|
|
sensor_type: "temperature",
|
|
sensor_descr: "test",
|
|
sensor_oid: "1.3.6.1.2.1.1.1.0"
|
|
})
|
|
|
|
output = capture_io(fn -> Checks.run(["--dry-run"]) end)
|
|
assert output =~ "DRY RUN MODE"
|
|
assert output =~ "WithSensor"
|
|
assert output =~ "[DRY RUN] Would create"
|
|
end
|
|
end
|
|
end
|