Files
coder/coderd/database/pubsub_memory_test.go
Steven Masley 591523a078 chore: Move httpapi, httpmw, & database into coderd (#568)
* chore: Move httpmw to /coderd directory
httpmw is specific to coderd and should be scoped under coderd

* chore: Move httpapi to /coderd directory
httpapi is specific to coderd and should be scoped under coderd

* chore: Move database  to /coderd directory
database is specific to coderd and should be scoped under coderd

* chore: Update codecov & gitattributes for generated files
* chore: Update Makefile
2022-03-25 16:07:45 -05:00

36 lines
741 B
Go

package database_test
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/coder/coder/coderd/database"
)
func TestPubsubMemory(t *testing.T) {
t.Parallel()
t.Run("Memory", func(t *testing.T) {
t.Parallel()
pubsub := database.NewPubsubInMemory()
event := "test"
data := "testing"
messageChannel := make(chan []byte)
cancelFunc, err := pubsub.Subscribe(event, func(ctx context.Context, message []byte) {
messageChannel <- message
})
require.NoError(t, err)
defer cancelFunc()
go func() {
err = pubsub.Publish(event, []byte(data))
require.NoError(t, err)
}()
message := <-messageChannel
assert.Equal(t, string(message), data)
})
}