package checker import "testing" func TestParseURI(t *testing.T) { cases := []struct { in string host string port uint16 transport Transport secure bool isTURN bool wantErr bool }{ {"stun:turn.example.com", "turn.example.com", 3478, TransportUDP, false, false, false}, {"stun:turn.example.com:3478", "turn.example.com", 3478, TransportUDP, false, false, false}, {"stuns:turn.example.com:5349", "turn.example.com", 5349, TransportTLS, true, false, false}, {"turn:turn.example.com:3478?transport=udp", "turn.example.com", 3478, TransportUDP, false, true, false}, {"turn:turn.example.com:3478?transport=tcp", "turn.example.com", 3478, TransportTCP, false, true, false}, {"turns:turn.example.com:5349?transport=tcp", "turn.example.com", 5349, TransportTLS, true, true, false}, {"turns:turn.example.com?transport=dtls", "turn.example.com", 5349, TransportDTLS, true, true, false}, {"http://example.com", "", 0, "", false, false, true}, {"stun:", "", 0, "", false, false, true}, } for _, tc := range cases { ep, err := parseURI(tc.in) if tc.wantErr { if err == nil { t.Errorf("%q: expected error, got nil", tc.in) } continue } if err != nil { t.Errorf("%q: unexpected error: %v", tc.in, err) continue } if ep.Host != tc.host || ep.Port != tc.port || ep.Transport != tc.transport || ep.Secure != tc.secure || ep.IsTURN != tc.isTURN { t.Errorf("%q: got %+v, want host=%s port=%d transport=%s secure=%v isTURN=%v", tc.in, ep, tc.host, tc.port, tc.transport, tc.secure, tc.isTURN) } } } func TestParseTransports(t *testing.T) { got := parseTransports("udp, TLS ,dtls") want := []Transport{TransportUDP, TransportTLS, TransportDTLS} if len(got) != len(want) { t.Fatalf("got %v want %v", got, want) } for i := range got { if got[i] != want[i] { t.Fatalf("index %d: got %s want %s", i, got[i], want[i]) } } } func TestRestAPICredentials(t *testing.T) { c := restAPICredentials("topsecret", "alice", "example.com", 0) if c.Username == "" || c.Password == "" { t.Fatalf("empty creds: %+v", c) } if c.Realm != "example.com" { t.Fatalf("realm mismatch: %s", c.Realm) } }