diff --git a/src/net/conf_test.go b/src/net/conf_test.go index 9228b34a39..cc9766a765 100644 --- a/src/net/conf_test.go +++ b/src/net/conf_test.go @@ -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 darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris +//go:build !js package net diff --git a/src/net/dnsclient_unix_test.go b/src/net/dnsclient_unix_test.go index 17fe90af77..4c926a47a8 100644 --- a/src/net/dnsclient_unix_test.go +++ b/src/net/dnsclient_unix_test.go @@ -10,10 +10,12 @@ import ( "context" "errors" "fmt" + "io/fs" "os" "path" "path/filepath" "reflect" + "runtime" "strings" "sync" "sync/atomic" @@ -2514,7 +2516,10 @@ func TestDNSConfigNoReload(t *testing.T) { func TestLookupOrderFilesNoSuchHost(t *testing.T) { defer func(orig string) { testHookHostsPath = orig }(testHookHostsPath) - defer setSystemNSS(getSystemNSS(), 0) + if runtime.GOOS != "openbsd" { + defer setSystemNSS(getSystemNSS(), 0) + setSystemNSS(nssStr("hosts: files"), time.Hour) + } conf, err := newResolvConfTest() if err != nil { @@ -2522,13 +2527,16 @@ func TestLookupOrderFilesNoSuchHost(t *testing.T) { } defer conf.teardown() - // update resolv.conf, so that it does not contain any unknownOpts - err = conf.writeAndUpdate([]string{"nameserver 127.0.0.1"}) - if err != nil { - t.Fatal(err) + resolvConf := dnsConfig{servers: defaultNS} + if runtime.GOOS == "openbsd" { + // Set error to ErrNotExist, so the hostLookupOrder + // returns hostLookupFiles for openbsd. + resolvConf.err = fs.ErrNotExist } - setSystemNSS(nssStr("hosts: files"), time.Hour) + if !conf.forceUpdateConf(&resolvConf, time.Now().Add(time.Hour)) { + t.Fatal("failed to update resolv config") + } tmpFile := filepath.Join(t.TempDir(), "hosts") f, err := os.OpenFile(tmpFile, os.O_CREATE|os.O_WRONLY, 0660)