2013-12-19 07:40:10 +09:00
|
|
|
// Copyright 2013 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2023-05-02 14:17:54 +00:00
|
|
|
//go:build !netgo && ((cgo && unix) || darwin)
|
2013-12-19 07:40:10 +09:00
|
|
|
|
|
|
|
package net
|
|
|
|
|
2016-04-14 17:47:25 -07:00
|
|
|
import (
|
|
|
|
"context"
|
2025-08-23 04:55:42 +08:00
|
|
|
"internal/testenv"
|
2016-04-14 17:47:25 -07:00
|
|
|
"testing"
|
|
|
|
)
|
2013-12-19 07:40:10 +09:00
|
|
|
|
|
|
|
func TestCgoLookupIP(t *testing.T) {
|
2017-12-07 20:30:28 -08:00
|
|
|
defer dnsWaitGroup.Wait()
|
2016-05-08 18:17:59 -07:00
|
|
|
ctx := context.Background()
|
2023-05-02 14:17:54 +00:00
|
|
|
_, err := cgoLookupIP(ctx, "ip", "localhost")
|
2013-12-19 07:40:10 +09:00
|
|
|
if err != nil {
|
2015-05-01 12:38:42 +09:00
|
|
|
t.Error(err)
|
2013-12-19 07:40:10 +09:00
|
|
|
}
|
2016-05-08 18:17:59 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCgoLookupIPWithCancel(t *testing.T) {
|
2017-12-07 20:30:28 -08:00
|
|
|
defer dnsWaitGroup.Wait()
|
2016-05-08 18:17:59 -07:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
2023-05-02 14:17:54 +00:00
|
|
|
_, err := cgoLookupIP(ctx, "ip", "localhost")
|
2016-05-08 18:17:59 -07:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCgoLookupPort(t *testing.T) {
|
2017-12-07 20:30:28 -08:00
|
|
|
defer dnsWaitGroup.Wait()
|
2016-05-08 18:17:59 -07:00
|
|
|
ctx := context.Background()
|
2023-05-02 14:17:54 +00:00
|
|
|
_, err := cgoLookupPort(ctx, "tcp", "smtp")
|
2016-05-08 18:17:59 -07:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCgoLookupPortWithCancel(t *testing.T) {
|
2017-12-07 20:30:28 -08:00
|
|
|
defer dnsWaitGroup.Wait()
|
2016-05-08 18:17:59 -07:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
2023-05-02 14:17:54 +00:00
|
|
|
_, err := cgoLookupPort(ctx, "tcp", "smtp")
|
2016-05-08 18:17:59 -07:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCgoLookupPTR(t *testing.T) {
|
2017-12-07 20:30:28 -08:00
|
|
|
defer dnsWaitGroup.Wait()
|
2016-05-08 18:17:59 -07:00
|
|
|
ctx := context.Background()
|
2023-05-02 14:17:54 +00:00
|
|
|
_, err := cgoLookupPTR(ctx, "127.0.0.1")
|
2016-05-08 18:17:59 -07:00
|
|
|
if err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCgoLookupPTRWithCancel(t *testing.T) {
|
2017-12-07 20:30:28 -08:00
|
|
|
defer dnsWaitGroup.Wait()
|
2016-05-08 18:17:59 -07:00
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
2023-05-02 14:17:54 +00:00
|
|
|
_, err := cgoLookupPTR(ctx, "127.0.0.1")
|
2016-05-08 18:17:59 -07:00
|
|
|
if err != nil {
|
2015-05-01 12:38:42 +09:00
|
|
|
t.Error(err)
|
2013-12-19 07:40:10 +09:00
|
|
|
}
|
|
|
|
}
|
2025-08-23 04:55:42 +08:00
|
|
|
|
|
|
|
func TestCgoLookupCNAME(t *testing.T) {
|
|
|
|
mustHaveExternalNetwork(t)
|
|
|
|
testenv.SkipFlakyNet(t)
|
|
|
|
defer dnsWaitGroup.Wait()
|
|
|
|
if _, err := cgoLookupCNAME(t.Context(), "www.iana.org."); err != nil {
|
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}
|