This commit is contained in:
2024-01-17 12:02:03 -07:00
parent 161cc95538
commit f8ce4e3b48
43 changed files with 1614 additions and 21 deletions

27
lib/redis_test.go Normal file
View File

@ -0,0 +1,27 @@
package lib_test
import (
"testing"
"github.com/go-redis/redismock/v9"
"github.com/stretchr/testify/assert"
"goth.stack/lib"
)
func TestPublish(t *testing.T) {
db, mock := redismock.NewClientMock()
mock.ExpectPublish("mychannel", "mymessage").SetVal(1)
err := lib.Publish(db, "mychannel", "mymessage")
assert.NoError(t, err)
assert.NoError(t, mock.ExpectationsWereMet())
}
// Then you can check the channel name in your test
func TestSubscribe(t *testing.T) {
db, _ := redismock.NewClientMock()
pubsub, channel := lib.Subscribe(db, "mychannel")
assert.NotNil(t, pubsub)
assert.Equal(t, "mychannel", channel)
}