Debian Codegraph @

libgo/go/net/cgo_unix_test.go

raw
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 //go:build cgo && !netgo && (aix || darwin || dragonfly || freebsd || hurd || linux || netbsd || openbsd || solaris)
6
7 package net
8
9 import (
10 "context"
11 "testing"
12 )
13
14 func TestCgoLookupIP(t *testing.T) {
15 defer dnsWaitGroup.Wait()
16 ctx := context.Background()
17 _, err, ok := cgoLookupIP(ctx, "ip", "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 defer dnsWaitGroup.Wait()
28 ctx, cancel := context.WithCancel(context.Background())
29 defer cancel()
30 _, err, ok := cgoLookupIP(ctx, "ip", "localhost")
31 if !ok {
32 t.Errorf("cgoLookupIP must not be a placeholder")
33 }
34 if err != nil {
35 t.Error(err)
36 }
37 }
38
39 func TestCgoLookupPort(t *testing.T) {
40 defer dnsWaitGroup.Wait()
41 ctx := context.Background()
42 _, err, ok := cgoLookupPort(ctx, "tcp", "smtp")
43 if !ok {
44 t.Errorf("cgoLookupPort must not be a placeholder")
45 }
46 if err != nil {
47 t.Error(err)
48 }
49 }
50
51 func TestCgoLookupPortWithCancel(t *testing.T) {
52 defer dnsWaitGroup.Wait()
53 ctx, cancel := context.WithCancel(context.Background())
54 defer cancel()
55 _, err, ok := cgoLookupPort(ctx, "tcp", "smtp")
56 if !ok {
57 t.Errorf("cgoLookupPort must not be a placeholder")
58 }
59 if err != nil {
60 t.Error(err)
61 }
62 }
63
64 func TestCgoLookupPTR(t *testing.T) {
65 defer dnsWaitGroup.Wait()
66 ctx := context.Background()
67 _, err, ok := cgoLookupPTR(ctx, "127.0.0.1")
68 if !ok {
69 t.Errorf("cgoLookupPTR must not be a placeholder")
70 }
71 if err != nil {
72 t.Error(err)
73 }
74 }
75
76 func TestCgoLookupPTRWithCancel(t *testing.T) {
77 defer dnsWaitGroup.Wait()
78 ctx, cancel := context.WithCancel(context.Background())
79 defer cancel()
80 _, err, ok := cgoLookupPTR(ctx, "127.0.0.1")
81 if !ok {
82 t.Errorf("cgoLookupPTR must not be a placeholder")
83 }
84 if err != nil {
85 t.Error(err)
86 }
87 }