func TestDelete(t *testing.T) { client := clientOrAbort(t) ds, err := NewDatastore(client) if err != nil { t.Fatal(err) } key, val := datastore.NewKey("foo"), []byte("bar") dstest.Nil(ds.Put(key, val), t) dstest.Nil(ds.Delete(key), t) hasAfterDelete, err := ds.Has(key) if err != nil { t.Fatal(err) } if hasAfterDelete { t.Fail() } }
func TestExpiry(t *testing.T) { ttl := 1 * time.Second client := clientOrAbort(t) ds, err := NewExpiringDatastore(client, ttl) if err != nil { t.Fatal(err) } key, val := datastore.NewKey("foo"), []byte("bar") dstest.Nil(ds.Put(key, val), t) time.Sleep(ttl + 1*time.Second) dstest.Nil(ds.Delete(key), t) hasAfterExpiration, err := ds.Has(key) if err != nil { t.Fatal(err) } if hasAfterExpiration { t.Fail() } }
func TestPutGetBytes(t *testing.T) { client := clientOrAbort(t) ds, err := NewDatastore(client) if err != nil { t.Fatal(err) } key, val := datastore.NewKey("foo"), []byte("bar") dstest.Nil(ds.Put(key, val), t) v, err := ds.Get(key) if err != nil { t.Fatal(err) } if bytes.Compare(v.([]byte), val) != 0 { t.Fail() } }