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.

34 lines
869 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/internal/pubsub"
  8. "github.com/tendermint/tendermint/internal/pubsub/query"
  9. "github.com/tendermint/tendermint/libs/log"
  10. )
  11. func TestExample(t *testing.T) {
  12. ctx, cancel := context.WithCancel(context.Background())
  13. defer cancel()
  14. s := newTestServer(ctx, t, log.TestingLogger())
  15. sub := newTestSub(t).must(s.SubscribeWithArgs(ctx, pubsub.SubscribeArgs{
  16. ClientID: "example-client",
  17. Query: query.MustCompile(`abci.account.name='John'`),
  18. }))
  19. events := []abci.Event{
  20. {
  21. Type: "abci.account",
  22. Attributes: []abci.EventAttribute{{Key: "name", Value: "John"}},
  23. },
  24. }
  25. require.NoError(t, s.PublishWithEvents(ctx, "Tombstone", events))
  26. sub.mustReceive(ctx, "Tombstone")
  27. }