backend_test.go 536 B

1234567891011121314151617181920212223242526272829
  1. package backend
  2. import (
  3. "os"
  4. "reflect"
  5. "testing"
  6. "time"
  7. )
  8. func TestBackendPut(t *testing.T) {
  9. backend := New("test", 10*time.Second, 10000)
  10. defer backend.Close()
  11. defer os.Remove("test")
  12. v := []byte("foo")
  13. batchTx := backend.BatchTx()
  14. batchTx.Lock()
  15. batchTx.UnsafeCreateBucket([]byte("test"))
  16. batchTx.UnsafePut([]byte("test"), []byte("foo"), v)
  17. _, gv := batchTx.UnsafeRange([]byte("test"), v, nil, -1)
  18. if !reflect.DeepEqual(gv[0], v) {
  19. t.Errorf("v = %s, want %s", string(gv[0]), string(v))
  20. }
  21. batchTx.Unlock()
  22. }