package mdns

import (
	"reflect"
	"testing"

	"github.com/miekg/dns"
)

func TestDNSSDServiceRecords(t *testing.T) {
	s := &DNSSDService{
		MDNSService: &MDNSService{
			serviceAddr: "_foobar._tcp.local.",
			Domain:      "local",
		},
	}
	q := dns.Question{
		Name:   "_services._dns-sd._udp.local.",
		Qtype:  dns.TypePTR,
		Qclass: dns.ClassINET,
	}
	recs := s.Records(q)
	if got, want := len(recs), 1; got != want {
		t.Fatalf("s.Records(%v) returned %v records, want %v", q, got, want)
	}

	want := dns.RR(&dns.PTR{
		Hdr: dns.RR_Header{
			Name:   "_services._dns-sd._udp.local.",
			Rrtype: dns.TypePTR,
			Class:  dns.ClassINET,
			Ttl:    defaultTTL,
		},
		Ptr: "_foobar._tcp.local.",
	})
	if got := recs[0]; !reflect.DeepEqual(got, want) {
		t.Errorf("s.Records()[0] = %v, want %v", got, want)
	}
}
