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.

32 lines
794 B

  1. package pubsub_test
  2. import (
  3. "context"
  4. "testing"
  5. "github.com/stretchr/testify/require"
  6. abci "github.com/tendermint/tendermint/abci/types"
  7. "github.com/tendermint/tendermint/libs/pubsub"
  8. "github.com/tendermint/tendermint/libs/pubsub/query"
  9. )
  10. func TestExample(t *testing.T) {
  11. ctx, cancel := context.WithCancel(context.Background())
  12. defer cancel()
  13. s := newTestServer(ctx, t)
  14. sub := newTestSub(t).must(s.SubscribeWithArgs(ctx, pubsub.SubscribeArgs{
  15. ClientID: "example-client",
  16. Query: query.MustCompile(`abci.account.name='John'`),
  17. }))
  18. events := []abci.Event{
  19. {
  20. Type: "abci.account",
  21. Attributes: []abci.EventAttribute{{Key: "name", Value: "John"}},
  22. },
  23. }
  24. require.NoError(t, s.PublishWithEvents(ctx, "Tombstone", events))
  25. sub.mustReceive(ctx, "Tombstone")
  26. }