Initial support for listing from in-memory cache.

This commit is contained in:
Wojciech Tyczynski
2015-10-23 16:13:21 +02:00
parent cc53619372
commit 652fb090eb
4 changed files with 69 additions and 45 deletions

View File

@@ -230,6 +230,24 @@ func TestEvents(t *testing.T) {
}
}
func TestWaitUntilFreshAndList(t *testing.T) {
store := newWatchCache(3)
// In background, update the store.
go func() {
store.Add(makeTestPod("foo", 2))
store.Add(makeTestPod("bar", 5))
}()
list, resourceVersion := store.WaitUntilFreshAndList(4)
if resourceVersion != 5 {
t.Errorf("unexpected resourceVersion: %v, expected: 5", resourceVersion)
}
if len(list) != 2 {
t.Errorf("unexpected list returned: %#v", list)
}
}
type testLW struct {
ListFunc func() (runtime.Object, error)
WatchFunc func(options api.ListOptions) (watch.Interface, error)
@@ -244,7 +262,7 @@ func TestReflectorForWatchCache(t *testing.T) {
store := newWatchCache(5)
{
_, version := store.ListWithVersion()
_, version := store.WaitUntilFreshAndList(0)
if version != 0 {
t.Errorf("unexpected resource version: %d", version)
}
@@ -264,7 +282,7 @@ func TestReflectorForWatchCache(t *testing.T) {
r.ListAndWatch(util.NeverStop)
{
_, version := store.ListWithVersion()
_, version := store.WaitUntilFreshAndList(10)
if version != 10 {
t.Errorf("unexpected resource version: %d", version)
}