mirror of
https://github.com/cloudflare/cloudflared.git
synced 2026-06-23 04:10:20 +00:00
9978cfd0d5
This PR implements all the dialers and resolvers needed to make pre-checks happen. So this task focuses on the following: 1. Implement the DNS probe: call DNSResolver.Resolve(region) 2. Implement the QUIC probe: call QUICDialer.DialQuic (handshake only, no stream opened) and record the result. 3. Implement the HTTP/2 probe: call TCPDialer.DialEdge (TCP + TLS handshake only, no frames sent) and record the result. 4. Implement the Management API probe: call ManagementDialer.DialContext to api.cloudflare.com:443 and record the result. 5. Export edgeDiscovery as EdgeDiscovery in edgediscovery/allregions/discovery.go so the pre-check can reuse the production DNS path. This sets up the main components to implement the checker.
40 lines
849 B
Go
40 lines
849 B
Go
package allregions
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/rs/zerolog"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func (ea *EdgeAddr) String() string {
|
|
return fmt.Sprintf("%s-%s", ea.TCP, ea.UDP)
|
|
}
|
|
|
|
func TestEdgeDiscovery(t *testing.T) {
|
|
mockAddrs := newMockAddrs(19, 2, 5)
|
|
netLookupSRV = mockNetLookupSRV(mockAddrs)
|
|
netLookupIP = mockNetLookupIP(mockAddrs)
|
|
|
|
expectedAddrSet := map[string]bool{}
|
|
for _, addrs := range mockAddrs.addrMap {
|
|
for _, addr := range addrs {
|
|
expectedAddrSet[addr.String()] = true
|
|
}
|
|
}
|
|
|
|
l := zerolog.Nop()
|
|
addrLists, err := EdgeDiscovery(&l, "")
|
|
require.NoError(t, err)
|
|
actualAddrSet := map[string]bool{}
|
|
for _, addrs := range addrLists {
|
|
for _, addr := range addrs {
|
|
actualAddrSet[addr.String()] = true
|
|
}
|
|
}
|
|
|
|
assert.Equal(t, expectedAddrSet, actualAddrSet)
|
|
}
|