Change filter to interface in storage.Interface

This commit is contained in:
Wojciech Tyczynski
2016-06-03 14:09:16 +02:00
parent d4df168186
commit 7f7ef0879f
13 changed files with 122 additions and 81 deletions

View File

@@ -39,7 +39,7 @@ var versioner = APIObjectVersioner{}
// Implements etcdCache interface as empty methods (i.e. does not cache any objects)
type fakeEtcdCache struct{}
func (f *fakeEtcdCache) getFromCache(index uint64, filter storage.FilterFunc) (runtime.Object, bool) {
func (f *fakeEtcdCache) getFromCache(index uint64, filter storage.Filter) (runtime.Object, bool) {
return nil, false
}
@@ -48,17 +48,22 @@ func (f *fakeEtcdCache) addToCache(index uint64, obj runtime.Object) {
var _ etcdCache = &fakeEtcdCache{}
// firstLetterIsB implements storage.Filter interface.
type firstLetterIsB struct {
}
func (f *firstLetterIsB) Filter(obj runtime.Object) bool {
return obj.(*api.Pod).Name[0] == 'b'
}
func TestWatchInterpretations(t *testing.T) {
codec := testapi.Default.Codec()
// Declare some pods to make the test cases compact.
podFoo := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "foo"}}
podBar := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "bar"}}
podBaz := &api.Pod{ObjectMeta: api.ObjectMeta{Name: "baz"}}
firstLetterIsB := func(obj runtime.Object) bool {
return obj.(*api.Pod).Name[0] == 'b'
}
// All of these test cases will be run with the firstLetterIsB FilterFunc.
// All of these test cases will be run with the firstLetterIsB Filter.
table := map[string]struct {
actions []string // Run this test item for every action here.
prevNodeValue string
@@ -131,7 +136,7 @@ func TestWatchInterpretations(t *testing.T) {
for name, item := range table {
for _, action := range item.actions {
w := newEtcdWatcher(true, false, nil, firstLetterIsB, codec, versioner, nil, &fakeEtcdCache{})
w := newEtcdWatcher(true, false, nil, &firstLetterIsB{}, codec, versioner, nil, &fakeEtcdCache{})
emitCalled := false
w.emit = func(event watch.Event) {
emitCalled = true
@@ -222,9 +227,10 @@ func TestWatchInterpretation_ResponseBadData(t *testing.T) {
func TestSendResultDeleteEventHaveLatestIndex(t *testing.T) {
codec := testapi.Default.Codec()
filter := func(obj runtime.Object) bool {
filterFunc := func(obj runtime.Object) bool {
return obj.(*api.Pod).Name != "bar"
}
filter := storage.NewSimpleFilter(filterFunc)
w := newEtcdWatcher(false, false, nil, filter, codec, versioner, nil, &fakeEtcdCache{})
eventChan := make(chan watch.Event, 1)