feat(discovery): android compatibility
This commit is contained in:
69
reach/discovery/resolver_test.go
Normal file
69
reach/discovery/resolver_test.go
Normal file
@ -0,0 +1,69 @@
|
||||
package discovery
|
||||
|
||||
import (
|
||||
"context"
|
||||
"regexp"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"forge.cadoles.com/cadoles/go-emlid/reach"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func TestResolver(t *testing.T) {
|
||||
reach.AssertIntegrationTests(t)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
resolver := NewResolver()
|
||||
|
||||
found, err := resolver.Scan(ctx, 500*time.Millisecond)
|
||||
if err != nil {
|
||||
t.Fatalf("%+v", errors.WithStack(err))
|
||||
}
|
||||
|
||||
services := make([]Service, 0)
|
||||
OUTER:
|
||||
for {
|
||||
select {
|
||||
case s := <-found:
|
||||
t.Logf("%s", spew.Sdump(s))
|
||||
services = append(services, s)
|
||||
case <-ctx.Done():
|
||||
break OUTER
|
||||
}
|
||||
}
|
||||
|
||||
if g, e := len(services), 1; g < e {
|
||||
t.Fatalf("len(services): got '%d', expected > %d", g, e)
|
||||
}
|
||||
|
||||
t.Logf("Found %d services", len(services))
|
||||
|
||||
patterns := []string{"reach", "Reach", "^RS.*"}
|
||||
|
||||
for i, s := range services {
|
||||
t.Logf("Service #%d: %s - %s:%d", i, s.Name, s.AddrV4.String(), s.Port)
|
||||
|
||||
matched := false
|
||||
|
||||
for _, p := range patterns {
|
||||
re, err := regexp.Compile(p)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if re.Match([]byte(s.Name)) {
|
||||
matched = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !matched {
|
||||
t.Errorf("services[%d].Name ('%s') to match on of '%v'", i, s.Name, patterns)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user