From ddb126db1709b1c7679b8370b508639991387bf0 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Sun, 8 May 2022 16:36:08 -0600 Subject: Move radix config into cfg, use that for integration tests --- srv/src/chat/chat_it_test.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'srv/src/chat') diff --git a/srv/src/chat/chat_it_test.go b/srv/src/chat/chat_it_test.go index 1767d88..b0d4431 100644 --- a/srv/src/chat/chat_it_test.go +++ b/srv/src/chat/chat_it_test.go @@ -1,4 +1,5 @@ //go:build integration +// +build integration package chat @@ -9,6 +10,7 @@ import ( "time" "github.com/google/uuid" + cfgpkg "github.com/mediocregopher/blog.mediocregopher.com/srv/cfg" "github.com/mediocregopher/mediocre-go-lib/v2/mlog" "github.com/mediocregopher/radix/v4" "github.com/stretchr/testify/assert" @@ -44,16 +46,25 @@ func (h *roomTestHarness) newMsg(t *testing.T) Message { } func newRoomTestHarness(t *testing.T) *roomTestHarness { + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) t.Cleanup(cancel) - redis, err := radix.Dial(ctx, "tcp", "127.0.0.1:6379") - assert.NoError(t, err) - t.Cleanup(func() { redis.Close() }) + cfg := cfgpkg.NewBlogCfg(cfgpkg.Params{ + Args: []string{}, // prevents the test process args from interfering + }) + + var radixClient cfgpkg.RadixClient + radixClient.SetupCfg(cfg) + t.Cleanup(func() { radixClient.Close() }) + + if err := cfg.Init(ctx); err != nil { + t.Fatal(err) + } roomParams := RoomParams{ Logger: mlog.NewLogger(nil), - Redis: redis, + Redis: radixClient.Client, ID: uuid.New().String(), MaxMessages: roomTestHarnessMaxMsgs, } @@ -63,7 +74,7 @@ func newRoomTestHarness(t *testing.T) *roomTestHarness { assert.NoError(t, err) t.Cleanup(func() { - err := redis.Do(context.Background(), radix.Cmd( + err := radixClient.Client.Do(context.Background(), radix.Cmd( nil, "DEL", roomParams.streamKey(), )) assert.NoError(t, err) -- cgit v1.2.3