-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
test.go
59 lines (47 loc) · 1.47 KB
/
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
package test
import (
"context"
"sync"
"testing"
"time"
"github.com/plgd-dev/hub/v2/grpc-gateway/service"
"github.com/plgd-dev/hub/v2/pkg/log"
"github.com/plgd-dev/hub/v2/test/config"
"github.com/stretchr/testify/require"
)
func MakeConfig(t *testing.T) service.Config {
var cfg service.Config
cfg.Log = log.MakeDefaultConfig()
cfg.APIs.GRPC.Config = config.MakeGrpcServerConfig(config.GRPC_HOST)
cfg.APIs.GRPC.OwnerCacheExpiration = time.Minute
cfg.APIs.GRPC.SubscriptionBufferSize = 1000
cfg.APIs.GRPC.TLS.ClientCertificateRequired = false
cfg.Clients.IdentityStore.Connection = config.MakeGrpcClientConfig(config.IDENTITY_STORE_HOST)
cfg.Clients.Eventbus.NATS = config.MakeSubscriberConfig()
cfg.Clients.Eventbus.GoPoolSize = 16
cfg.Clients.ResourceAggregate.Connection = config.MakeGrpcClientConfig(config.RESOURCE_AGGREGATE_HOST)
cfg.Clients.ResourceDirectory.Connection = config.MakeGrpcClientConfig(config.RESOURCE_DIRECTORY_HOST)
cfg.Clients.OpenTelemetryCollector = config.MakeOpenTelemetryCollectorClient()
err := cfg.Validate()
require.NoError(t, err)
return cfg
}
func SetUp(t *testing.T) (TearDown func()) {
return New(t, MakeConfig(t))
}
func New(t *testing.T, cfg service.Config) func() {
ctx := context.Background()
logger := log.NewLogger(cfg.Log)
s, err := service.New(ctx, cfg, logger)
require.NoError(t, err)
var wg sync.WaitGroup
wg.Add(1)
go func() {
defer wg.Done()
_ = s.Serve()
}()
return func() {
s.Close()
wg.Wait()
}
}