Fix GC deleting values without expiry (#54)

* Test MYSQL Fix

* Test

* Add postgres

* Fix mysql

* Fix sqlite
This commit is contained in:
hi019
2021-03-18 17:09:06 -04:00
committed by GitHub
parent 9829073dd7
commit a66230ef17
6 changed files with 108 additions and 15 deletions

View File

@@ -1,6 +1,7 @@
package sqlite3
import (
"database/sql"
"testing"
"time"
@@ -119,6 +120,31 @@ func Test_SQLite3_Reset(t *testing.T) {
utils.AssertEqual(t, true, len(result) == 0)
}
func Test_SQLite3_GC(t *testing.T) {
var (
testVal = []byte("doe")
)
// This key should expire
err := testStore.Set("john", testVal, time.Nanosecond)
utils.AssertEqual(t, nil, err)
testStore.gc(time.Now())
row := testStore.db.QueryRow(testStore.sqlSelect, "john")
err = row.Scan(nil, nil)
utils.AssertEqual(t, sql.ErrNoRows, err)
// This key should not expire
err = testStore.Set("john", testVal, 0)
utils.AssertEqual(t, nil, err)
testStore.gc(time.Now())
val, err := testStore.Get("john")
utils.AssertEqual(t, nil, err)
utils.AssertEqual(t, testVal, val)
}
func Test_SQLite3_Close(t *testing.T) {
utils.AssertEqual(t, nil, testStore.Close())
}