Phase 1: Foundation Types (100% complete)
- query_helpers: SQL LIKE sanitization with pipe operators
- numeric: Integer parsing with pattern matching guards
- result: Pure Elixir Result monad (map, and_then, unwrap_or)
Phase 2: Ecto Domain Types (100% complete)
- ip_address: IPv4/IPv6 validation using :inet directly
- mac_address: Multi-format MAC parsing (colon/hyphen/dot/compact)
- snmp_oid: OID parsing/manipulation with recursive pattern matching
All 198 tests passing across converted modules.
API changed from Gleam-style {:some/:none to idiomatic {:ok/:error.
Refactored parse_numeric_oid to use with statement, reducing nesting depth.
Reviewed-on: graham/towerops-web#196
31 lines
888 B
Elixir
31 lines
888 B
Elixir
defmodule Towerops.QueryHelpersTest do
|
|
use ExUnit.Case, async: true
|
|
|
|
alias Towerops.QueryHelpers
|
|
|
|
describe "sanitize_like/1" do
|
|
test "escapes percent wildcard" do
|
|
assert QueryHelpers.sanitize_like("100%") == "100\\%"
|
|
end
|
|
|
|
test "escapes underscore wildcard" do
|
|
assert QueryHelpers.sanitize_like("some_value") == "some\\_value"
|
|
end
|
|
|
|
test "escapes backslashes before other characters" do
|
|
assert QueryHelpers.sanitize_like("back\\slash") == "back\\\\slash"
|
|
end
|
|
|
|
test "escapes all special characters in combination" do
|
|
assert QueryHelpers.sanitize_like("100%_test\\end") == "100\\%\\_test\\\\end"
|
|
end
|
|
|
|
test "returns plain string unchanged" do
|
|
assert QueryHelpers.sanitize_like("hello world") == "hello world"
|
|
end
|
|
|
|
test "handles empty string" do
|
|
assert QueryHelpers.sanitize_like("") == ""
|
|
end
|
|
end
|
|
end
|