Skip to content

Commit

Permalink
net: add lookup IP hook for testing
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
cixtor committed Apr 7, 2015
1 parent bec4481 commit 35b3db2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/net/hook.go
Original file line number Diff line number Diff line change
@@ -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) }
4 changes: 2 additions & 2 deletions src/net/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 35b3db2

Please sign in to comment.