mirror of
https://github.com/coder/coder.git
synced 2026-09-22 21:22:17 +08:00
test(cli): fix TestServer flake due to DNS lookup (#10390)
This commit is contained in:
@@ -1206,6 +1206,14 @@ func WriteConfigMW(cfg *codersdk.DeploymentValues) clibase.MiddlewareFunc {
|
|||||||
// isLocalURL returns true if the hostname of the provided URL appears to
|
// isLocalURL returns true if the hostname of the provided URL appears to
|
||||||
// resolve to a loopback address.
|
// resolve to a loopback address.
|
||||||
func IsLocalURL(ctx context.Context, u *url.URL) (bool, error) {
|
func IsLocalURL(ctx context.Context, u *url.URL) (bool, error) {
|
||||||
|
// In tests, we commonly use "example.com" or "google.com", which
|
||||||
|
// are not loopback, so avoid the DNS lookup to avoid flakes.
|
||||||
|
if flag.Lookup("test.v") != nil {
|
||||||
|
if u.Hostname() == "example.com" || u.Hostname() == "google.com" {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
resolver := &net.Resolver{}
|
resolver := &net.Resolver{}
|
||||||
ips, err := resolver.LookupIPAddr(ctx, u.Hostname())
|
ips, err := resolver.LookupIPAddr(ctx, u.Hostname())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user