func TestDiscardReplica(t *testing.T) { for i := 0; i < 10; i++ { r := New(0, discard{}, memory.New()) storagetest.StorageTest(t, r) r = New(0, memory.New(), discard{}) storagetest.StorageTest(t, r) } }
func TestErrorReplica(t *testing.T) { for i := 0; i < 10; i++ { r := New(2, storagetest.Errstore{}, memory.New()) storagetest.StorageTest(t, r) r = New(2, memory.New(), storagetest.Errstore{}) storagetest.StorageTest(t, r) } }
func TestRest(t *testing.T) { storage = make(map[string][]byte) ts := httptest.NewServer(http.HandlerFunc(handler)) defer ts.Close() r := New(ts.URL) storagetest.StorageTest(t, r) }
func TestRedis(t *testing.T) { s, err := New("localhost:6379") if err != nil { t.Skip("error connecting to redis instance on localhost:6379 -- can't test") return } storagetest.StorageTest(t, s) }
func TestFS(t *testing.T) { dir, err := ioutil.TempDir(os.TempDir(), "shardedkv-fs-storagetest") if err != nil { t.Skipf("Unable to create temporary directory: %s", err) } m := New(dir) storagetest.StorageTest(t, m) // cleanup os.RemoveAll(dir) }
func TestSQL(t *testing.T) { f, err := ioutil.TempFile(os.TempDir(), "shardedkv-sql-storagetest") if err != nil { t.Skipf("unable to create tempfile: %s", err) } db, err := sql.Open("sqlite3", f.Name()) if err != nil { t.Errorf("error creating sqlite temp file") return } _, err = db.Exec(` CREATE TABLE Storage ( key VARCHAR(64) NOT NULL, value VARCHAR(256) NOT NULL ); `) if err != nil { t.Errorf("error creating table: %s", err) return } db.Close() var tblConf = TableConfig{ Table: "Storage", KeyColumn: "key", ValueColumn: "value", } connector := func() (*sql.DB, error) { return sql.Open("sqlite3", f.Name()) } s, err := New(connector, &tblConf) if err != nil { t.Errorf("error creating sqlite") return } storagetest.StorageTest(t, s) os.Remove(f.Name()) }
func TestMemory(t *testing.T) { m := New() storagetest.StorageTest(t, m) }
func TestBackoff(t *testing.T) { m := memory.New() b := &Storage{Store: m} storagetest.StorageTest(t, b) }