You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.1 KiB

  1. // Copyright (c) 2014, Suryandaru Triandana <syndtr@gmail.com>
  2. // All rights reserved.
  3. //
  4. // Use of this source code is governed by a BSD-style license that can be
  5. // found in the LICENSE file.
  6. package leveldb
  7. import (
  8. . "github.com/onsi/gomega"
  9. "github.com/syndtr/goleveldb/leveldb/iterator"
  10. "github.com/syndtr/goleveldb/leveldb/opt"
  11. "github.com/syndtr/goleveldb/leveldb/testutil"
  12. "github.com/syndtr/goleveldb/leveldb/util"
  13. )
  14. type testingDB struct {
  15. *DB
  16. ro *opt.ReadOptions
  17. wo *opt.WriteOptions
  18. stor *testutil.Storage
  19. }
  20. func (t *testingDB) TestPut(key []byte, value []byte) error {
  21. return t.Put(key, value, t.wo)
  22. }
  23. func (t *testingDB) TestDelete(key []byte) error {
  24. return t.Delete(key, t.wo)
  25. }
  26. func (t *testingDB) TestGet(key []byte) (value []byte, err error) {
  27. return t.Get(key, t.ro)
  28. }
  29. func (t *testingDB) TestHas(key []byte) (ret bool, err error) {
  30. return t.Has(key, t.ro)
  31. }
  32. func (t *testingDB) TestNewIterator(slice *util.Range) iterator.Iterator {
  33. return t.NewIterator(slice, t.ro)
  34. }
  35. func (t *testingDB) TestClose() {
  36. err := t.Close()
  37. ExpectWithOffset(1, err).NotTo(HaveOccurred())
  38. err = t.stor.Close()
  39. ExpectWithOffset(1, err).NotTo(HaveOccurred())
  40. }
  41. func newTestingDB(o *opt.Options, ro *opt.ReadOptions, wo *opt.WriteOptions) *testingDB {
  42. stor := testutil.NewStorage()
  43. db, err := Open(stor, o)
  44. // FIXME: This may be called from outside It, which may cause panic.
  45. Expect(err).NotTo(HaveOccurred())
  46. return &testingDB{
  47. DB: db,
  48. ro: ro,
  49. wo: wo,
  50. stor: stor,
  51. }
  52. }
  53. type testingTransaction struct {
  54. *Transaction
  55. ro *opt.ReadOptions
  56. wo *opt.WriteOptions
  57. }
  58. func (t *testingTransaction) TestPut(key []byte, value []byte) error {
  59. return t.Put(key, value, t.wo)
  60. }
  61. func (t *testingTransaction) TestDelete(key []byte) error {
  62. return t.Delete(key, t.wo)
  63. }
  64. func (t *testingTransaction) TestGet(key []byte) (value []byte, err error) {
  65. return t.Get(key, t.ro)
  66. }
  67. func (t *testingTransaction) TestHas(key []byte) (ret bool, err error) {
  68. return t.Has(key, t.ro)
  69. }
  70. func (t *testingTransaction) TestNewIterator(slice *util.Range) iterator.Iterator {
  71. return t.NewIterator(slice, t.ro)
  72. }
  73. func (t *testingTransaction) TestClose() {}