Pull request: all: update go and backend tools
Updates #2275. Squashed commit of the following: commit f24c26cd2b49fac00a581936da4ccb13ca341bc9 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Mar 10 21:33:15 2021 +0300 aghtest: imp docs commit 46f5b06f9743e800b489e8c30af07d24bfdcf989 Merge: bfb852cb55d4c7eeAuthor: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Mar 10 21:32:32 2021 +0300 Merge branch 'master' into 2275-upd commit bfb852cbc74ec219a41e985f2dcb090d58299aee Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Mar 10 19:06:32 2021 +0300 scripts: rem unsupported platform commit c1645e247f18d384a980c60d3a94b9363f83f174 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Mar 10 18:47:57 2021 +0300 all: rollback more commit 989811b5e38498234dc11baf5dd153c76b9dada4 Merge: 976bdfbd2d704242Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Mar 10 18:30:42 2021 +0300 Merge branch 'master' into 2275-upd commit 976bdfbdd44983f4cd657a486b94ff63f5885fd5 Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Mar 10 18:28:23 2021 +0300 aghtest: fix os_windows commit 9e85080eefe882d72c939969f7008e3c46467c0c Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Mar 10 18:15:37 2021 +0300 all: rewrite windows workaround, imp code, docs commit 35a0b1d8656640a962fe9ae019c3d665f42707ce Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Thu Jan 21 20:38:17 2021 +0300 all: update go and backend tools
This commit is contained in:
@@ -1,14 +1,7 @@
|
||||
package aghtest
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// PrepareTestDir returns the full path to temporary created directory and
|
||||
@@ -16,30 +9,5 @@ import (
|
||||
func PrepareTestDir(t *testing.T) (dir string) {
|
||||
t.Helper()
|
||||
|
||||
wd, err := os.Getwd()
|
||||
require.Nil(t, err)
|
||||
|
||||
dir, err = ioutil.TempDir(wd, "agh-test")
|
||||
require.Nil(t, err)
|
||||
require.NotEmpty(t, dir)
|
||||
|
||||
t.Cleanup(func() {
|
||||
// TODO(e.burkov): Replace with t.TempDir methods after updating
|
||||
// go version to 1.15.
|
||||
start := time.Now()
|
||||
for {
|
||||
err := os.RemoveAll(dir)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
|
||||
if runtime.GOOS != "windows" || time.Since(start) >= 500*time.Millisecond {
|
||||
break
|
||||
}
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
}
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
|
||||
return dir
|
||||
return prepareTestDir(t)
|
||||
}
|
||||
|
||||
13
internal/aghtest/os_others.go
Normal file
13
internal/aghtest/os_others.go
Normal file
@@ -0,0 +1,13 @@
|
||||
// +build !windows
|
||||
|
||||
package aghtest
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func prepareTestDir(t *testing.T) (dir string) {
|
||||
t.Helper()
|
||||
|
||||
return t.TempDir()
|
||||
}
|
||||
63
internal/aghtest/os_windows.go
Normal file
63
internal/aghtest/os_windows.go
Normal file
@@ -0,0 +1,63 @@
|
||||
// +build windows
|
||||
|
||||
package aghtest
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const (
|
||||
maxRetryDur = 500 * time.Millisecond
|
||||
retryDur = 5 * time.Millisecond
|
||||
)
|
||||
|
||||
func prepareTestDir(t *testing.T) (dir string) {
|
||||
// Windows, including the version of Windows Server that Github Actions
|
||||
// uses, apparently likes to overly eagerly inspect new directories with
|
||||
// its Windows Defender. Disabling it might require additional
|
||||
// workarounds, and until we've figured it out, just retry the deletion
|
||||
// until the error goes away.
|
||||
//
|
||||
// The code is largely inspired by the one that has been introduced into
|
||||
// the go command itself. We should probably make a proposal to use the
|
||||
// same mechanism in t.TempDir.
|
||||
//
|
||||
// See https://go-review.googlesource.com/c/go/+/172337.
|
||||
//
|
||||
// See https://github.com/golang/go/issues/44919.
|
||||
|
||||
t.Helper()
|
||||
|
||||
wd, err := os.Getwd()
|
||||
require.Nil(t, err)
|
||||
|
||||
dir, err = ioutil.TempDir(wd, "agh-test")
|
||||
require.Nil(t, err)
|
||||
require.NotEmpty(t, dir)
|
||||
|
||||
t.Cleanup(func() {
|
||||
start := time.Now()
|
||||
for {
|
||||
err := os.RemoveAll(dir)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
|
||||
if time.Since(start) >= maxRetryDur {
|
||||
break
|
||||
}
|
||||
|
||||
time.Sleep(retryDur)
|
||||
}
|
||||
|
||||
assert.Nil(t, err)
|
||||
})
|
||||
|
||||
return dir
|
||||
}
|
||||
@@ -14,23 +14,17 @@ type TestResolver struct {
|
||||
}
|
||||
|
||||
// HostToIPs generates IPv4 and IPv6 from host.
|
||||
//
|
||||
// TODO(e.burkov): Replace with LookupIP after upgrading go to v1.15.
|
||||
func (r *TestResolver) HostToIPs(host string) (ipv4, ipv6 net.IP) {
|
||||
hash := sha256.Sum256([]byte(host))
|
||||
|
||||
return net.IP(hash[:4]), net.IP(hash[4:20])
|
||||
}
|
||||
|
||||
// LookupIPAddr implements Resolver interface for *testResolver. It returns the
|
||||
// slice of net.IPAddr with IPv4 and IPv6 instances.
|
||||
func (r *TestResolver) LookupIPAddr(_ context.Context, host string) (ips []net.IPAddr, err error) {
|
||||
// LookupIP implements Resolver interface for *testResolver. It returns the
|
||||
// slice of net.IP with IPv4 and IPv6 instances.
|
||||
func (r *TestResolver) LookupIP(_ context.Context, _, host string) (ips []net.IP, err error) {
|
||||
ipv4, ipv6 := r.HostToIPs(host)
|
||||
addrs := []net.IPAddr{{
|
||||
IP: ipv4,
|
||||
}, {
|
||||
IP: ipv6,
|
||||
}}
|
||||
addrs := []net.IP{ipv4, ipv6}
|
||||
|
||||
r.counterLock.Lock()
|
||||
defer r.counterLock.Unlock()
|
||||
|
||||
Reference in New Issue
Block a user