mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 10:43:17 -04:00
middleware/file: fix delegations (#376)
Fix the delegation handling in the *file* and *dnssec* middleware. Refactor tests a bit and show that they are failling. Add a Tree printer, cleanups and tests. Fix wildcard test - should get no answer from empty-non-terminal
This commit is contained in:
58
middleware/file/tree/print.go
Normal file
58
middleware/file/tree/print.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package tree
|
||||
|
||||
import "fmt"
|
||||
|
||||
// Print prints a Tree. Main use is to aid in debugging.
|
||||
func (t *Tree) Print() {
|
||||
if t.Root == nil {
|
||||
fmt.Println("<nil>")
|
||||
}
|
||||
t.Root.print()
|
||||
}
|
||||
|
||||
func (n *Node) print() {
|
||||
q := NewQueue()
|
||||
q.Push(n)
|
||||
|
||||
nodesInCurrentLevel := 1
|
||||
nodesInNextLevel := 0
|
||||
|
||||
for !q.Empty() {
|
||||
do := q.Pop()
|
||||
nodesInCurrentLevel--
|
||||
|
||||
if do != nil {
|
||||
fmt.Print(do.Elem.Name(), " ")
|
||||
q.Push(do.Left)
|
||||
q.Push(do.Right)
|
||||
nodesInNextLevel += 2
|
||||
}
|
||||
if nodesInCurrentLevel == 0 {
|
||||
fmt.Println()
|
||||
}
|
||||
nodesInCurrentLevel = nodesInNextLevel
|
||||
nodesInNextLevel = 0
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
type queue []*Node
|
||||
|
||||
func NewQueue() queue {
|
||||
q := queue([]*Node{})
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *queue) Push(n *Node) {
|
||||
*q = append(*q, n)
|
||||
}
|
||||
|
||||
func (q *queue) Pop() *Node {
|
||||
n := (*q)[0]
|
||||
*q = (*q)[1:]
|
||||
return n
|
||||
}
|
||||
|
||||
func (q *queue) Empty() bool {
|
||||
return len(*q) == 0
|
||||
}
|
||||
Reference in New Issue
Block a user