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.

41 lines
1.1 KiB

  1. package remotedb_test
  2. import (
  3. "net"
  4. "testing"
  5. "github.com/stretchr/testify/require"
  6. "github.com/tendermint/tmlibs/grpcdb"
  7. "github.com/tendermint/tmlibs/remotedb"
  8. )
  9. func TestRemoteDB(t *testing.T) {
  10. ln, err := net.Listen("tcp", "0.0.0.0:0")
  11. require.Nil(t, err, "expecting a port to have been assigned on which we can listen")
  12. srv := grpcdb.NewServer()
  13. defer srv.Stop()
  14. go func() {
  15. if err := srv.Serve(ln); err != nil {
  16. t.Fatalf("BindServer: %v", err)
  17. }
  18. }()
  19. client, err := remotedb.NewInsecure(ln.Addr().String())
  20. require.Nil(t, err, "expecting a successful client creation")
  21. require.Nil(t, client.InitRemote(&remotedb.Init{Name: "test-remote-db", Type: "leveldb"}))
  22. k1 := []byte("key-1")
  23. v1 := client.Get(k1)
  24. require.Equal(t, 0, len(v1), "expecting no key1 to have been stored")
  25. vv1 := []byte("value-1")
  26. client.Set(k1, vv1)
  27. gv1 := client.Get(k1)
  28. require.Equal(t, gv1, vv1)
  29. // Deletion
  30. client.Delete(k1)
  31. gv2 := client.Get(k1)
  32. require.Equal(t, len(gv2), 0, "after deletion, not expecting the key to exist anymore")
  33. require.NotEqual(t, len(gv1), len(gv2), "after deletion, not expecting the key to exist anymore")
  34. }