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.2 KiB

  1. package leveldb
  2. import (
  3. "github.com/iden3/go-merkletree"
  4. "io/ioutil"
  5. "os"
  6. "testing"
  7. "github.com/iden3/go-merkletree/db/test"
  8. "github.com/stretchr/testify/require"
  9. )
  10. var rmDirs []string
  11. func levelDbStorage(t *testing.T) merkletree.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 := NewLevelDbStorage(dir, false)
  19. if err != nil {
  20. t.Fatal(err)
  21. return nil
  22. }
  23. return sto
  24. }
  25. func TestLevelDb(t *testing.T) {
  26. test.TestReturnKnownErrIfNotExists(t, levelDbStorage(t))
  27. test.TestStorageInsertGet(t, levelDbStorage(t))
  28. test.TestStorageWithPrefix(t, levelDbStorage(t))
  29. test.TestConcatTx(t, levelDbStorage(t))
  30. test.TestList(t, levelDbStorage(t))
  31. test.TestIterate(t, levelDbStorage(t))
  32. }
  33. func TestLevelDbInterface(t *testing.T) {
  34. var db merkletree.Storage //nolint:gosimple
  35. dir, err := ioutil.TempDir("", "db")
  36. require.Nil(t, err)
  37. rmDirs = append(rmDirs, dir)
  38. sto, err := NewLevelDbStorage(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) //nolint:errcheck,gosec
  47. }
  48. os.Exit(result)
  49. }