aboutsummaryrefslogtreecommitdiff
path: root/plugin/pkg/fall/fall_test.go
blob: 26cfbc2dc4afd1aeffd101ce25ba491ac5e28007 (plain) (blame)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
package fall

import "testing"

func TestEqual(t *testing.T) {
	var z F
	f := F{Zones: []string{"example.com."}}
	g := F{Zones: []string{"example.net."}}
	h := F{Zones: []string{"example.com."}}

	if !f.Equal(h) {
		t.Errorf("%v should equal %v", f, h)
	}

	if z.Equal(f) {
		t.Errorf("%v should not be equal to %v", z, f)
	}

	if f.Equal(g) {
		t.Errorf("%v should not be equal to %v", f, g)
	}
}

func TestZero(t *testing.T) {
	var f F
	if !f.Equal(Zero) {
		t.Errorf("F should be zero")
	}
}

func TestSetZonesFromArgs(t *testing.T) {
	var f F
	f.SetZonesFromArgs([]string{})
	if !f.Equal(Root) {
		t.Errorf("F should have the root zone")
	}

	f.SetZonesFromArgs([]string{"example.com", "example.net."})
	expected := F{Zones: []string{"example.com.", "example.net."}}
	if !f.Equal(expected) {
		t.Errorf("F should be %v but is %v", expected, f)
	}
}

func TestFallthrough(t *testing.T) {
	var fall F
	if fall.Through("foo.com.") {
		t.Errorf("Expected false, got true for zero fallthrough")
	}

	fall.SetZonesFromArgs([]string{})
	if !fall.Through("foo.net.") {
		t.Errorf("Expected true, got false for all zone fallthrough")
	}

	fall.SetZonesFromArgs([]string{"foo.com", "bar.com"})

	if fall.Through("foo.net.") {
		t.Errorf("Expected false, got true for non-matching fallthrough zone")
	}

	if !fall.Through("bar.com.") {
		t.Errorf("Expected true, got false for matching fallthrough zone")
	}
}