github.com/rakyll/go@v0.0.0-20170216000551-64c02460d703/src/net/cgo_unix_test.go (about) 1 // Copyright 2013 The Go Authors. 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 // +build cgo,!netgo 6 // +build darwin dragonfly freebsd linux netbsd openbsd solaris 7 8 package net 9 10 import ( 11 "context" 12 "testing" 13 ) 14 15 func TestCgoLookupIP(t *testing.T) { 16 ctx := context.Background() 17 _, err, ok := cgoLookupIP(ctx, "localhost") 18 if !ok { 19 t.Errorf("cgoLookupIP must not be a placeholder") 20 } 21 if err != nil { 22 t.Error(err) 23 } 24 } 25 26 func TestCgoLookupIPWithCancel(t *testing.T) { 27 ctx, cancel := context.WithCancel(context.Background()) 28 defer cancel() 29 _, err, ok := cgoLookupIP(ctx, "localhost") 30 if !ok { 31 t.Errorf("cgoLookupIP must not be a placeholder") 32 } 33 if err != nil { 34 t.Error(err) 35 } 36 } 37 38 func TestCgoLookupPort(t *testing.T) { 39 ctx := context.Background() 40 _, err, ok := cgoLookupPort(ctx, "tcp", "smtp") 41 if !ok { 42 t.Errorf("cgoLookupPort must not be a placeholder") 43 } 44 if err != nil { 45 t.Error(err) 46 } 47 } 48 49 func TestCgoLookupPortWithCancel(t *testing.T) { 50 ctx, cancel := context.WithCancel(context.Background()) 51 defer cancel() 52 _, err, ok := cgoLookupPort(ctx, "tcp", "smtp") 53 if !ok { 54 t.Errorf("cgoLookupPort must not be a placeholder") 55 } 56 if err != nil { 57 t.Error(err) 58 } 59 } 60 61 func TestCgoLookupPTR(t *testing.T) { 62 ctx := context.Background() 63 _, err, ok := cgoLookupPTR(ctx, "127.0.0.1") 64 if !ok { 65 t.Errorf("cgoLookupPTR must not be a placeholder") 66 } 67 if err != nil { 68 t.Error(err) 69 } 70 } 71 72 func TestCgoLookupPTRWithCancel(t *testing.T) { 73 ctx, cancel := context.WithCancel(context.Background()) 74 defer cancel() 75 _, err, ok := cgoLookupPTR(ctx, "127.0.0.1") 76 if !ok { 77 t.Errorf("cgoLookupPTR must not be a placeholder") 78 } 79 if err != nil { 80 t.Error(err) 81 } 82 }