summaryrefslogtreecommitdiff
path: root/xN/xN_test.go
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2024-04-02 16:44:01 +0200
committerPřemysl Eric Janouch <p@janouch.name>2024-04-03 15:56:33 +0200
commit53ba996ec9c5c8fc64f66934d8c98509bd7ed06d (patch)
treefe396b25631e5a325c0e7d470dbb3e7e045d66b4 /xN/xN_test.go
parentd450c6cc5fe4caa2f9a1db3f0ec76c84b6a110af (diff)
downloadxK-53ba996ec9c5c8fc64f66934d8c98509bd7ed06d.tar.gz
xK-53ba996ec9c5c8fc64f66934d8c98509bd7ed06d.tar.xz
xK-53ba996ec9c5c8fc64f66934d8c98509bd7ed06d.zip
Add a simple IRC notifier utility
Diffstat (limited to 'xN/xN_test.go')
-rw-r--r--xN/xN_test.go98
1 files changed, 98 insertions, 0 deletions
diff --git a/xN/xN_test.go b/xN/xN_test.go
new file mode 100644
index 0000000..4755b39
--- /dev/null
+++ b/xN/xN_test.go
@@ -0,0 +1,98 @@
+//
+// Copyright (c) 2024, Přemysl Eric Janouch <p@janouch.name>
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+//
+
+package main
+
+import "testing"
+
+func TestParseURL(t *testing.T) {
+ for _, rawURL := range []string{
+ `irc:server/channel`,
+ `irc://server/channel,isnetwork`,
+ `ircs://ssl.ircnet.io`,
+ `ircs://ssl.ircnet.io/`,
+ `http://server/path`,
+ } {
+ if _, _, err := parse(rawURL, nil); err == nil {
+ t.Errorf("%q should not parse\n", rawURL)
+ }
+ }
+
+ for _, test := range []struct {
+ rawURL string
+ p parameters
+ }{
+ {
+ rawURL: `irc://uptime@localhost/%23watch?skipjoin&usenotice`,
+ p: parameters{
+ username: "uptime",
+ target: "#watch",
+ skipjoin: true,
+ usenotice: true,
+ },
+ },
+ {
+ rawURL: `ircs://ohayou@irc.libera.chat/john,isuser,isserver`,
+ p: parameters{
+ username: "ohayou",
+ target: "john",
+ isuser: true,
+ },
+ },
+ {
+ rawURL: `ircs://agent:Password123@irc.cia.gov:1337/#hq?key=123456`,
+ p: parameters{
+ username: "agent",
+ password: "Password123",
+ target: "#hq",
+ chankey: "123456",
+ },
+ },
+ } {
+ p, _, err := parse(test.rawURL, nil)
+ if err != nil {
+ t.Errorf("%q should parse, got: %s\n", test.rawURL, err)
+ continue
+ }
+ if p.username != test.p.username {
+ t.Errorf("%q: username: %v ≠ %v\n",
+ test.rawURL, p.username, test.p.username)
+ }
+ if p.password != test.p.password {
+ t.Errorf("%q: password: %v ≠ %v\n",
+ test.rawURL, p.password, test.p.password)
+ }
+ if p.target != test.p.target {
+ t.Errorf("%q: target: %v ≠ %v\n",
+ test.rawURL, p.target, test.p.target)
+ }
+ if p.isuser != test.p.isuser {
+ t.Errorf("%q: isuser: %v ≠ %v\n",
+ test.rawURL, p.isuser, test.p.isuser)
+ }
+ if p.chankey != test.p.chankey {
+ t.Errorf("%q: chankey: %v ≠ %v\n",
+ test.rawURL, p.chankey, test.p.chankey)
+ }
+ if p.skipjoin != test.p.skipjoin {
+ t.Errorf("%q: skipjoin: %v ≠ %v\n",
+ test.rawURL, p.skipjoin, test.p.skipjoin)
+ }
+ if p.usenotice != test.p.usenotice {
+ t.Errorf("%q: usenotice: %v ≠ %v\n",
+ test.rawURL, p.usenotice, test.p.usenotice)
+ }
+ }
+}