54 lines
992 B
Go
54 lines
992 B
Go
package discovery
|
|
|
|
import (
|
|
"context"
|
|
"regexp"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestDiscovery(t *testing.T) {
|
|
if !*runDiscoveryIntegrationTests {
|
|
t.Skip("To run this test, go test -v ./reach/discovery -discovery-integration")
|
|
}
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
defer cancel()
|
|
|
|
services, err := Discover(ctx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|
|
|
|
}
|