Finish remove, also need test for signatures

This commit is contained in:
Miek Gieben 2012-10-15 08:56:40 +02:00
parent 76d5d8493f
commit 7305ca2b58
2 changed files with 9 additions and 3 deletions

View File

@ -281,13 +281,18 @@ func (z *Zone) Remove(r RR) error {
}
}
}
if remove && len(r.Header().Name) > 1 && r.Header().Name[0] == '*' && r.Header().Name[1] == '.' {
if !remove {
return nil
}
if len(r.Header().Name) > 1 && r.Header().Name[0] == '*' && r.Header().Name[1] == '.' {
z.Wildcard--
if z.Wildcard < 0 {
z.Wildcard = 0
}
}
// TODO(mg): what to do if the whole structure is empty? Set it to nil?
if len(z.Value.(*ZoneData).RR) == 0 && len(z.Value.(*ZoneData).Signatures) == 0 {
z.Radix.Remove(key)
}
return nil
}

View File

@ -24,7 +24,7 @@ func TestInsert(t *testing.T) {
z := NewZone("miek.nl.")
mx, _ := NewRR("foo.miek.nl. MX 10 mx.miek.nl.")
z.Insert(mx)
zd, exact := z.Find("foo.miek.nl.")
_, exact := z.Find("foo.miek.nl.")
if exact != true {
t.Fail() // insert broken?
}
@ -41,6 +41,7 @@ func TestRemove(t *testing.T) {
z.Remove(mx)
zd, exact = z.Find("foo.miek.nl.")
if exact != false {
println(zd.String())
t.Errorf("zd(%s) exact(%s) still exists", zd, exact) // it should no longer be in the zone
}
}