netutil: ctx-ize URLStringsEqual
Handles the case where the DNS entry will only be set up after etcd starts.
This commit is contained in:
@ -21,6 +21,9 @@ import (
|
||||
"reflect"
|
||||
"strconv"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func TestResolveTCPAddrs(t *testing.T) {
|
||||
@ -124,7 +127,9 @@ func TestResolveTCPAddrs(t *testing.T) {
|
||||
}
|
||||
return &net.TCPAddr{IP: net.ParseIP(tt.hostMap[host]), Port: i, Zone: ""}, nil
|
||||
}
|
||||
urls, err := resolveTCPAddrs(tt.urls)
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), time.Second)
|
||||
urls, err := resolveTCPAddrs(ctx, tt.urls)
|
||||
cancel()
|
||||
if tt.hasError {
|
||||
if err == nil {
|
||||
t.Errorf("expected error")
|
||||
@ -244,14 +249,14 @@ func TestURLsEqual(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
result := urlsEqual(test.a, test.b)
|
||||
result := urlsEqual(context.TODO(), test.a, test.b)
|
||||
if result != test.expect {
|
||||
t.Errorf("a:%v b:%v, expected %v but %v", test.a, test.b, test.expect, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
func TestURLStringsEqual(t *testing.T) {
|
||||
result := URLStringsEqual([]string{"http://127.0.0.1:8080"}, []string{"http://127.0.0.1:8080"})
|
||||
result := URLStringsEqual(context.TODO(), []string{"http://127.0.0.1:8080"}, []string{"http://127.0.0.1:8080"})
|
||||
if !result {
|
||||
t.Errorf("unexpected result %v", result)
|
||||
}
|
||||
|
Reference in New Issue
Block a user