mirror of
https://github.com/coredns/coredns.git
synced 2025-10-31 18:23:13 -04:00
Allow overlapping Zones if binding addresses are different (#1530)
* add OverlapChecker, move the test of overlap AFTER the directive setup process, change key of configs to allow multiple same key * glitch when rebase. init of Config should include the default host * add tests for the registering of configuration rename multicast in 'unbound'. add comments on the validator * - merged zoneAddr and addrKey that are very similar - move maps of Validator to zoneAddr, avoinding need to have string representation of zoneaddr - moving key build for saving Config at Config side instead of dnsContext * - UT on saving config is now useless. * - cannot cleanup access to Configs after setup. Deferred function to Start, use it * - cleanup register unit tests. remove useless function * - address comments of review. name of validator, comments, simplify registerAndCheck * - fixes after review. renaming a function and a comment
This commit is contained in:
committed by
Miek Gieben
parent
455040c143
commit
9047bdf3a0
@@ -108,3 +108,72 @@ func TestSplitProtocolHostPort(t *testing.T) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
type checkCall struct {
|
||||
zone zoneAddr
|
||||
same bool
|
||||
overlap bool
|
||||
overlapKey string
|
||||
}
|
||||
|
||||
type checkTest struct {
|
||||
sequence []checkCall
|
||||
}
|
||||
|
||||
func TestOverlapAddressChecker(t *testing.T) {
|
||||
for i, test := range []checkTest{
|
||||
{sequence: []checkCall{
|
||||
{zoneAddr{Transport: "dns", Zone: ".", Address: "", Port: "53"}, false, false, ""},
|
||||
{zoneAddr{Transport: "dns", Zone: ".", Address: "", Port: "53"}, true, false, ""},
|
||||
},
|
||||
},
|
||||
{sequence: []checkCall{
|
||||
{zoneAddr{Transport: "dns", Zone: ".", Address: "", Port: "53"}, false, false, ""},
|
||||
{zoneAddr{Transport: "dns", Zone: ".", Address: "", Port: "54"}, false, false, ""},
|
||||
{zoneAddr{Transport: "dns", Zone: ".", Address: "127.0.0.1", Port: "53"}, false, true, "dns://.:53"},
|
||||
},
|
||||
},
|
||||
{sequence: []checkCall{
|
||||
{zoneAddr{Transport: "dns", Zone: ".", Address: "127.0.0.1", Port: "53"}, false, false, ""},
|
||||
{zoneAddr{Transport: "dns", Zone: ".", Address: "", Port: "54"}, false, false, ""},
|
||||
{zoneAddr{Transport: "dns", Zone: ".", Address: "127.0.0.1", Port: "53"}, true, false, ""},
|
||||
},
|
||||
},
|
||||
{sequence: []checkCall{
|
||||
{zoneAddr{Transport: "dns", Zone: ".", Address: "127.0.0.1", Port: "53"}, false, false, ""},
|
||||
{zoneAddr{Transport: "dns", Zone: ".", Address: "", Port: "54"}, false, false, ""},
|
||||
{zoneAddr{Transport: "dns", Zone: ".", Address: "128.0.0.1", Port: "53"}, false, false, ""},
|
||||
{zoneAddr{Transport: "dns", Zone: ".", Address: "129.0.0.1", Port: "53"}, false, false, ""},
|
||||
{zoneAddr{Transport: "dns", Zone: ".", Address: "", Port: "53"}, false, true, "dns://.:53 on 129.0.0.1"},
|
||||
},
|
||||
},
|
||||
{sequence: []checkCall{
|
||||
{zoneAddr{Transport: "dns", Zone: ".", Address: "127.0.0.1", Port: "53"}, false, false, ""},
|
||||
{zoneAddr{Transport: "dns", Zone: "com.", Address: "127.0.0.1", Port: "53"}, false, false, ""},
|
||||
{zoneAddr{Transport: "dns", Zone: "com.", Address: "", Port: "53"}, false, true, "dns://com.:53 on 127.0.0.1"},
|
||||
},
|
||||
},
|
||||
} {
|
||||
|
||||
checker := newOverlapZone()
|
||||
for _, call := range test.sequence {
|
||||
same, overlap := checker.registerAndCheck(call.zone)
|
||||
sZone := call.zone.String()
|
||||
if (same != nil) != call.same {
|
||||
t.Errorf("Test %d: error, for zone %s, 'same' (%v) has not the expected value (%v)", i, sZone, same != nil, call.same)
|
||||
}
|
||||
if same == nil {
|
||||
if (overlap != nil) != call.overlap {
|
||||
t.Errorf("Test %d: error, for zone %s, 'overlap' (%v) has not the expected value (%v)", i, sZone, overlap != nil, call.overlap)
|
||||
}
|
||||
if overlap != nil {
|
||||
if overlap.String() != call.overlapKey {
|
||||
t.Errorf("Test %d: error, for zone %s, 'overlap Key' (%v) has not the expected value (%v)", i, sZone, overlap.String(), call.overlapKey)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user