| 1 |
package dnsutil |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"testing" |
| 6 |
) |
| 7 |
|
| 8 |
func TestSkip(t *testing.T) { |
| 9 |
testcases := []struct { |
| 10 |
in string |
| 11 |
n int |
| 12 |
dir skip |
| 13 |
out string |
| 14 |
}{ |
| 15 |
{"www.example.org.", 3, SkipForward, ""}, |
| 16 |
{"www.example.org.", 2, SkipForward, "org."}, |
| 17 |
{"www.example.org.", 1, SkipForward, "example.org."}, |
| 18 |
{"www.example.org.", 0, SkipForward, "www.example.org."}, |
| 19 |
|
| 20 |
{"www.example.org.", 3, SkipBackward, "www.example.org."}, |
| 21 |
{"www.example.org.", 2, SkipBackward, "example.org."}, |
| 22 |
{"www.example.org.", 1, SkipBackward, "org."}, |
| 23 |
{"www.example.org.", 0, SkipBackward, ""}, |
| 24 |
} |
| 25 |
for _, tc := range testcases { |
| 26 |
t.Run(fmt.Sprintf("%s%s%d", tc.in, |
| 27 |
func() string { |
| 28 |
if tc.dir == SkipForward { |
| 29 |
return "+" |
| 30 |
} |
| 31 |
return "-" |
| 32 |
}(), |
| 33 |
tc.n), |
| 34 |
func(t *testing.T) { |
| 35 |
x, _ := Skip(tc.in, tc.n, tc.dir) |
| 36 |
if x != tc.out { |
| 37 |
t.Fatalf("expected %s, got %s", tc.out, x) |
| 38 |
} |
| 39 |
}) |
| 40 |
} |
| 41 |
} |