Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve starting of mDNS service in tests, stop using pkg/errors #15

Merged
merged 1 commit into from
Sep 20, 2021
Merged
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
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.16
require (
github.com/cenkalti/backoff/v4 v4.1.1
github.com/miekg/dns v1.1.41
github.com/pkg/errors v0.9.1
golang.org/x/net v0.0.0-20210423184538-5f58ad60dda6
golang.org/x/sys v0.0.0-20210426080607-c94f62235c83 // indirect
)
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ github.com/cenkalti/backoff/v4 v4.1.1 h1:G2HAfAmvm/GcKan2oOQpBXOd2tT2G57ZnZGWa1P
github.com/cenkalti/backoff/v4 v4.1.1/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw=
github.com/miekg/dns v1.1.41 h1:WMszZWJG0XmzbK9FEmzH2TVcqYzFesusSIB41b8KHxY=
github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210423184538-5f58ad60dda6 h1:0PC75Fz/kyMGhL0e1QnypqK2kQMqKt9csD1GnMJR+Zk=
golang.org/x/net v0.0.0-20210423184538-5f58ad60dda6/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
Expand Down
21 changes: 7 additions & 14 deletions service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"log"
"testing"
"time"

"github.com/pkg/errors"
)

var (
Expand All @@ -17,26 +15,21 @@ var (
mdnsPort = 8888
)

func startMDNS(ctx context.Context, port int, name, service, domain string) {
func startMDNS(t *testing.T, port int, name, service, domain string) {
// 5353 is default mdns port
server, err := Register(name, service, domain, port, []string{"txtv=0", "lo=1", "la=2"}, nil)
if err != nil {
panic(errors.Wrap(err, "while registering mdns service"))
t.Fatalf("error while registering mdns service: %s", err)
}
defer server.Shutdown()
t.Cleanup(server.Shutdown)
log.Printf("Published service: %s, type: %s, domain: %s", name, service, domain)

<-ctx.Done()

log.Printf("Shutting down.")

}

func TestBasic(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

go startMDNS(ctx, mdnsPort, mdnsName, mdnsService, mdnsDomain)
startMDNS(t, mdnsPort, mdnsName, mdnsService, mdnsDomain)

time.Sleep(time.Second)

Expand Down Expand Up @@ -87,7 +80,7 @@ func TestSubtype(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

go startMDNS(ctx, mdnsPort, mdnsName, mdnsSubtype, mdnsDomain)
startMDNS(t, mdnsPort, mdnsName, mdnsSubtype, mdnsDomain)

time.Sleep(time.Second)

Expand Down Expand Up @@ -119,7 +112,7 @@ func TestSubtype(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

go startMDNS(ctx, mdnsPort, mdnsName, mdnsSubtype, mdnsDomain)
startMDNS(t, mdnsPort, mdnsName, mdnsSubtype, mdnsDomain)

time.Sleep(time.Second)

Expand Down Expand Up @@ -159,7 +152,7 @@ func TestSubtype(t *testing.T) {

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
go startMDNS(ctx, mdnsPort, mdnsName, mdnsSubtype, mdnsDomain)
startMDNS(t, mdnsPort, mdnsName, mdnsSubtype, mdnsDomain)

entries := make(chan *ServiceEntry, 100)
if err := Browse(ctx, mdnsService, mdnsDomain, entries); err != nil {
Expand Down