From 4f7191831117e836b81fbfb32b1168956b8b732c Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Mon, 29 Jul 2024 22:37:28 +0900 Subject: [PATCH] fix IsValidRelayURL --- utils.go | 3 --- utils_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 utils_test.go diff --git a/utils.go b/utils.go index 3d3b6ad..be20ca6 100644 --- a/utils.go +++ b/utils.go @@ -14,9 +14,6 @@ func IsValidRelayURL(u string) bool { if parsed.Scheme != "wss" && parsed.Scheme != "ws" { return false } - if len(strings.Split(parsed.Host, ".")) < 2 { - return false - } return true } diff --git a/utils_test.go b/utils_test.go new file mode 100644 index 0000000..6c39f8d --- /dev/null +++ b/utils_test.go @@ -0,0 +1,28 @@ +package nostr + +import ( + "testing" +) + +func TestIsValidRelayURL(t *testing.T) { + tests := []struct { + u string + want bool + }{ + {"ws://127.0.0.1", true}, + {"ws://localhost", true}, + {"wss://localhost", true}, + {"wss://relay.nostr.com", true}, + {"http://127.0.0.1", false}, + {"127.0.0.1", false}, + //{"wss://relay.nostr.com'", false}, + //{"wss://relay.nostr.com'hiphop", true}, + } + + for _, test := range tests { + got := IsValidRelayURL(test.u) + if got != test.want { + t.Errorf("IsValidRelayURL want %v for %q but got %v", test.want, test.u, got) + } + } +}