Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use net.IP.Equal to compare IP addresses #30

Merged
merged 1 commit into from
Apr 22, 2021
Merged
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
15 changes: 5 additions & 10 deletions resolve_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package madns

import (
"bytes"
"context"
"net"
"testing"
Expand Down Expand Up @@ -271,17 +270,13 @@ func TestCustomResolver(t *testing.T) {
t.Fatal(err)
}

sameIP := func(ip1, ip2 net.IPAddr) bool {
return bytes.Equal(ip1.IP, ip2.IP)
}

ctx := context.Background()
res, err := rslv.LookupIPAddr(ctx, "example.com")
if err != nil {
t.Fatal(err)
}

if len(res) != 1 || !sameIP(res[0], ip1) {
if len(res) != 1 || !res[0].IP.Equal(ip1.IP) {
t.Fatal("expected result to be ip1")
}

Expand All @@ -290,7 +285,7 @@ func TestCustomResolver(t *testing.T) {
t.Fatal(err)
}

if len(res) != 1 || !sameIP(res[0], ip2) {
if len(res) != 1 || !res[0].IP.Equal(ip2.IP) {
t.Fatal("expected result to be ip2")
}

Expand All @@ -299,7 +294,7 @@ func TestCustomResolver(t *testing.T) {
t.Fatal(err)
}

if len(res) != 1 || !sameIP(res[0], ip3) {
if len(res) != 1 || !res[0].IP.Equal(ip3.IP) {
t.Fatal("expected result to be ip3")
}

Expand All @@ -308,7 +303,7 @@ func TestCustomResolver(t *testing.T) {
t.Fatal(err)
}

if len(res) != 1 || !sameIP(res[0], ip4) {
if len(res) != 1 || !res[0].IP.Equal(ip4.IP) {
t.Fatal("expected result to be ip4")
}

Expand All @@ -317,7 +312,7 @@ func TestCustomResolver(t *testing.T) {
t.Fatal(err)
}

if len(res) != 1 || !sameIP(res[0], ip5) {
if len(res) != 1 || !res[0].IP.Equal(ip5.IP) {
t.Fatal("expected result to be ip5")
}
}