diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/hub/src/spreadspace.org/sfive/s5store_test.go | 49 |
1 files changed, 45 insertions, 4 deletions
diff --git a/src/hub/src/spreadspace.org/sfive/s5store_test.go b/src/hub/src/spreadspace.org/sfive/s5store_test.go index 680f32b..1d369de 100644 --- a/src/hub/src/spreadspace.org/sfive/s5store_test.go +++ b/src/hub/src/spreadspace.org/sfive/s5store_test.go @@ -205,6 +205,10 @@ func TestAppendAndFetch(t *testing.T) { } defer store.Close() + if _, err := store.GetUpdate(17); err != ErrNotFound { + t.Fatalf("fetching not exisiting update should return non-found, error=%v", err) + } + upd := updateData upd.StartTime = time.Date(2014, time.August, 24, 14, 35, 33, 847000000, time.UTC) upd.Data.Clients = clientsData @@ -298,7 +302,7 @@ func TestGetUpdatesAfter(t *testing.T) { t.Fatalf("creating a read-only database should throw an error") } - // prepare a store with 3 data-update + // prepare a store with 3 data-updates store, err := NewStore(testBoltPath, false) if err != nil { t.Fatalf("unexpected error: %v", err) @@ -322,17 +326,54 @@ func TestGetUpdatesAfter(t *testing.T) { upd.StartTime = upd.StartTime.Add(time.Duration(upd.Duration) * time.Millisecond) } - updList, err := store.GetUpdatesAfter(0, -1) + // all the updates + updList, err := store.GetUpdatesAfter(-1, -1) if err != nil { t.Fatalf("failed to fetch updates: %v", err) } - for i, _ := range updList { updList[i].StartTime = updList[i].StartTime.UTC() // this would normally be handled by the protocol encoder } if !reflect.DeepEqual(expected, updList) { - t.Fatalf("failed to fetch update\nactual: %v\nexpected: %v\n", updList, expected) + t.Fatalf("failed to fetch updates\nactual: %v\nexpected: %v\n", updList, expected) + } + + // first 2 + updList, err = store.GetUpdatesAfter(0, 2) + if err != nil { + t.Fatalf("failed to fetch updates: %v", err) + } + for i, _ := range updList { + updList[i].StartTime = updList[i].StartTime.UTC() // this would normally be handled by the protocol encoder + } + if len(updList) != 2 { + t.Fatalf("failed to fetch updates: got %d updates, expected 1", len(updList)) + } + if !reflect.DeepEqual(expected[:2], updList) { + t.Fatalf("failed to fetch updates\nactual: %v\nexpected: %v\n", updList, expected[:2]) + } + + // all after id 2 + updList, err = store.GetUpdatesAfter(2, -1) + if err != nil { + t.Fatalf("failed to fetch updates: %v", err) + } + for i, _ := range updList { + updList[i].StartTime = updList[i].StartTime.UTC() // this would normally be handled by the protocol encoder + } + + if !reflect.DeepEqual(expected[2:], updList) { + t.Fatalf("failed to fetch updates\nactual: %v\nexpected: %v\n", updList, expected[2:]) + } + + // all after id 3 -> should return nothing + updList, err = store.GetUpdatesAfter(3, -1) + if err != nil { + t.Fatalf("failed to fetch updates: %v", err) + } + if len(updList) != 0 { + t.Fatalf("failed to fetch updates: got %d updates, expected 0", len(updList)) } } |