Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,10 @@ func (r *Resolver) Browse(ctx context.Context, service, domain string, entries c

// Lookup a specific service by its name and type in a given domain.
func (r *Resolver) Lookup(ctx context.Context, instance, service, domain string, entries chan<- *ServiceEntry) error {
params := defaultParams(service)
params.Instance = instance
if domain != "" {
params.Domain = domain
if domain == "" {
domain = "local"
}
params.Entries = entries
params := newLookupParams(instance, service, domain, false, entries)
ctx, cancel := context.WithCancel(ctx)
go r.c.mainloop(ctx, params)
err := r.c.query(params)
Expand Down
26 changes: 26 additions & 0 deletions service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,32 @@ func TestNoRegister(t *testing.T) {
cancel()
}

func TestLookupParamsServiceInstanceName(t *testing.T) {
instance := "device-one"
service := "_lookup-filter._tcp"
domain := "local"
entries := make(chan *ServiceEntry)

// Correct path used by Resolver.Lookup: instance is set at construction.
params := newLookupParams(instance, service, domain, false, entries)
want := "device-one._lookup-filter._tcp.local."
if got := params.ServiceInstanceName(); got != want {
t.Fatalf("ServiceInstanceName() = %q, want %q", got, want)
}
if params.Instance != instance {
t.Fatalf("Instance = %q, want %q", params.Instance, instance)
}
if params.ServiceName() != "_lookup-filter._tcp.local." {
t.Fatalf("ServiceName() = %q, want %q", params.ServiceName(), "_lookup-filter._tcp.local.")
}

broken := defaultParams(service)
broken.Instance = instance
if got := broken.ServiceInstanceName(); got != "" {
t.Fatalf("mutating Instance after construction must not update ServiceInstanceName; got %q", got)
}
}

func TestSubtype(t *testing.T) {
t.Run("browse with subtype", func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
Expand Down