netbird/relay/server/relay_test.go
Zoltan Papp 0c039274a4
[relay] Feature/relay integration (#2244)
This update adds new relay integration for NetBird clients. The new relay is based on web sockets and listens on a single port.

- Adds new relay implementation with websocket with single port relaying mechanism
- refactor peer connection logic, allowing upgrade and downgrade from/to P2P connection
- peer connections are faster since it connects first to relay and then upgrades to P2P
- maintains compatibility with old clients by not using the new relay
- updates infrastructure scripts with new relay service
2024-09-08 12:06:14 +02:00

37 lines
1.5 KiB
Go

package server
import "testing"
func TestGetInstanceURL(t *testing.T) {
tests := []struct {
name string
exposedAddress string
tlsSupported bool
expectedURL string
expectError bool
}{
{"Valid address with TLS", "example.com", true, "rels://example.com", false},
{"Valid address without TLS", "example.com", false, "rel://example.com", false},
{"Valid address with scheme", "rel://example.com", false, "rel://example.com", false},
{"Valid address with non TLS scheme and TLS true", "rel://example.com", true, "rel://example.com", false},
{"Valid address with TLS scheme", "rels://example.com", true, "rels://example.com", false},
{"Valid address with TLS scheme and TLS false", "rels://example.com", false, "rels://example.com", false},
{"Valid address with TLS scheme and custom port", "rels://example.com:9300", true, "rels://example.com:9300", false},
{"Invalid address with multiple schemes", "rel://rels://example.com", false, "", true},
{"Invalid address with unsupported scheme", "http://example.com", false, "", true},
{"Invalid address format", "://example.com", false, "", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
url, err := getInstanceURL(tt.exposedAddress, tt.tlsSupported)
if (err != nil) != tt.expectError {
t.Errorf("expected error: %v, got: %v", tt.expectError, err)
}
if url != tt.expectedURL {
t.Errorf("expected URL: %s, got: %s", tt.expectedURL, url)
}
})
}
}