github.com/searKing/golang/go@v1.2.117/net/resolver/resolve_test.go (about) 1 // Copyright 2021 The searKing Author. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package resolver_test 6 7 import ( 8 "context" 9 "testing" 10 "time" 11 12 "github.com/searKing/golang/go/net/resolver" 13 _ "github.com/searKing/golang/go/net/resolver/dns" 14 _ "github.com/searKing/golang/go/net/resolver/passthrough" 15 _ "github.com/searKing/golang/go/net/resolver/unix" 16 ) 17 18 func TestResolveAddr(t *testing.T) { 19 20 testCases := []struct { 21 target string 22 expect string 23 }{ 24 { 25 target: "google.com", 26 expect: "google.com", 27 }, 28 { 29 target: "passthrough://a.server.com/google.com", 30 expect: "google.com", 31 }, 32 //{ 33 // target: "dns:///www.google.com", 34 // expect: "162.125.82.7:443", 35 //}, 36 //{ 37 // target: "dns://114.114.114.114/www.google.com", 38 // expect: "199.16.156.7:443", 39 //}, 40 { 41 target: "unix:///a/b/c", 42 expect: "a/b/c", 43 }, 44 } 45 46 for i, test := range testCases { 47 func() { 48 ctx, cancel := context.WithTimeout(context.Background(), time.Second) 49 defer cancel() 50 var target = test.target 51 addr, err := resolver.ResolveOneAddr(ctx, target) 52 if err != nil { 53 t.Fatalf("#%d: ResolveOneAddr failed: %s", i, err) 54 } 55 if addr.Addr != test.expect { 56 t.Fatalf("#%d: expected %s got %s", i, test.expect, addr.Addr) 57 } 58 t.Logf("#%d: addr: %s", i, addr.Addr) 59 }() 60 } 61 }