From 07e5119b5696b77f3dc766c38c9a64234c0b52c4 Mon Sep 17 00:00:00 2001 From: Maurizio Porrato Date: Sat, 22 May 2021 10:44:22 +0100 Subject: [PATCH] Add test cases for store.Count() --- bsync/store_test.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/bsync/store_test.go b/bsync/store_test.go index f4e8e3c..becec85 100644 --- a/bsync/store_test.go +++ b/bsync/store_test.go @@ -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)