Skip to content
This repository has been archived by the owner on May 14, 2020. It is now read-only.

test: extend test to improve coverage #7

Merged
merged 1 commit into from
Dec 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (f *Filters) AddrBlocked(a ma.Multiaddr) bool {
}
netaddr, err := manet.ToNetAddr(maddr[0])
if err != nil {
// if we cant parse it, its probably not blocked
// if we can't parse it, it's probably not blocked
return false
}
netip := net.ParseIP(netaddr.String())
Expand Down
10 changes: 10 additions & 0 deletions filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ import (

func TestFilter(t *testing.T) {
f := NewFilters()

_, ipnet, _ := net.ParseCIDR("0.1.2.3/24")
f.AddDialFilter(ipnet)
filters := f.Filters()
if len(filters) != 1 {
t.Fatal("Expected only 1 filter")
}
f.Remove(filters[0])

for _, cidr := range []string{
"1.2.3.0/24",
"4.3.2.1/32",
Expand Down Expand Up @@ -39,6 +48,7 @@ func TestFilter(t *testing.T) {
"/ip4/4.3.2.2/udp/123",
"/ip6/fe00::1/tcp/321",
"/ip6/fc00::2/udp/321",
"",
} {
maddr, err := ma.NewMultiaddr(notBlocked)
if err != nil {
Expand Down