querylog_test.go 1016 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package server
  2. import (
  3. "testing"
  4. "github.com/abh/geodns/v3/querylog"
  5. "github.com/miekg/dns"
  6. )
  7. type testLogger struct {
  8. lastLog querylog.Entry
  9. }
  10. func (l *testLogger) Close() error {
  11. return nil
  12. }
  13. func (l *testLogger) Write(ql *querylog.Entry) error {
  14. l.lastLog = *ql
  15. return nil
  16. }
  17. func (l *testLogger) Last() querylog.Entry {
  18. // l.logged = false
  19. return l.lastLog
  20. }
  21. func testQueryLog(srv *Server) func(*testing.T) {
  22. tlog := &testLogger{}
  23. srv.SetQueryLogger(tlog)
  24. return func(t *testing.T) {
  25. r := exchange(t, "www-alias.example.com.", dns.TypeA)
  26. expected := "geo.bitnames.com."
  27. answer := r.Answer[0].(*dns.CNAME).Target
  28. if answer != expected {
  29. t.Logf("expected CNAME %s, got %s", expected, answer)
  30. t.Fail()
  31. }
  32. last := tlog.Last()
  33. // t.Logf("last log: %+v", last)
  34. if last.Name != "www-alias.example.com." {
  35. t.Logf("didn't get qname in Name querylog")
  36. t.Fail()
  37. }
  38. if last.LabelName != "www" {
  39. t.Logf("LabelName didn't contain resolved label")
  40. t.Fail()
  41. }
  42. }
  43. }