Source file src/net/cgo_unix_test.go

     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 !netgo && ((cgo && unix) || darwin)
     6  
     7  package net
     8  
     9  import (
    10  	"context"
    11  	"internal/testenv"
    12  	"testing"
    13  )
    14  
    15  func TestCgoLookupIP(t *testing.T) {
    16  	defer dnsWaitGroup.Wait()
    17  	ctx := context.Background()
    18  	_, err := cgoLookupIP(ctx, "ip", "localhost")
    19  	if err != nil {
    20  		t.Error(err)
    21  	}
    22  }
    23  
    24  func TestCgoLookupIPWithCancel(t *testing.T) {
    25  	defer dnsWaitGroup.Wait()
    26  	ctx, cancel := context.WithCancel(context.Background())
    27  	defer cancel()
    28  	_, err := cgoLookupIP(ctx, "ip", "localhost")
    29  	if err != nil {
    30  		t.Error(err)
    31  	}
    32  }
    33  
    34  func TestCgoLookupPort(t *testing.T) {
    35  	defer dnsWaitGroup.Wait()
    36  	ctx := context.Background()
    37  	_, err := cgoLookupPort(ctx, "tcp", "smtp")
    38  	if err != nil {
    39  		t.Error(err)
    40  	}
    41  }
    42  
    43  func TestCgoLookupPortWithCancel(t *testing.T) {
    44  	defer dnsWaitGroup.Wait()
    45  	ctx, cancel := context.WithCancel(context.Background())
    46  	defer cancel()
    47  	_, err := cgoLookupPort(ctx, "tcp", "smtp")
    48  	if err != nil {
    49  		t.Error(err)
    50  	}
    51  }
    52  
    53  func TestCgoLookupPTR(t *testing.T) {
    54  	defer dnsWaitGroup.Wait()
    55  	ctx := context.Background()
    56  	_, err := cgoLookupPTR(ctx, "127.0.0.1")
    57  	if err != nil {
    58  		t.Error(err)
    59  	}
    60  }
    61  
    62  func TestCgoLookupPTRWithCancel(t *testing.T) {
    63  	defer dnsWaitGroup.Wait()
    64  	ctx, cancel := context.WithCancel(context.Background())
    65  	defer cancel()
    66  	_, err := cgoLookupPTR(ctx, "127.0.0.1")
    67  	if err != nil {
    68  		t.Error(err)
    69  	}
    70  }
    71  
    72  func TestCgoLookupCNAME(t *testing.T) {
    73  	mustHaveExternalNetwork(t)
    74  	testenv.SkipFlakyNet(t)
    75  	defer dnsWaitGroup.Wait()
    76  	if _, err := cgoLookupCNAME(t.Context(), "www.iana.org."); err != nil {
    77  		t.Error(err)
    78  	}
    79  }
    80  

View as plain text