From 39e1567d0ad3ef578bca645c914fc0c6b8f0fbed Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Tue, 8 May 2018 00:53:33 +0200 Subject: [PATCH] Add iterator tests --- remotedb/remotedb_test.go | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/remotedb/remotedb_test.go b/remotedb/remotedb_test.go index a5b77cf5a..c4014fe66 100644 --- a/remotedb/remotedb_test.go +++ b/remotedb/remotedb_test.go @@ -36,9 +36,38 @@ func TestRemoteDB(t *testing.T) { gv1 := client.Get(k1) require.Equal(t, gv1, vv1) + // Simple iteration + itr := client.Iterator(nil, nil) + itr.Next() + require.Equal(t, itr.Key(), []byte("key-1")) + require.Equal(t, itr.Value(), []byte("value-1")) + require.Panics(t, itr.Next) + itr.Close() + + // Set some more keys + k2 := []byte("key-2") + v2 := []byte("value-2") + client.Set(k2, v2) + gv2 := client.Get(k2) + require.Equal(t, gv2, v2) + + // More iteration + itr = client.Iterator(nil, nil) + itr.Next() + require.Equal(t, itr.Key(), []byte("key-1")) + require.Equal(t, itr.Value(), []byte("value-1")) + itr.Next() + require.Equal(t, itr.Key(), []byte("key-2")) + require.Equal(t, itr.Value(), []byte("value-2")) + require.Panics(t, itr.Next) + // Deletion client.Delete(k1) - gv2 := client.Get(k1) + client.Delete(k2) + gv1 = client.Get(k1) + gv2 = client.Get(k2) require.Equal(t, len(gv2), 0, "after deletion, not expecting the key to exist anymore") - require.NotEqual(t, len(gv1), len(gv2), "after deletion, not expecting the key to exist anymore") + require.Equal(t, len(gv1), 0, "after deletion, not expecting the key to exist anymore") + + // TODO Batch tests }