Skip to content

Commit

Permalink
add setupTestRedis to interacor UT
Browse files Browse the repository at this point in the history
  • Loading branch information
akiyatomohiro committed Jan 30, 2025
1 parent c655f89 commit 4beff77
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion server/internal/usecase/interactor/style_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ func TestImportStyles(t *testing.T) {
ctx := context.Background()

db := memory.New()
ifs := NewStyle(db)

redis, cleanup := setupTestRedis(t)
defer cleanup()

ifs := NewStyle(db, redis)

ws := workspace.New().NewID().Policy(policy.ID("policy").Ref()).MustBuild()
prj, _ := project.New().NewID().Workspace(ws.ID()).Build()
Expand Down
29 changes: 29 additions & 0 deletions server/internal/usecase/interactor/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package interactor

import (
"testing"

"github.com/alicebob/miniredis/v2"
"github.com/go-redis/redis/v8"
infraRedis "github.com/reearth/reearth/server/internal/infrastructure/redis"
"github.com/reearth/reearth/server/internal/usecase/gateway"
)

func setupTestRedis(t *testing.T) (gateway.RedisGateway, func()) {
t.Helper()

mr, err := miniredis.Run()
if err != nil {
t.Fatal(err)
}
cleanup := func() {
mr.Close()
}

redisClient := redis.NewClient(&redis.Options{
Addr: mr.Addr(),
})
redisAdapter := infraRedis.NewRedisAdapter(redisClient)

return redisAdapter, cleanup
}

0 comments on commit 4beff77

Please sign in to comment.