net: net remove completed return from cgo lookup functions

After CL 487196 there is no need anymore to return
completed == false from the cgo lookup functions and
then fallback to to go resolver.  (Before CL 487196 this
change would cause the (only?) tests to fail)
Now the cgoAvailable constant guards that correctly.

This change will cause a panic when the cgo resolver is being
used without the cgo support, so it will be easier to
detect bug while changing the code in the net package.

I am leaving the completed return from cgoLookupCNAME,
because it is super broken now.

Change-Id: I2661b9a3725de2b1a229847c12adf64b3f62b136
GitHub-Last-Rev: 2a6501a53e
GitHub-Pull-Request: golang/go#59925
Reviewed-on: https://go-review.googlesource.com/c/go/+/491275
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Mateusz Poliwczak <mpoliwczak34@gmail.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
Mateusz Poliwczak 2023-05-02 14:17:54 +00:00 committed by Gopher Robot
parent 1596aeec8e
commit 2c49bf89ed
5 changed files with 41 additions and 98 deletions

View file

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build (cgo || darwin) && !netgo && unix
//go:build !netgo && ((cgo && unix) || darwin)
package net
@ -14,10 +14,7 @@ import (
func TestCgoLookupIP(t *testing.T) {
defer dnsWaitGroup.Wait()
ctx := context.Background()
_, err, ok := cgoLookupIP(ctx, "ip", "localhost")
if !ok {
t.Errorf("cgoLookupIP must not be a placeholder")
}
_, err := cgoLookupIP(ctx, "ip", "localhost")
if err != nil {
t.Error(err)
}
@ -27,10 +24,7 @@ func TestCgoLookupIPWithCancel(t *testing.T) {
defer dnsWaitGroup.Wait()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
_, err, ok := cgoLookupIP(ctx, "ip", "localhost")
if !ok {
t.Errorf("cgoLookupIP must not be a placeholder")
}
_, err := cgoLookupIP(ctx, "ip", "localhost")
if err != nil {
t.Error(err)
}
@ -39,10 +33,7 @@ func TestCgoLookupIPWithCancel(t *testing.T) {
func TestCgoLookupPort(t *testing.T) {
defer dnsWaitGroup.Wait()
ctx := context.Background()
_, err, ok := cgoLookupPort(ctx, "tcp", "smtp")
if !ok {
t.Errorf("cgoLookupPort must not be a placeholder")
}
_, err := cgoLookupPort(ctx, "tcp", "smtp")
if err != nil {
t.Error(err)
}
@ -52,10 +43,7 @@ func TestCgoLookupPortWithCancel(t *testing.T) {
defer dnsWaitGroup.Wait()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
_, err, ok := cgoLookupPort(ctx, "tcp", "smtp")
if !ok {
t.Errorf("cgoLookupPort must not be a placeholder")
}
_, err := cgoLookupPort(ctx, "tcp", "smtp")
if err != nil {
t.Error(err)
}
@ -64,10 +52,7 @@ func TestCgoLookupPortWithCancel(t *testing.T) {
func TestCgoLookupPTR(t *testing.T) {
defer dnsWaitGroup.Wait()
ctx := context.Background()
_, err, ok := cgoLookupPTR(ctx, "127.0.0.1")
if !ok {
t.Errorf("cgoLookupPTR must not be a placeholder")
}
_, err := cgoLookupPTR(ctx, "127.0.0.1")
if err != nil {
t.Error(err)
}
@ -77,10 +62,7 @@ func TestCgoLookupPTRWithCancel(t *testing.T) {
defer dnsWaitGroup.Wait()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
_, err, ok := cgoLookupPTR(ctx, "127.0.0.1")
if !ok {
t.Errorf("cgoLookupPTR must not be a placeholder")
}
_, err := cgoLookupPTR(ctx, "127.0.0.1")
if err != nil {
t.Error(err)
}