Created
October 26, 2017 12:59
-
-
Save xadhoom/e0bdd395dc29b498c034797c69f573ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule HPortalBackend.Test.IceTest do | |
use ExUnitProperties | |
alias HPortalBackend.Rtc.Ice | |
property "parses all possible ice config strings" do | |
check all foo <- generator() do | |
IO.inspect foo | |
end | |
end | |
def generator do | |
""" | |
general schema is | |
schema://[user:password@]host[:port][;transport=tcp|udp] | |
elements between [] are optional | |
""" | |
schema_g = one_of(["stun", "turn", "turns"] |> Enum.map(fn (x) -> constant(x) end)) | |
auth_g = one_of([constant(""), auth_generator()]) | |
port_g = one_of([constant(""), port_generator()]) | |
transport_g = one_of(["", ";transport=tcp", ";transport=udp"] |> Enum.map(fn (x) -> constant(x) end)) | |
gen all schema <- schema_g, | |
auth <- auth_g, | |
host <- host_generator(), | |
port <- port_g, | |
transport <- transport_g do | |
schema <> "://" <> auth <> host <> port <> transport | |
end | |
end | |
def port_generator do | |
gen all port <- one_of(0..65_535 |> Enum.map(fn (x) -> constant(x) end)) do | |
":" <> Integer.to_string(port) | |
end | |
end | |
def host_generator do | |
gen all host <- string(:printable), | |
String.trim(host) != "" do | |
host | |
end | |
end | |
def auth_generator do | |
gen all user <- string(:printable), | |
secret <- string(:printable), | |
String.trim(user) != "", | |
String.trim(secret) != "" do | |
user <> ":" <> secret <> "@" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment