srv_test.go 816 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package dnsutils
  2. import (
  3. "github.com/stretchr/testify/assert"
  4. "net"
  5. "testing"
  6. )
  7. func TestOrderSRV(t *testing.T) {
  8. srv11 := net.SRV{
  9. Target: "t11",
  10. Port: 1234,
  11. Priority: 1,
  12. Weight: 100,
  13. }
  14. srv12 := net.SRV{
  15. Target: "t12",
  16. Port: 1234,
  17. Priority: 1,
  18. Weight: 100,
  19. }
  20. srv13 := net.SRV{
  21. Target: "t13",
  22. Port: 1234,
  23. Priority: 1,
  24. Weight: 20,
  25. }
  26. srv21 := net.SRV{
  27. Target: "t21",
  28. Port: 1234,
  29. Priority: 2,
  30. Weight: 1,
  31. }
  32. addrs := []*net.SRV{
  33. &srv11, &srv21, &srv12, &srv13,
  34. }
  35. count, orderedSRV := orderSRV(addrs)
  36. assert.Equal(t, len(addrs), count, "Index not the expected size")
  37. assert.Equal(t, len(addrs), len(orderedSRV), "orderedSRV not the expected size")
  38. assert.Equal(t, uint16(2), orderedSRV[4].Priority, "Priority order not as expected")
  39. }