Add test cases for store.Count()

This commit is contained in:
Maurizio Porrato 2021-05-22 10:44:22 +01:00
parent 95c4967f83
commit 07e5119b56
Signed by: guru
GPG Key ID: C622977DF024AC24
1 changed files with 20 additions and 0 deletions

View File

@ -13,6 +13,10 @@ import (
func testStoreHelper(t *testing.T, drv StoreDriver) {
store := NewStore(drv)
cnt := store.Count()
if cnt != 0 {
t.Errorf("Expected new store to be empty. It has %d syncs instead.", cnt)
}
v1 := "0.1.2"
time10 := time.Now().UTC()
t1, e1 := store.Create(v1)
@ -40,6 +44,10 @@ func testStoreHelper(t *testing.T, drv StoreDriver) {
"Create() returned an incorrect lastUpdated timestamp: %v (should be between %v and %v)",
t1.LastUpdated, time10, time11)
}
cnt = store.Count()
if cnt != 1 {
t.Errorf("Expected store size to be 1 after first Create(). Got %d instead.", cnt)
}
t2, e2 := store.Get(t1.ID)
if e2 != nil {
t.Errorf("Get() failed (%v)", e2)
@ -65,6 +73,10 @@ func testStoreHelper(t *testing.T, drv StoreDriver) {
"Update() returned an incorrect lastUpdated timestamp: %v (should be between %v and %v)",
t3, time30, time31)
}
cnt = store.Count()
if cnt != 1 {
t.Errorf("Expected store size to be 1 after successful Update(). Got %d instead.", cnt)
}
t4, e4 := store.Get(t1.ID)
if e4 != nil {
t.Errorf("Get() failed with error (%v)", e4)
@ -78,6 +90,10 @@ func testStoreHelper(t *testing.T, drv StoreDriver) {
if e5 != SyncConflictError {
t.Errorf("Expected SyncConflictError on Update() with incorrect lastUpdated, got %v instead", e5)
}
cnt = store.Count()
if cnt != 1 {
t.Errorf("Expected store size to be 1 after failed Update(). Got %d instead.", cnt)
}
}
func TestStore_Mem(t *testing.T) {
@ -136,6 +152,10 @@ func testStoreConcurrencyHelper(t *testing.T, drv StoreDriver, workers, rounds i
if err != nil {
t.Error("failed to parse an integer: ", err)
}
cnt := store.Count()
if cnt != 1 {
t.Errorf("Expected store size to be 1. Got %d instead.", cnt)
}
expected := workers * rounds
if n != expected {
t.Errorf("inconsistent result: expected %d, got %d", expected, n)