]> Cypherpunks repositories - gostls13.git/commitdiff
net: add lookup IP hook for testing
authorMikio Hara <mikioh.mikioh@gmail.com>
Fri, 3 Apr 2015 16:11:10 +0000 (01:11 +0900)
committerMikio Hara <mikioh.mikioh@gmail.com>
Tue, 7 Apr 2015 02:34:42 +0000 (02:34 +0000)
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 <iant@golang.org>
src/net/hook.go [new file with mode: 0644]
src/net/lookup.go

diff --git a/src/net/hook.go b/src/net/hook.go
new file mode 100644 (file)
index 0000000..14dc19f
--- /dev/null
@@ -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) }
index 65abc81309f1cb46cf1ffceacaa687ad5afb005a..be4b0c2df6e336f6308c8b8058bbadc1852b9395 100644 (file)
@@ -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 {