From 35b3db253c4c43912b2cb3cc85594b9c1be03895 Mon Sep 17 00:00:00 2001 From: Mikio Hara Date: Sat, 4 Apr 2015 01:11:10 +0900 Subject: [PATCH] net: add lookup IP hook for testing This change adds testHookLookIP to enable to inject DNS name to IP address mappings for Happ{y,yish,ier} Eyeballs dial testing. Change-Id: I8ac04a594e1e2bd77909528df0552889914a7790 Reviewed-on: https://go-review.googlesource.com/8399 Reviewed-by: Ian Lance Taylor --- src/net/hook.go | 7 +++++++ src/net/lookup.go | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 src/net/hook.go diff --git a/src/net/hook.go b/src/net/hook.go new file mode 100644 index 0000000000..14dc19f68f --- /dev/null +++ b/src/net/hook.go @@ -0,0 +1,7 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package net + +var testHookLookupIP = func(fn func(string) ([]IPAddr, error), host string) ([]IPAddr, error) { return fn(host) } diff --git a/src/net/lookup.go b/src/net/lookup.go index 65abc81309..be4b0c2df6 100644 --- a/src/net/lookup.go +++ b/src/net/lookup.go @@ -46,7 +46,7 @@ var lookupGroup singleflight // is always owned by the caller. func lookupIPMerge(host string) (addrs []IPAddr, err error) { addrsi, err, shared := lookupGroup.Do(host, func() (interface{}, error) { - return lookupIP(host) + return testHookLookupIP(lookupIP, host) }) return lookupIPReturn(addrsi, err, shared) } @@ -84,7 +84,7 @@ func lookupIPDeadline(host string, deadline time.Time) (addrs []IPAddr, err erro defer t.Stop() ch := lookupGroup.DoChan(host, func() (interface{}, error) { - return lookupIP(host) + return testHookLookupIP(lookupIP, host) }) select { -- 2.48.1