-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.go
156 lines (138 loc) · 3.72 KB
/
config.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package test
import (
"os"
"path/filepath"
"runtime"
"time"
"github.com/alexfalkowski/go-service/cmd"
"github.com/alexfalkowski/go-service/database/sql/config"
"github.com/alexfalkowski/go-service/database/sql/pg"
"github.com/alexfalkowski/go-service/debug"
"github.com/alexfalkowski/go-service/hooks"
"github.com/alexfalkowski/go-service/marshaller"
"github.com/alexfalkowski/go-service/retry"
"github.com/alexfalkowski/go-service/security"
"github.com/alexfalkowski/go-service/server"
"github.com/alexfalkowski/go-service/telemetry/tracer"
"github.com/alexfalkowski/go-service/transport"
"github.com/alexfalkowski/go-service/transport/events"
"github.com/alexfalkowski/go-service/transport/grpc"
"github.com/alexfalkowski/go-service/transport/http"
)
const timeout = 2 * time.Second
// Config for test.
type Config struct {
Events events.Config `yaml:"events,omitempty" json:"events,omitempty" toml:"events,omitempty"`
config.Config `yaml:",inline" json:",inline" toml:",inline"`
}
// NewHook for test.
func NewHook() *hooks.Config {
return &hooks.Config{
Secret: "YWJjZGUxMjM0NQ==",
}
}
// NewRetry for test.
func NewRetry() *retry.Config {
return &retry.Config{
Timeout: timeout.String(),
Attempts: 1,
}
}
// NewSecureClientConfig for test.
func NewSecureClientConfig() *security.Config {
_, b, _, _ := runtime.Caller(0) //nolint:dogsled
dir := filepath.Dir(b)
return &security.Config{
Enabled: true,
CertFile: filepath.Join(dir, "certs/client-cert.pem"),
KeyFile: filepath.Join(dir, "certs/client-key.pem"),
}
}
// NewInsecureTransportConfig for test.
func NewInsecureTransportConfig() *transport.Config {
return &transport.Config{
HTTP: &http.Config{
Config: server.Config{
Enabled: true,
Port: Port(),
UserAgent: "TestHTTP/1.0",
Retry: NewRetry(),
},
},
GRPC: &grpc.Config{
Config: server.Config{
Enabled: true,
Port: Port(),
UserAgent: "TestGRPC/1.0",
Retry: NewRetry(),
},
},
}
}
// NewSecureTransportConfig for test.
func NewSecureTransportConfig() *transport.Config {
_, b, _, _ := runtime.Caller(0) //nolint:dogsled
dir := filepath.Dir(b)
s := &security.Config{
Enabled: true,
CertFile: filepath.Join(dir, "certs/cert.pem"),
KeyFile: filepath.Join(dir, "certs/key.pem"),
}
r := NewRetry()
return &transport.Config{
HTTP: &http.Config{
Config: server.Config{
Enabled: true,
Security: s,
Port: Port(),
UserAgent: "TestHTTP/1.0",
Retry: r,
},
},
GRPC: &grpc.Config{
Config: server.Config{
Enabled: true,
Security: s,
Port: Port(),
UserAgent: "TestGRPC/1.0",
Retry: r,
},
},
}
}
// NewDefaultTracerConfig for test.
func NewDefaultTracerConfig() *tracer.Config {
return &tracer.Config{
Enabled: true,
Host: "localhost:4318",
}
}
// NewBaselimeTracerConfig for test.
func NewBaselimeTracerConfig() *tracer.Config {
return &tracer.Config{
Enabled: true,
Kind: "baselime",
Key: os.Getenv("BASELIME_API_KEY"),
}
}
// NewPGConfig for test.
func NewPGConfig() *pg.Config {
return &pg.Config{Config: config.Config{
Masters: []config.DSN{{URL: "postgres://test:test@localhost:5432/test?sslmode=disable"}},
Slaves: []config.DSN{{URL: "postgres://test:test@localhost:5432/test?sslmode=disable"}},
MaxOpenConns: 5,
MaxIdleConns: 5,
ConnMaxLifetime: time.Hour.String(),
}}
}
// NewCmdConfig for test.
func NewCmdConfig(flag string) (*cmd.Config, error) {
p := marshaller.FactoryParams{YAML: marshaller.NewYAML(), TOML: marshaller.NewTOML()}
return cmd.NewConfig(flag, marshaller.NewFactory(p))
}
// NewDebugConfig for test.
func NewDebugConfig() *debug.Config {
return &debug.Config{
Port: Port(),
}
}