-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(DNSConfig): allow to remove entries
Part of ooni/probe#2029
- Loading branch information
1 parent
db1220e
commit 831de45
Showing
3 changed files
with
67 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package netem | ||
|
||
import ( | ||
"net" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestDNSConfig(t *testing.T) { | ||
t.Run("removing a nonexisting record does not cause any issue", func(t *testing.T) { | ||
dc := NewDNSConfig() | ||
dc.RemoveRecord("www.example.com") | ||
}) | ||
|
||
t.Run("we can remove a previously added record", func(t *testing.T) { | ||
dc := NewDNSConfig() | ||
|
||
t.Run("the record should be there once we have added it", func(t *testing.T) { | ||
if err := dc.AddRecord("www.example.com", "www1.example.com", "1.2.3.4", "4.5.6.7"); err != nil { | ||
t.Fatal(err) | ||
} | ||
rec, good := dc.Lookup("www.example.com") | ||
if !good { | ||
t.Fatal("the record is not there") | ||
} | ||
expect := &DNSRecord{ | ||
A: []net.IP{ | ||
net.IPv4(1, 2, 3, 4), | ||
net.IPv4(4, 5, 6, 7), | ||
}, | ||
CNAME: "www1.example.com.", | ||
} | ||
if diff := cmp.Diff(expect, rec); diff != "" { | ||
t.Fatal(diff) | ||
} | ||
|
||
t.Run("the record should disappear once we have removed it", func(t *testing.T) { | ||
dc.RemoveRecord("www.example.com") | ||
rec, good := dc.Lookup("www.example.com") | ||
if good { | ||
t.Fatal("expected the record to be nonexistent") | ||
} | ||
if rec != nil { | ||
t.Fatal("expected a nil record") | ||
} | ||
}) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters