towerops/test/towerops_web/channels/agent_channel_check_proto_test.exs
2026-06-15 11:15:46 -05:00

85 lines
2.2 KiB
Elixir

defmodule ToweropsWeb.AgentChannelCheckProtoTest do
use ExUnit.Case, async: true
alias Towerops.Agent.Check, as: CheckProto
alias Towerops.Agent.CheckList
alias Towerops.Agent.DnsCheckConfig
alias Towerops.Agent.HttpCheckConfig
alias Towerops.Agent.SslCheckConfig
alias Towerops.Agent.TcpCheckConfig
describe "Check protobuf encoding" do
test "encodes HTTP check correctly" do
check = %CheckProto{
id: "test-id",
check_type: "http",
interval_seconds: 60,
timeout_ms: 5000,
http: %HttpCheckConfig{
url: "https://example.com",
method: "GET",
expected_status: 200,
verify_ssl: true,
regex: "",
follow_redirects: true
}
}
binary = CheckList.encode(%CheckList{checks: [check]})
assert is_binary(binary) and byte_size(binary) > 0
end
test "encodes TCP check correctly" do
check = %CheckProto{
id: "test-id",
check_type: "tcp",
interval_seconds: 60,
timeout_ms: 5000,
tcp: %TcpCheckConfig{
host: "example.com",
port: 443,
send: "",
expect: ""
}
}
binary = CheckList.encode(%CheckList{checks: [check]})
assert is_binary(binary) and byte_size(binary) > 0
end
test "encodes DNS check correctly" do
check = %CheckProto{
id: "test-id",
check_type: "dns",
interval_seconds: 60,
timeout_ms: 5000,
dns: %DnsCheckConfig{
hostname: "example.com",
server: "8.8.8.8",
record_type: "A",
expected: "1.2.3.4"
}
}
binary = CheckList.encode(%CheckList{checks: [check]})
assert is_binary(binary) and byte_size(binary) > 0
end
test "encodes SSL check correctly" do
check = %CheckProto{
id: "test-id",
check_type: "ssl",
interval_seconds: 60,
timeout_ms: 5000,
ssl: %SslCheckConfig{
host: "example.com",
port: 443,
warning_days: 30
}
}
binary = CheckList.encode(%CheckList{checks: [check]})
assert is_binary(binary) and byte_size(binary) > 0
end
end
end