mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +00:00
* 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
36 lines
741 B
Go
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)
|
|
})
|
|
}
|