mirror of
https://github.com/netbirdio/netbird.git
synced 2026-05-05 16:46:39 +00:00
67 lines
1.4 KiB
Go
67 lines
1.4 KiB
Go
package ws
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestPrepareURL(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
want string
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "rel scheme with non-standard port",
|
|
input: "rel://test-domain-2:45678",
|
|
want: "ws://test-domain-2:45678/relay",
|
|
},
|
|
{
|
|
name: "rels scheme with non-standard port",
|
|
input: "rels://test-domain-2:45678",
|
|
want: "wss://test-domain-2:45678/relay",
|
|
},
|
|
{
|
|
name: "rel scheme without port",
|
|
input: "rel://test-domain-2",
|
|
want: "ws://test-domain-2/relay",
|
|
},
|
|
{
|
|
name: "rels scheme without port",
|
|
input: "rels://test-domain-2",
|
|
want: "wss://test-domain-2/relay",
|
|
},
|
|
{
|
|
name: "rel scheme with IP and port",
|
|
input: "rel://1.2.3.4:45678",
|
|
want: "ws://1.2.3.4:45678/relay",
|
|
},
|
|
{
|
|
name: "rel scheme with hostname starting with rel",
|
|
input: "rel://relay.example.com:45678",
|
|
want: "ws://relay.example.com:45678/relay",
|
|
},
|
|
{
|
|
name: "unsupported scheme",
|
|
input: "http://test-domain-2:45678",
|
|
wantErr: true,
|
|
},
|
|
{
|
|
name: "no scheme",
|
|
input: "test-domain-2:45678",
|
|
wantErr: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got, err := prepareURL(tt.input)
|
|
if (err != nil) != tt.wantErr {
|
|
t.Fatalf("prepareURL(%q) err = %v, wantErr %v", tt.input, err, tt.wantErr)
|
|
}
|
|
if got != tt.want {
|
|
t.Errorf("prepareURL(%q) = %q, want %q", tt.input, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|