srv_integration_test.go 1008 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // +build integration
  2. // To turn on this test use -tags=integration in go test command
  3. package dnsutils
  4. import (
  5. "github.com/stretchr/testify/assert"
  6. "strconv"
  7. "strings"
  8. "testing"
  9. )
  10. func TestResolveKDC(t *testing.T) {
  11. for i := 0; i < 100; i++ {
  12. count, res, err := OrderedSRV("kerberos", "tcp", "test.gokrb5")
  13. if err != nil {
  14. t.Errorf("error resolving SRV DNS records: %v", err)
  15. }
  16. expected := []string{
  17. "kdc.test.gokrb5:88",
  18. "kdc1a.test.gokrb5:88",
  19. "kdc2a.test.gokrb5:88",
  20. "kdc1b.test.gokrb5:88",
  21. "kdc2b.test.gokrb5:88",
  22. }
  23. assert.Equal(t, len(expected), count, "Number of SRV records not as expected: %v", res)
  24. assert.Equal(t, count, len(res), "Map size does not match: %v", res)
  25. for _, s := range expected {
  26. var found bool
  27. for _, v := range res {
  28. srvStr := strings.TrimRight(v.Target, ".") + ":" + strconv.Itoa(int(v.Port))
  29. if s == srvStr {
  30. found = true
  31. break
  32. }
  33. }
  34. assert.True(t, found, "Record %s not found in results", s)
  35. }
  36. }
  37. }