summaryrefslogtreecommitdiff
path: root/mask_test.go
blob: 87ba40633142c91826a6dbfa590738162d9e96b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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)
			}
		})
	}
}