mirror of
https://github.com/pgsty/minio.git
synced 2026-11-01 13:22:02 +03:00
test: isolate endpoint locality fixtures from public DNS
Signed-off-by: Feng Ruohang <rh@vonng.com>
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -25,10 +26,34 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/minio/dnscache"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type endpointTestResolver struct {
|
||||||
|
dnscache.DNSResolver
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r endpointTestResolver) LookupHost(ctx context.Context, host string) ([]string, error) {
|
||||||
|
// These endpoint fixtures test locality and parsing, not public DNS.
|
||||||
|
for i, name := range []string{"example.org", "example.com", "example.net", "example.edu"} {
|
||||||
|
if host == name {
|
||||||
|
return []string{fmt.Sprintf("203.0.113.%d", i+1)}, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return r.DNSResolver.LookupHost(ctx, host)
|
||||||
|
}
|
||||||
|
|
||||||
|
func useTestEndpointDNS(t *testing.T) {
|
||||||
|
t.Helper()
|
||||||
|
previous := globalDNSCache
|
||||||
|
globalDNSCache = &dnscache.Resolver{Resolver: endpointTestResolver{net.DefaultResolver}}
|
||||||
|
t.Cleanup(func() { globalDNSCache = previous })
|
||||||
|
}
|
||||||
|
|
||||||
func useStaticTestEndpoints(t *testing.T) {
|
func useStaticTestEndpoints(t *testing.T) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
useTestEndpointDNS(t)
|
||||||
// These fixtures deliberately use localhost, including inside containers.
|
// These fixtures deliberately use localhost, including inside containers.
|
||||||
previous := orchestrated
|
previous := orchestrated
|
||||||
orchestrated = false
|
orchestrated = false
|
||||||
@@ -36,6 +61,7 @@ func useStaticTestEndpoints(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNewEndpoint(t *testing.T) {
|
func TestNewEndpoint(t *testing.T) {
|
||||||
|
useTestEndpointDNS(t)
|
||||||
u2, _ := url.Parse("https://example.org/path")
|
u2, _ := url.Parse("https://example.org/path")
|
||||||
u4, _ := url.Parse("http://192.168.253.200/path")
|
u4, _ := url.Parse("http://192.168.253.200/path")
|
||||||
rootSlashFoo, _ := filepath.Abs("/foo")
|
rootSlashFoo, _ := filepath.Abs("/foo")
|
||||||
|
|||||||
@@ -186,6 +186,7 @@ func TestGetAPIEndpoints(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestCheckLocalServerAddr(t *testing.T) {
|
func TestCheckLocalServerAddr(t *testing.T) {
|
||||||
|
useTestEndpointDNS(t)
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
serverAddr string
|
serverAddr string
|
||||||
expectedErr error
|
expectedErr error
|
||||||
|
|||||||
Reference in New Issue
Block a user