-
Notifications
You must be signed in to change notification settings - Fork 27
/
suite_test.go
78 lines (62 loc) · 1.32 KB
/
suite_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package bokchoy_test
import (
"context"
"fmt"
"log"
"os"
"testing"
"github.com/thoas/bokchoy"
"github.com/thoas/bokchoy/logging"
"github.com/thoas/bokchoy/middleware"
)
type suiteServer struct {
}
func (s suiteServer) Start(context.Context) error {
return nil
}
func (s suiteServer) Stop(context.Context) {
}
type suite struct {
bokchoy *bokchoy.Bokchoy
}
type FuncTest func(t *testing.T, s *suite)
// nolint
func run(t *testing.T, f FuncTest) {
logger, err := logging.NewDevelopmentLogger()
if err != nil {
log.Fatal(err)
}
defer logger.Sync()
ctx := context.Background()
addr := fmt.Sprintf("%s:%s", os.Getenv("REDIS_HOST"), os.Getenv("REDIS_PORT"))
bok, err := bokchoy.New(ctx, bokchoy.Config{
Broker: bokchoy.BrokerConfig{
Type: "redis",
Redis: bokchoy.RedisConfig{
Type: "client",
Client: bokchoy.RedisClientConfig{
Addr: addr,
},
},
},
Queues: []bokchoy.QueueConfig{
{
Name: "tests.task.message",
},
},
},
bokchoy.WithQueues([]string{"tasks.message"}),
bokchoy.WithServers([]bokchoy.Server{suiteServer{}}),
bokchoy.WithLogger(logger.With(logging.String("logger", "bokchoy"))))
if err != nil {
panic(err)
}
bok.Use(middleware.RequestID)
bok.Use(middleware.Recoverer)
err = bok.Empty(ctx)
if err != nil {
panic(err)
}
suite := &suite{bok}
f(t, suite)
}