-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_test.go
More file actions
35 lines (27 loc) · 859 Bytes
/
example_test.go
File metadata and controls
35 lines (27 loc) · 859 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package redefine_test
import (
"context"
"fmt"
"net"
"time"
"github.com/pboyd/redefine"
)
func ExampleFunc() {
redefine.Func(time.Now, func() time.Time {
return time.Date(2000, 1, 1, 17, 0, 0, 0, time.FixedZone("somewhere", -5))
})
defer redefine.Restore(time.Now)
fmt.Printf("It's %s\n", time.Now().Format("3:04 PM MST"))
// Output: It's 5:00 PM somewhere
}
type myResolver net.Resolver
func (*myResolver) LookupHost(context.Context, string) ([]string, error) {
return []string{"127.0.0.1"}, nil
}
func ExampleMethod() {
redefine.Method((*net.Resolver).LookupHost, (*myResolver).LookupHost)
defer redefine.Restore((*net.Resolver).LookupHost)
addrs, _ := net.DefaultResolver.LookupHost(context.Background(), "www.google.com")
fmt.Printf("www.google.com has addresses %v", addrs)
// Output: www.google.com has addresses [127.0.0.1]
}