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.

43 lines
1005 B

  1. package db
  2. import (
  3. "fmt"
  4. "testing"
  5. "github.com/stretchr/testify/require"
  6. cmn "github.com/tendermint/tmlibs/common"
  7. )
  8. func testBackend(t *testing.T, backend string) {
  9. // Default
  10. dir, dirname := cmn.Tempdir(fmt.Sprintf("test_backend_%s_", backend))
  11. defer dir.Close()
  12. db := NewDB("testdb", backend, dirname)
  13. require.Nil(t, db.Get([]byte("")))
  14. require.Nil(t, db.Get(nil))
  15. // Set empty ("")
  16. db.Set([]byte(""), []byte(""))
  17. require.NotNil(t, db.Get([]byte("")))
  18. require.NotNil(t, db.Get(nil))
  19. require.Empty(t, db.Get([]byte("")))
  20. require.Empty(t, db.Get(nil))
  21. // Set empty (nil)
  22. db.Set([]byte(""), nil)
  23. require.NotNil(t, db.Get([]byte("")))
  24. require.NotNil(t, db.Get(nil))
  25. require.Empty(t, db.Get([]byte("")))
  26. require.Empty(t, db.Get(nil))
  27. // Delete
  28. db.Delete([]byte(""))
  29. require.Nil(t, db.Get([]byte("")))
  30. require.Nil(t, db.Get(nil))
  31. }
  32. func TestBackends(t *testing.T) {
  33. testBackend(t, CLevelDBBackendStr)
  34. testBackend(t, GoLevelDBBackendStr)
  35. testBackend(t, MemDBBackendStr)
  36. }