Fix watch for events; add test for interface implementation so it won't break again.

This commit is contained in:
Daniel Smith
2014-11-12 13:30:13 -08:00
parent 02a0593df0
commit 178d0af795
11 changed files with 72 additions and 69 deletions

View File

@@ -91,8 +91,12 @@ func (e *Etcd) Delete(ctx api.Context, id string) error {
// Watch starts a watch for the items that m matches.
// TODO: Detect if m references a single object instead of a list.
func (e *Etcd) Watch(ctx api.Context, m generic.Matcher, resourceVersion uint64) (watch.Interface, error) {
return e.Helper.WatchList(e.KeyRoot, resourceVersion, func(obj runtime.Object) bool {
func (e *Etcd) Watch(ctx api.Context, m generic.Matcher, resourceVersion string) (watch.Interface, error) {
version, err := tools.ParseWatchResourceVersion(resourceVersion, e.EndpointName)
if err != nil {
return nil, err
}
return e.Helper.WatchList(e.KeyRoot, version, func(obj runtime.Object) bool {
matches, err := m.Matches(obj)
return err == nil && matches
})

View File

@@ -417,7 +417,7 @@ func TestEtcdWatch(t *testing.T) {
}
fakeClient, registry := NewTestGenericEtcdRegistry(t)
wi, err := registry.Watch(api.NewContext(), EverythingMatcher{}, 1)
wi, err := registry.Watch(api.NewContext(), EverythingMatcher{}, "1")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

View File

@@ -76,7 +76,7 @@ type Registry interface {
Update(ctx api.Context, id string, obj runtime.Object) error
Get(ctx api.Context, id string) (runtime.Object, error)
Delete(ctx api.Context, id string) error
Watch(ctx api.Context, m Matcher, resourceVersion uint64) (watch.Interface, error)
Watch(ctx api.Context, m Matcher, resourceVersion string) (watch.Interface, error)
}
// FilterList filters any list object that conforms to the api conventions,