discovery_test.go 809 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package allregions
  2. import (
  3. "fmt"
  4. "testing"
  5. "github.com/rs/zerolog"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func (ea *EdgeAddr) String() string {
  9. return fmt.Sprintf("%s-%s", ea.TCP, ea.UDP)
  10. }
  11. func TestEdgeDiscovery(t *testing.T) {
  12. mockAddrs := newMockAddrs(19, 2, 5)
  13. netLookupSRV = mockNetLookupSRV(mockAddrs)
  14. netLookupIP = mockNetLookupIP(mockAddrs)
  15. expectedAddrSet := map[string]bool{}
  16. for _, addrs := range mockAddrs.addrMap {
  17. for _, addr := range addrs {
  18. expectedAddrSet[addr.String()] = true
  19. }
  20. }
  21. l := zerolog.Nop()
  22. addrLists, err := edgeDiscovery(&l, "")
  23. assert.NoError(t, err)
  24. actualAddrSet := map[string]bool{}
  25. for _, addrs := range addrLists {
  26. for _, addr := range addrs {
  27. actualAddrSet[addr.String()] = true
  28. }
  29. }
  30. assert.Equal(t, expectedAddrSet, actualAddrSet)
  31. }