mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-03-17 21:32:56 +01:00
* test: refactor NormalizeURL tests * feat(NormalizeURL): add 'ws://' prefix if url starts with 'localhost' * test(NormalizeURL): add 'ws://' prefix if url is localhost
37 lines
988 B
Go
37 lines
988 B
Go
package nostr
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
type urlTest struct {
|
|
url, expected string
|
|
}
|
|
|
|
var urlTests = []urlTest{
|
|
{"", ""},
|
|
{"wss://x.com/y", "wss://x.com/y"},
|
|
{"wss://x.com/y/", "wss://x.com/y"},
|
|
{"http://x.com/y", "ws://x.com/y"},
|
|
{NormalizeURL("http://x.com/y"), "ws://x.com/y"},
|
|
{NormalizeURL("wss://x.com"), "wss://x.com"},
|
|
{NormalizeURL("wss://x.com/"), "wss://x.com"},
|
|
{NormalizeURL(NormalizeURL(NormalizeURL("wss://x.com/"))), "wss://x.com"},
|
|
{"wss://x.com", "wss://x.com"},
|
|
{"wss://x.com/", "wss://x.com"},
|
|
{"x.com////", "wss://x.com"},
|
|
{"x.com/?x=23", "wss://x.com?x=23"},
|
|
{"localhost:4036", "ws://localhost:4036"},
|
|
{"localhost:4036/relay", "ws://localhost:4036/relay"},
|
|
{NormalizeURL("localhost:4036/relay"), "ws://localhost:4036/relay"},
|
|
}
|
|
|
|
func TestNormalizeURL(t *testing.T) {
|
|
|
|
for _, test := range urlTests {
|
|
if output := NormalizeURL(test.url); output != test.expected {
|
|
t.Errorf("Output '%s' not equal to expected '%s'", output, test.expected)
|
|
}
|
|
}
|
|
}
|