-
Notifications
You must be signed in to change notification settings - Fork 35
/
server_test.go
52 lines (40 loc) · 1.51 KB
/
server_test.go
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
46
47
48
49
50
51
52
package main
import "testing"
func TestGetRedirectSimple(t *testing.T) {
var redirect *Redirect
var err error
dnsTXT := []string{
"Redirects from /test/* to https://github.com/holic/*",
}
redirect, err = getRedirect(dnsTXT, "/test/")
assertEqual(t, err, nil)
assertEqual(t, redirect.Location, "https://github.com/holic/")
redirect, err = getRedirect(dnsTXT, "/test/success")
assertEqual(t, err, nil)
assertEqual(t, redirect.Location, "https://github.com/holic/success")
redirect, err = getRedirect(dnsTXT, "/should/fail")
assertEqual(t, err.Error(), "No paths matched")
}
func TestGetRedirectComplex(t *testing.T) {
// Tests that catchalls (even interspersed in the TXT records) apply
// only after more specific matches
var redirect *Redirect
var err error
dnsTXT := []string{
"Redirects from /test/* to https://github.com/holic/*",
"Redirects to https://github.com/holic",
"Redirects from /noglob/ to https://github.com/holic/noglob",
}
redirect, err = getRedirect(dnsTXT, "/")
assertEqual(t, err, nil)
assertEqual(t, redirect.Location, "https://github.com/holic")
redirect, err = getRedirect(dnsTXT, "/test/somepath")
assertEqual(t, err, nil)
assertEqual(t, redirect.Location, "https://github.com/holic/somepath")
redirect, err = getRedirect(dnsTXT, "/noglob/")
assertEqual(t, err, nil)
assertEqual(t, redirect.Location, "https://github.com/holic/noglob")
redirect, err = getRedirect(dnsTXT, "/catch/all")
assertEqual(t, err, nil)
assertEqual(t, redirect.Location, "https://github.com/holic")
}