-
Notifications
You must be signed in to change notification settings - Fork 11
/
host_test.go
195 lines (180 loc) · 5.61 KB
/
host_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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package provider
import (
"bytes"
"log/slog"
"strings"
"testing"
)
func TestRedactedStringLogging(t *testing.T) {
var buf bytes.Buffer
secret := "its-a-secret"
redactedString := RedactedString(secret)
jsonSlog := slog.New(slog.NewJSONHandler(&buf, nil))
jsonSlog.Info("jsonSlog", "redactedString", redactedString)
if !strings.Contains(buf.String(), "\"redactedString\":\"redacted(string)\"") || strings.Contains(buf.String(), secret) {
t.Error("json slog handler output should not have contained the secret string")
}
buf.Reset()
textSlog := slog.New(slog.NewTextHandler(&buf, nil))
textSlog.Info("textSlog", "redactedString", redactedString)
if !strings.Contains(buf.String(), "redactedString=redacted(string)") || strings.Contains(buf.String(), secret) {
t.Error("text slog handler should not have contained the secret string")
}
}
func TestOtelConfigProtocol(t *testing.T) {
type test struct {
name string
config OtelConfig
protocol string
}
tests := []test{
{
name: "Defaults to http",
config: OtelConfig{},
protocol: "http",
},
{
name: "Explicit Grpc Rust enum variant",
config: OtelConfig{Protocol: "Grpc"},
protocol: "grpc",
},
{
name: "Explicit Http Rust enum variant",
config: OtelConfig{Protocol: "Http"},
protocol: "http",
},
}
for _, tc := range tests {
if tc.config.OtelProtocol() != tc.protocol {
t.Fatalf("%s / OtelProtocol: expected %q, got: %q", tc.name, tc.protocol, tc.config.OtelProtocol())
}
}
}
func TestOtelConfigURLs(t *testing.T) {
type test struct {
name string
config OtelConfig
tracesURL string
metricsURL string
logsURL string
}
tests := []test{
{
name: "Defaults with HTTP",
config: OtelConfig{},
tracesURL: "http://localhost:4318/v1/traces",
metricsURL: "http://localhost:4318/v1/metrics",
logsURL: "http://localhost:4318/v1/logs",
},
{
name: "Defaults with gRPC",
config: OtelConfig{Protocol: "Grpc"},
tracesURL: "http://localhost:4317",
metricsURL: "http://localhost:4317",
logsURL: "http://localhost:4317",
},
{
name: "Custom ObservabilityEndpoint",
config: OtelConfig{ObservabilityEndpoint: "https://api.opentelemetry.com"},
tracesURL: "https://api.opentelemetry.com/v1/traces",
metricsURL: "https://api.opentelemetry.com/v1/metrics",
logsURL: "https://api.opentelemetry.com/v1/logs",
},
{
name: "Custom ObservabilityEndpoint with gRPC",
config: OtelConfig{Protocol: "grpc", ObservabilityEndpoint: "https://api.opentelemetry.com"},
tracesURL: "https://api.opentelemetry.com",
metricsURL: "https://api.opentelemetry.com",
logsURL: "https://api.opentelemetry.com",
},
{
name: "Custom TracesEndpoint",
config: OtelConfig{TracesEndpoint: "https://api.opentelemetry.com/v1/traces"},
tracesURL: "https://api.opentelemetry.com/v1/traces",
metricsURL: "http://localhost:4318/v1/metrics",
logsURL: "http://localhost:4318/v1/logs",
},
{
name: "Custom MetricsEndpoint",
config: OtelConfig{MetricsEndpoint: "https://api.opentelemetry.com/v1/metrics"},
tracesURL: "http://localhost:4318/v1/traces",
metricsURL: "https://api.opentelemetry.com/v1/metrics",
logsURL: "http://localhost:4318/v1/logs",
},
{
name: "Custom LogsEndpoint",
config: OtelConfig{LogsEndpoint: "https://api.opentelemetry.com/v1/logs"},
tracesURL: "http://localhost:4318/v1/traces",
metricsURL: "http://localhost:4318/v1/metrics",
logsURL: "https://api.opentelemetry.com/v1/logs",
},
}
for _, tc := range tests {
if tc.config.TracesURL() != tc.tracesURL {
t.Fatalf("%s / TracesURL: expected %s, got: %s", tc.name, tc.tracesURL, tc.config.TracesURL())
}
if tc.config.MetricsURL() != tc.metricsURL {
t.Fatalf("%s / MetricsURL: expected %s, got: %s", tc.name, tc.metricsURL, tc.config.MetricsURL())
}
if tc.config.LogsURL() != tc.logsURL {
t.Fatalf("%s / LogsURL: expected %s, got: %s", tc.name, tc.logsURL, tc.config.LogsURL())
}
}
}
func TestOtelConfigBooleans(t *testing.T) {
type test struct {
name string
config OtelConfig
tracesEnabled bool
metricsEnabled bool
logsEnabled bool
}
tests := []test{
{
name: "Defaults",
config: OtelConfig{},
tracesEnabled: false,
metricsEnabled: false,
logsEnabled: false,
},
{
name: "Enable all with EnableObservability",
config: OtelConfig{EnableObservability: true},
tracesEnabled: true,
metricsEnabled: true,
logsEnabled: true,
},
{
name: "Enable just traces",
config: OtelConfig{EnableTraces: true},
tracesEnabled: true,
metricsEnabled: false,
logsEnabled: false,
},
{
name: "Enable just metrics",
config: OtelConfig{EnableMetrics: true},
tracesEnabled: false,
metricsEnabled: true,
logsEnabled: false,
},
{
name: "Enable just logs",
config: OtelConfig{EnableLogs: true},
tracesEnabled: false,
metricsEnabled: false,
logsEnabled: true,
},
}
for _, tc := range tests {
if tc.config.TracesEnabled() != tc.tracesEnabled {
t.Fatalf("%s / TracesEnabled: expected %t, got: %t", tc.name, tc.tracesEnabled, tc.config.TracesEnabled())
}
if tc.config.MetricsEnabled() != tc.metricsEnabled {
t.Fatalf("%s / MetricsEnabled: expected %t, got: %t", tc.name, tc.metricsEnabled, tc.config.MetricsEnabled())
}
if tc.config.LogsEnabled() != tc.logsEnabled {
t.Fatalf("%s / LogsEnabled: expected %t, got: %t", tc.name, tc.logsEnabled, tc.config.LogsEnabled())
}
}
}