towerops/test/mix/tasks/import_mibs_test.exs
Graham McIntire 2269f38fc5 test: lift coverage 78.42% → 79.59% with focused unit + integration tests
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.
2026-05-07 18:40:43 -05:00

103 lines
3.3 KiB
Elixir

defmodule Mix.Tasks.ImportMibsTest do
# Hardcoded `priv/mibs` destination forces us to chdir into a tmp directory.
use ExUnit.Case, async: false
import ExUnit.CaptureLog
alias Mix.Tasks.ImportMibs
@moduletag :tmp_dir
setup %{tmp_dir: tmp_dir} do
cwd = File.cwd!()
File.cd!(tmp_dir)
on_exit(fn -> File.cd!(cwd) end)
:ok
end
describe "run/1" do
test "raises when --source-path is missing" do
assert_raise RuntimeError, ~r/Missing --source-path/, fn ->
ImportMibs.run([])
end
end
test "raises when source path does not exist", %{tmp_dir: tmp_dir} do
missing = Path.join(tmp_dir, "missing")
assert_raise RuntimeError, ~r/Source directory not found/, fn ->
ImportMibs.run(["--source-path", missing])
end
end
test "imports all vendors and standard MIBs", %{tmp_dir: tmp_dir} do
source = Path.join(tmp_dir, "source")
File.mkdir_p!(Path.join(source, "mikrotik"))
File.mkdir_p!(Path.join(source, "cisco"))
File.mkdir_p!(Path.join(source, "lost+found"))
File.write!(Path.join(source, "STANDARD-MIB"), "STD\n")
File.write!(Path.join([source, "mikrotik", "MK-MIB"]), "MK\n")
File.write!(Path.join([source, "cisco", "C-MIB"]), "C\n")
File.write!(Path.join(source, ".hidden"), "skip\n")
capture_log(fn ->
ImportMibs.run(["--source-path", source])
end)
assert File.exists?(Path.join(["priv", "mibs", "STANDARD-MIB"]))
assert File.exists?(Path.join(["priv", "mibs", "mikrotik", "MK-MIB"]))
assert File.exists?(Path.join(["priv", "mibs", "cisco", "C-MIB"]))
refute File.exists?(Path.join(["priv", "mibs", "lost+found"]))
refute File.exists?(Path.join(["priv", "mibs", ".hidden"]))
end
test "--clean wipes priv/mibs before importing", %{tmp_dir: tmp_dir} do
source = Path.join(tmp_dir, "source")
File.mkdir_p!(source)
File.write!(Path.join(source, "NEW"), "new\n")
File.mkdir_p!("priv/mibs")
File.write!("priv/mibs/STALE", "stale\n")
capture_log(fn ->
ImportMibs.run(["--source-path", source, "--clean"])
end)
refute File.exists?("priv/mibs/STALE")
assert File.exists?("priv/mibs/NEW")
end
test "imports only the named vendors", %{tmp_dir: tmp_dir} do
source = Path.join(tmp_dir, "source")
File.mkdir_p!(Path.join(source, "cisco"))
File.mkdir_p!(Path.join(source, "ubiquiti"))
File.write!(Path.join([source, "cisco", "C-MIB"]), "C\n")
File.write!(Path.join([source, "ubiquiti", "U-MIB"]), "U\n")
capture_log(fn ->
ImportMibs.run([
"--source-path",
source,
"--vendors",
"cisco,does_not_exist"
])
end)
assert File.exists?(Path.join(["priv", "mibs", "cisco", "C-MIB"]))
refute File.exists?(Path.join(["priv", "mibs", "ubiquiti"]))
refute File.exists?(Path.join(["priv", "mibs", "does_not_exist"]))
end
test "treats empty --vendors as :all", %{tmp_dir: tmp_dir} do
source = Path.join(tmp_dir, "source")
File.mkdir_p!(source)
File.write!(Path.join(source, "ANY-MIB"), "x\n")
capture_log(fn ->
ImportMibs.run(["--source-path", source, "--vendors", ""])
end)
assert File.exists?(Path.join(["priv", "mibs", "ANY-MIB"]))
end
end
end