From 55cf66418551b72c1a251680267693b083efc6d5 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 11 Jan 2018 02:54:24 +0100 Subject: domain mask --- mask_test.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 mask_test.go (limited to 'mask_test.go') diff --git a/mask_test.go b/mask_test.go new file mode 100644 index 0000000..87ba406 --- /dev/null +++ b/mask_test.go @@ -0,0 +1,45 @@ +package main + +import ( + "testing" +) + +func TestDomainMask(t *testing.T) { + testCases := []struct { + in, out string + }{ + {"192.0.2.1", "192.0.2.*"}, + {"gateway/ip.192.0.2.1", "*.192.0.2.1"}, + {"example.com", "example.com"}, + {"www.example.com", "*.example.com"}, + {"2001:db8::1", "2001:db8::*"}, + {"cloaked/user", "cloaked/user"}, + } + for _, tc := range testCases { + t.Run(tc.in, func(t *testing.T) { + out := domainMask(tc.in) + if out != tc.out { + t.Errorf("got %v; want %v", out, tc.out) + } + }) + } +} + +func TestMask(t *testing.T) { + testCases := []struct { + in, out string + }{ + {"~test@gateway/web/freenode/ip.192.0.2.1", "*!*test@*.192.0.2.1"}, + {"~test@192.0.2.1", "*!*test@192.0.2.*"}, + {"test@192.0.2.1", "*!*test@192.0.2.*"}, + {"bogus", "*!*bogus"}, + } + for _, tc := range testCases { + t.Run(tc.in, func(t *testing.T) { + out := mask(tc.in) + if out != tc.out { + t.Errorf("got %v; want %v", out, tc.out) + } + }) + } +} -- cgit v1.2.3