Simplify watcher test

This commit is contained in:
Asim 2016-05-01 22:30:33 +01:00
parent 7996785195
commit d3de45409f

View File

@ -100,64 +100,45 @@ func TestWatcher(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
var ok bool for {
for i := 0; i < 5; i++ {
// get registered service
res, err := w.Next() res, err := w.Next()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if res.Service.Name != service.Name { if res.Service.Name != service.Name {
break continue
} }
if res.Action != "create" { if res.Action != "create" {
break t.Fatalf("Expected create event got %s for %s", res.Action, res.Service.Name)
} }
testFn(service, res.Service) testFn(service, res.Service)
ok = true
break break
} }
if !ok {
t.Fatalf("Watch test failed for creation of %s", service.Name)
}
}
for _, service := range testData {
// deregister // deregister
if err := r.Deregister(service); err != nil { if err := r.Deregister(service); err != nil {
t.Fatal(err) t.Fatal(err)
} }
var ok bool for {
for i := 0; i < 5; i++ {
// get registered service
res, err := w.Next() res, err := w.Next()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if res.Service.Name != service.Name {
continue
}
if res.Action != "delete" { if res.Action != "delete" {
continue continue
} }
if res.Service.Name != service.Name {
break
}
testFn(service, res.Service) testFn(service, res.Service)
ok = true
break break
} }
if !ok {
t.Fatalf("Watch test failed for deletion of %s", service.Name)
} }
}
} }