From fa1bcec1f4b824425d1e70d4514b2ca86f709505 Mon Sep 17 00:00:00 2001 From: Asim Date: Sun, 1 May 2016 22:30:33 +0100 Subject: [PATCH] Simplify watcher test --- watcher_test.go | 35 ++++++++--------------------------- 1 file changed, 8 insertions(+), 27 deletions(-) diff --git a/watcher_test.go b/watcher_test.go index 8cf0008..8b1335b 100644 --- a/watcher_test.go +++ b/watcher_test.go @@ -100,64 +100,45 @@ func TestWatcher(t *testing.T) { t.Fatal(err) } - var ok bool - - for i := 0; i < 5; i++ { - // get registered service + for { res, err := w.Next() if err != nil { t.Fatal(err) } if res.Service.Name != service.Name { - break + continue } if res.Action != "create" { - break + t.Fatalf("Expected create event got %s for %s", res.Action, res.Service.Name) } testFn(service, res.Service) - ok = true break } - if !ok { - t.Fatalf("Watch test failed for creation of %s", service.Name) - } - } - - for _, service := range testData { // deregister if err := r.Deregister(service); err != nil { t.Fatal(err) } - var ok bool - - for i := 0; i < 5; i++ { - // get registered service + for { res, err := w.Next() if err != nil { t.Fatal(err) } + if res.Service.Name != service.Name { + continue + } + if res.Action != "delete" { continue } - if res.Service.Name != service.Name { - break - } - testFn(service, res.Service) - ok = true break } - - if !ok { - t.Fatalf("Watch test failed for deletion of %s", service.Name) - } } - }