Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-02-20 14:23:07 +03:00
parent 9c94a3e6a8
commit 21928ee740

View File

@ -1,6 +1,7 @@
package mdns package mdns
import ( import (
"context"
"os" "os"
"testing" "testing"
"time" "time"
@ -9,6 +10,8 @@ import (
) )
func TestMDNS(t *testing.T) { func TestMDNS(t *testing.T) {
ctx := context.Background()
// skip test in travis because of sendto: operation not permitted error // skip test in travis because of sendto: operation not permitted error
if travis := os.Getenv("TRAVIS"); travis == "true" { if travis := os.Getenv("TRAVIS"); travis == "true" {
t.Skip() t.Skip()
@ -69,12 +72,12 @@ func TestMDNS(t *testing.T) {
for _, service := range testData { for _, service := range testData {
// register service // register service
if err := r.Register(service); err != nil { if err := r.Register(ctx, service); err != nil {
t.Fatal(err) t.Fatal(err)
} }
// get registered service // get registered service
s, err := r.LookupService(service.Name) s, err := r.LookupService(ctx, service.Name)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -106,7 +109,7 @@ func TestMDNS(t *testing.T) {
} }
} }
services, err := r.ListServices() services, err := r.ListServices(ctx)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -124,14 +127,14 @@ func TestMDNS(t *testing.T) {
} }
// deregister // deregister
if err := r.Deregister(service); err != nil { if err := r.Deregister(ctx, service); err != nil {
t.Fatal(err) t.Fatal(err)
} }
time.Sleep(time.Millisecond * 5) time.Sleep(time.Millisecond * 5)
// check its gone // check its gone
s, _ := r.GetService(service.Name) s, _ := r.LookupService(ctx, service.Name)
if len(s) > 0 { if len(s) > 0 {
t.Fatalf("Expected nothing got %+v", s[0]) t.Fatalf("Expected nothing got %+v", s[0])
} }
@ -200,6 +203,8 @@ func TestEncoding(t *testing.T) {
} }
func TestWatcher(t *testing.T) { func TestWatcher(t *testing.T) {
ctx := context.Background()
if travis := os.Getenv("TRAVIS"); travis == "true" { if travis := os.Getenv("TRAVIS"); travis == "true" {
t.Skip() t.Skip()
} }
@ -286,7 +291,7 @@ func TestWatcher(t *testing.T) {
// new registry // new registry
r := NewRegister(opts...) r := NewRegister(opts...)
w, err := r.Watch() w, err := r.Watch(ctx)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -294,7 +299,7 @@ func TestWatcher(t *testing.T) {
for _, service := range testData { for _, service := range testData {
// register service // register service
if err := r.Register(service); err != nil { if err := r.Register(ctx, service); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -317,7 +322,7 @@ func TestWatcher(t *testing.T) {
} }
// deregister // deregister
if err := r.Deregister(service); err != nil { if err := r.Deregister(ctx, service); err != nil {
t.Fatal(err) t.Fatal(err)
} }