Cockroach store feature completion (#1358)

* Start fixing cockroach store

* Add prefix, suffix, limit, offset for cockroachdb store
This commit is contained in:
Jake Sanders
2020-03-17 16:15:23 +00:00
committed by GitHub
parent b3c631dd38
commit 638c219736
3 changed files with 129 additions and 9 deletions

View File

@@ -14,8 +14,8 @@ func TestSQL(t *testing.T) {
connection := fmt.Sprintf(
"host=%s port=%d user=%s sslmode=disable dbname=%s",
"localhost",
5432,
"jake",
26257,
"root",
"test",
)
db, err := sql.Open("postgres", connection)
@@ -32,6 +32,10 @@ func TestSQL(t *testing.T) {
store.Nodes(connection),
)
if err := sqlStore.Init(); err != nil {
t.Fatal(err)
}
keys, err := sqlStore.List()
if err != nil {
t.Error(err)
@@ -74,7 +78,7 @@ func TestSQL(t *testing.T) {
err = sqlStore.Write(&store.Record{
Key: "test",
Value: []byte("bar"),
Expiry: time.Minute,
Expiry: time.Second * 10,
})
if err != nil {
t.Error(err)
@@ -89,7 +93,7 @@ func TestSQL(t *testing.T) {
t.Error("Expected bar, got ", string(records[0].Value))
}
time.Sleep(61 * time.Second)
time.Sleep(11 * time.Second)
_, err = sqlStore.Read("test")
switch err {
case nil:
@@ -99,4 +103,17 @@ func TestSQL(t *testing.T) {
case store.ErrNotFound:
break
}
sqlStore.Delete("bar")
sqlStore.Write(&store.Record{Key: "aaa", Value: []byte("bbb"), Expiry: 5 * time.Second})
sqlStore.Write(&store.Record{Key: "aaaa", Value: []byte("bbb"), Expiry: 5 * time.Second})
sqlStore.Write(&store.Record{Key: "aaaaa", Value: []byte("bbb"), Expiry: 5 * time.Second})
results, err := sqlStore.Read("a", store.ReadPrefix())
if len(results) != 3 {
t.Fatal("Results should have returned 3 records")
}
time.Sleep(6 * time.Second)
results, err = sqlStore.Read("a", store.ReadPrefix())
if len(results) != 0 {
t.Fatal("Results should have returned 0 records")
}
}