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.

57 lines
1.1 KiB

  1. package pebble
  2. import (
  3. "io/ioutil"
  4. "os"
  5. "testing"
  6. "github.com/iden3/go-merkletree/db"
  7. "github.com/iden3/go-merkletree/db/test"
  8. "github.com/stretchr/testify/require"
  9. )
  10. var rmDirs []string
  11. func pebbleStorage(t *testing.T) db.Storage {
  12. dir, err := ioutil.TempDir("", "db")
  13. rmDirs = append(rmDirs, dir)
  14. if err != nil {
  15. t.Fatal(err)
  16. return nil
  17. }
  18. sto, err := NewPebbleStorage(dir, false)
  19. if err != nil {
  20. t.Fatal(err)
  21. return nil
  22. }
  23. return sto
  24. }
  25. func TestPebble(t *testing.T) {
  26. test.TestReturnKnownErrIfNotExists(t, pebbleStorage(t))
  27. test.TestStorageInsertGet(t, pebbleStorage(t))
  28. test.TestStorageWithPrefix(t, pebbleStorage(t))
  29. test.TestConcatTx(t, pebbleStorage(t))
  30. test.TestIterate(t, pebbleStorage(t))
  31. test.TestList(t, pebbleStorage(t))
  32. }
  33. func TestPebbleInterface(t *testing.T) {
  34. var db db.Storage //nolint:gosimple
  35. dir, err := ioutil.TempDir("", "db")
  36. require.Nil(t, err)
  37. rmDirs = append(rmDirs, dir)
  38. sto, err := NewPebbleStorage(dir, false)
  39. require.Nil(t, err)
  40. db = sto
  41. require.NotNil(t, db)
  42. }
  43. func TestMain(m *testing.M) {
  44. result := m.Run()
  45. for _, dir := range rmDirs {
  46. os.RemoveAll(dir)
  47. }
  48. os.Exit(result)
  49. }