zone_health_test.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package zones
  2. import (
  3. "math/rand"
  4. "testing"
  5. "github.com/abh/geodns/health"
  6. "github.com/miekg/dns"
  7. )
  8. type HealthStatus struct {
  9. t *testing.T
  10. status health.StatusType
  11. odds float64
  12. }
  13. func (hs *HealthStatus) GetStatus(name string) health.StatusType {
  14. hs.t.Logf("GetStatus(%s)", name)
  15. // hs.t.Fatalf("in get status")
  16. if hs.odds >= 0 {
  17. switch rand.Float64() < hs.odds {
  18. case true:
  19. return health.StatusHealthy
  20. case false:
  21. return health.StatusUnhealthy
  22. }
  23. }
  24. return hs.status
  25. }
  26. func (hs *HealthStatus) Close() error {
  27. return nil
  28. }
  29. func (hs *HealthStatus) Reload() error {
  30. return nil
  31. }
  32. func TestHealth(t *testing.T) {
  33. muxm := loadZones(t)
  34. t.Log("setting up health status")
  35. hs := &HealthStatus{t: t, odds: -1, status: health.StatusUnhealthy}
  36. tz := muxm.zonelist["hc.example.com"]
  37. tz.HealthStatus = hs
  38. // t.Logf("hs: '%+v'", tz.HealthStatus)
  39. // t.Logf("hc zone: '%+v'", tz)
  40. matches := tz.FindLabels("tucs", []string{"@"}, []uint16{dns.TypeA})
  41. // t.Logf("qt: %d, label: '%+v'", qt, label)
  42. records := tz.Picker(matches[0].Label, matches[0].Type, 2, nil)
  43. if len(records) > 0 {
  44. t.Errorf("got %d records when expecting 0", len(records))
  45. }
  46. // t.Logf("label.Test: '%+v'", label.Test)
  47. if len(records) == 0 {
  48. t.Log("didn't get any records")
  49. }
  50. }