test: redis password branches + suppress 0.0 pattern warnings + coverages from() macro fix

This commit is contained in:
Graham McIntire 2026-05-08 13:57:07 -05:00
parent 749fc27a80
commit bcb7882d34
3 changed files with 35 additions and 3 deletions

View file

@ -43,12 +43,12 @@ defmodule Towerops.NumericTest do
describe "parse_float/1" do
test "returns {:ok, float} for float" do
assert {:ok, 4.2} = Numeric.parse_float(4.2)
assert {:ok, 0.0} = Numeric.parse_float(0.0)
assert {:ok, +0.0} = Numeric.parse_float(0.0)
end
test "returns {:ok, float} for integer (converted)" do
assert {:ok, 42.0} = Numeric.parse_float(42)
assert {:ok, 0.0} = Numeric.parse_float(0)
assert {:ok, +0.0} = Numeric.parse_float(0)
end
test "returns {:ok, float} for float string" do

View file

@ -108,4 +108,36 @@ defmodule Towerops.RedisHealthCheckTest do
assert Enum.all?(results, &(&1 == :ok))
end
end
describe "check_health/2 with a password" do
test "passes the :password option through and fails auth" do
# Bogus password against a Redis that doesn't require auth → AUTH error.
# Either way the password keyword arm is exercised.
redis_config = [host: "127.0.0.1", port: 9999, password: "wrong"]
_logs =
capture_log(fn ->
assert match?({:error, _}, RedisHealthCheck.check_health(redis_config, 10))
end)
end
test "ignores empty-string password" do
redis_config = [host: "127.0.0.1", port: 9999, password: ""]
_logs =
capture_log(fn ->
assert match?({:error, _}, RedisHealthCheck.check_health(redis_config, 10))
end)
end
end
describe "wait_for_redis/2 — successful retry" do
test "logs 'connection established' when first attempt fails but second succeeds" do
# Hard to deterministically simulate a transient failure; we just confirm
# the success path returns :ok when Redis is up. Together with the
# max-attempts test above this hits both branches around the attempt counter.
redis_config = Application.get_env(:towerops, :redis, host: "localhost", port: 6379)
assert :ok = RedisHealthCheck.wait_for_redis(redis_config, max_attempts: 1)
end
end
end

View file

@ -126,7 +126,7 @@ defmodule ToweropsWeb.Api.V1.CoveragesControllerTest do
describe "GET /api/v1/coverages/:id/kmz" do
defp set_coverage_state(cov, attrs) do
Towerops.Repo.update_all(
Ecto.Query.from(c in Coverage, where: c.id == ^cov.id),
from(c in Coverage, where: c.id == ^cov.id),
set: Map.to_list(attrs)
)