Skip to content

Commit b9d975a

Browse files
committed
update test
Signed-off-by: alex boten <[email protected]>
1 parent b37ab00 commit b9d975a

File tree

4 files changed

+102
-54
lines changed

4 files changed

+102
-54
lines changed

otelconf/config_test.go

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,32 @@ func TestNewSDK(t *testing.T) {
450450
}
451451
}
452452

453+
func TestNewSDKWithEnvVar(t *testing.T) {
454+
cfg := []ConfigurationOption{
455+
WithContext(t.Context()),
456+
WithOpenTelemetryConfiguration(OpenTelemetryConfiguration{
457+
TracerProvider: &ResourceJson{},
458+
}),
459+
}
460+
// NewSDK without an env file set
461+
_, err := NewSDK(cfg...)
462+
require.Equal(t, newErrInvalid("tracer_provider"), err)
463+
// test a non existent file
464+
t.Setenv(envVarConfigFile, filepath.Join("testdata", "file_missing.yaml"))
465+
_, err = NewSDK(cfg...)
466+
require.Error(t, err)
467+
require.ErrorContains(t, err, "no such file or directory")
468+
// test a file that causes a parse error
469+
t.Setenv(envVarConfigFile, filepath.Join("testdata", "v1.0.0_invalid_nil_name.yaml"))
470+
_, err = NewSDK(cfg...)
471+
require.Error(t, err)
472+
require.ErrorIs(t, err, newErrRequired(&NameStringValuePair{}, "name"))
473+
// test a valid file, error is returned from the SDK instantiation
474+
t.Setenv(envVarConfigFile, filepath.Join("testdata", "v1.0.0.yaml"))
475+
_, err = NewSDK(cfg...)
476+
require.ErrorIs(t, err, newErrInvalid("otlp_file/development"))
477+
}
478+
453479
var v10OpenTelemetryConfig = OpenTelemetryConfiguration{
454480
Disabled: ptr(false),
455481
FileFormat: "1.0-rc.2",
@@ -557,9 +583,9 @@ var v10OpenTelemetryConfig = OpenTelemetryConfiguration{
557583
ExportTimeout: ptr(30000),
558584
Exporter: LogRecordExporter{
559585
OTLPHttp: &OTLPHttpExporter{
560-
CertificateFile: ptr("/app/cert.pem"),
561-
ClientCertificateFile: ptr("/app/cert.pem"),
562-
ClientKeyFile: ptr("/app/cert.pem"),
586+
CertificateFile: ptr("testdata/ca.crt"),
587+
ClientCertificateFile: ptr("testdata/client.crt"),
588+
ClientKeyFile: ptr("testdata/client.key"),
563589
Compression: ptr("gzip"),
564590
Encoding: ptr(OTLPHttpEncodingProtobuf),
565591
Endpoint: ptr("http://localhost:4318/v1/logs"),
@@ -579,9 +605,9 @@ var v10OpenTelemetryConfig = OpenTelemetryConfiguration{
579605
Batch: &BatchLogRecordProcessor{
580606
Exporter: LogRecordExporter{
581607
OTLPGrpc: &OTLPGrpcExporter{
582-
CertificateFile: ptr("/app/cert.pem"),
583-
ClientCertificateFile: ptr("/app/cert.pem"),
584-
ClientKeyFile: ptr("/app/cert.pem"),
608+
CertificateFile: ptr("testdata/ca.crt"),
609+
ClientCertificateFile: ptr("testdata/client.crt"),
610+
ClientKeyFile: ptr("testdata/client.key"),
585611
Compression: ptr("gzip"),
586612
Endpoint: ptr("http://localhost:4317"),
587613
Headers: []NameStringValuePair{
@@ -689,9 +715,9 @@ var v10OpenTelemetryConfig = OpenTelemetryConfiguration{
689715
},
690716
Exporter: PushMetricExporter{
691717
OTLPHttp: &OTLPHttpMetricExporter{
692-
CertificateFile: ptr("/app/cert.pem"),
693-
ClientCertificateFile: ptr("/app/cert.pem"),
694-
ClientKeyFile: ptr("/app/cert.pem"),
718+
CertificateFile: ptr("testdata/ca.crt"),
719+
ClientCertificateFile: ptr("testdata/client.crt"),
720+
ClientKeyFile: ptr("testdata/client.key"),
695721
Compression: ptr("gzip"),
696722
DefaultHistogramAggregation: ptr(ExporterDefaultHistogramAggregationBase2ExponentialBucketHistogram),
697723
Endpoint: ptr("http://localhost:4318/v1/metrics"),
@@ -712,9 +738,9 @@ var v10OpenTelemetryConfig = OpenTelemetryConfiguration{
712738
Periodic: &PeriodicMetricReader{
713739
Exporter: PushMetricExporter{
714740
OTLPGrpc: &OTLPGrpcMetricExporter{
715-
CertificateFile: ptr("/app/cert.pem"),
716-
ClientCertificateFile: ptr("/app/cert.pem"),
717-
ClientKeyFile: ptr("/app/cert.pem"),
741+
CertificateFile: ptr("testdata/ca.crt"),
742+
ClientCertificateFile: ptr("testdata/client.crt"),
743+
ClientKeyFile: ptr("testdata/client.key"),
718744
Compression: ptr("gzip"),
719745
DefaultHistogramAggregation: ptr(ExporterDefaultHistogramAggregationBase2ExponentialBucketHistogram),
720746
Endpoint: ptr("http://localhost:4317"),
@@ -863,9 +889,9 @@ var v10OpenTelemetryConfig = OpenTelemetryConfiguration{
863889
ExportTimeout: ptr(30000),
864890
Exporter: SpanExporter{
865891
OTLPHttp: &OTLPHttpExporter{
866-
CertificateFile: ptr("/app/cert.pem"),
867-
ClientCertificateFile: ptr("/app/cert.pem"),
868-
ClientKeyFile: ptr("/app/cert.pem"),
892+
CertificateFile: ptr("testdata/ca.crt"),
893+
ClientCertificateFile: ptr("testdata/client.crt"),
894+
ClientKeyFile: ptr("testdata/client.key"),
869895
Compression: ptr("gzip"),
870896
Encoding: ptr(OTLPHttpEncodingProtobuf),
871897
Endpoint: ptr("http://localhost:4318/v1/traces"),
@@ -885,9 +911,9 @@ var v10OpenTelemetryConfig = OpenTelemetryConfiguration{
885911
Batch: &BatchSpanProcessor{
886912
Exporter: SpanExporter{
887913
OTLPGrpc: &OTLPGrpcExporter{
888-
CertificateFile: ptr("/app/cert.pem"),
889-
ClientCertificateFile: ptr("/app/cert.pem"),
890-
ClientKeyFile: ptr("/app/cert.pem"),
914+
CertificateFile: ptr("testdata/ca.crt"),
915+
ClientCertificateFile: ptr("testdata/client.crt"),
916+
ClientKeyFile: ptr("testdata/client.key"),
891917
Compression: ptr("gzip"),
892918
Endpoint: ptr("http://localhost:4317"),
893919
Headers: []NameStringValuePair{

otelconf/testdata/client.crt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIDnzCCAoegAwIBAgIUBxmeJyLb45dq6RmW5bOFIl8VON0wDQYJKoZIhvcNAQEL
3+
BQAwXzELMAkGA1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4JAnrHWBeuiLNJoswdKbA3rQO1Z6u5ioakluNHiCJX6T
20+
fcJxbEVmorLNfBOnZTm61rPsC5aVtvFAxXDDb6B00KBW9FrV9m2MEFw71bMmC8X3
21+
rFaC9Gm5g2bfyX/65YBQyLwXRA==
22+
-----END CERTIFICATE-----

otelconf/testdata/v1.0.0.json

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
"exporter": {
1818
"otlp_http": {
1919
"endpoint": "http://localhost:4318/v1/logs",
20-
"certificate_file": "/app/cert.pem",
21-
"client_key_file": "/app/cert.pem",
22-
"client_certificate_file": "/app/cert.pem",
20+
"certificate_file": "testdata/ca.crt",
21+
"client_key_file": "testdata/client.key",
22+
"client_certificate_file": "testdata/client.crt",
2323
"headers": [
2424
{
2525
"name": "api-key",
@@ -39,9 +39,9 @@
3939
"exporter": {
4040
"otlp_grpc": {
4141
"endpoint": "http://localhost:4317",
42-
"certificate_file": "/app/cert.pem",
43-
"client_key_file": "/app/cert.pem",
44-
"client_certificate_file": "/app/cert.pem",
42+
"certificate_file": "testdata/ca.crt",
43+
"client_key_file": "testdata/client.key",
44+
"client_certificate_file": "testdata/client.crt",
4545
"headers": [
4646
{
4747
"name": "api-key",
@@ -144,9 +144,9 @@
144144
"exporter": {
145145
"otlp_http": {
146146
"endpoint": "http://localhost:4318/v1/metrics",
147-
"certificate_file": "/app/cert.pem",
148-
"client_key_file": "/app/cert.pem",
149-
"client_certificate_file": "/app/cert.pem",
147+
"certificate_file": "testdata/ca.crt",
148+
"client_key_file": "testdata/client.key",
149+
"client_certificate_file": "testdata/client.crt",
150150
"headers": [
151151
{
152152
"name": "api-key",
@@ -183,9 +183,9 @@
183183
"exporter": {
184184
"otlp_grpc": {
185185
"endpoint": "http://localhost:4317",
186-
"certificate_file": "/app/cert.pem",
187-
"client_key_file": "/app/cert.pem",
188-
"client_certificate_file": "/app/cert.pem",
186+
"certificate_file": "testdata/ca.crt",
187+
"client_key_file": "testdata/client.key",
188+
"client_certificate_file": "testdata/client.crt",
189189
"headers": [
190190
{
191191
"name": "api-key",
@@ -329,9 +329,9 @@
329329
"exporter": {
330330
"otlp_http": {
331331
"endpoint": "http://localhost:4318/v1/traces",
332-
"certificate_file": "/app/cert.pem",
333-
"client_key_file": "/app/cert.pem",
334-
"client_certificate_file": "/app/cert.pem",
332+
"certificate_file": "testdata/ca.crt",
333+
"client_key_file": "testdata/client.key",
334+
"client_certificate_file": "testdata/client.crt",
335335
"headers": [
336336
{
337337
"name": "api-key",
@@ -351,9 +351,9 @@
351351
"exporter": {
352352
"otlp_grpc": {
353353
"endpoint": "http://localhost:4317",
354-
"certificate_file": "/app/cert.pem",
355-
"client_key_file": "/app/cert.pem",
356-
"client_certificate_file": "/app/cert.pem",
354+
"certificate_file": "testdata/ca.crt",
355+
"client_key_file": "testdata/client.key",
356+
"client_certificate_file": "testdata/client.crt",
357357
"headers": [
358358
{
359359
"name": "api-key",

otelconf/testdata/v1.0.0.yaml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ logger_provider:
5454
# Configure certificate used to verify a server's TLS credentials.
5555
# Absolute path to certificate file in PEM format.
5656
# If omitted or null, system default certificate verification is used for secure connections.
57-
certificate_file: /app/cert.pem
57+
certificate_file: testdata/ca.crt
5858
# Configure mTLS private client key.
5959
# Absolute path to client key file in PEM format. If set, .client_certificate must also be set.
6060
# If omitted or null, mTLS is not used.
61-
client_key_file: /app/cert.pem
61+
client_key_file: testdata/client.key
6262
# Configure mTLS client certificate.
6363
# Absolute path to client certificate file in PEM format. If set, .client_key must also be set.
6464
# If omitted or null, mTLS is not used.
65-
client_certificate_file: /app/cert.pem
65+
client_certificate_file: testdata/client.crt
6666
# Configure headers. Entries have higher priority than entries from .headers_list.
6767
# If an entry's .value is null, the entry is ignored.
6868
headers:
@@ -96,15 +96,15 @@ logger_provider:
9696
# Configure certificate used to verify a server's TLS credentials.
9797
# Absolute path to certificate file in PEM format.
9898
# If omitted or null, system default certificate verification is used for secure connections.
99-
certificate_file: /app/cert.pem
99+
certificate_file: testdata/ca.crt
100100
# Configure mTLS private client key.
101101
# Absolute path to client key file in PEM format. If set, .client_certificate must also be set.
102102
# If omitted or null, mTLS is not used.
103-
client_key_file: /app/cert.pem
103+
client_key_file: testdata/client.key
104104
# Configure mTLS client certificate.
105105
# Absolute path to client certificate file in PEM format. If set, .client_key must also be set.
106106
# If omitted or null, mTLS is not used.
107-
client_certificate_file: /app/cert.pem
107+
client_certificate_file: testdata/client.crt
108108
# Configure headers. Entries have higher priority than entries from .headers_list.
109109
# If an entry's .value is null, the entry is ignored.
110110
headers:
@@ -279,15 +279,15 @@ meter_provider:
279279
# Configure certificate used to verify a server's TLS credentials.
280280
# Absolute path to certificate file in PEM format.
281281
# If omitted or null, system default certificate verification is used for secure connections.
282-
certificate_file: /app/cert.pem
282+
certificate_file: testdata/ca.crt
283283
# Configure mTLS private client key.
284284
# Absolute path to client key file in PEM format. If set, .client_certificate must also be set.
285285
# If omitted or null, mTLS is not used.
286-
client_key_file: /app/cert.pem
286+
client_key_file: testdata/client.key
287287
# Configure mTLS client certificate.
288288
# Absolute path to client certificate file in PEM format. If set, .client_key must also be set.
289289
# If omitted or null, mTLS is not used.
290-
client_certificate_file: /app/cert.pem
290+
client_certificate_file: testdata/client.crt
291291
# Configure headers. Entries have higher priority than entries from .headers_list.
292292
# If an entry's .value is null, the entry is ignored.
293293
headers:
@@ -360,15 +360,15 @@ meter_provider:
360360
# Configure certificate used to verify a server's TLS credentials.
361361
# Absolute path to certificate file in PEM format.
362362
# If omitted or null, system default certificate verification is used for secure connections.
363-
certificate_file: /app/cert.pem
363+
certificate_file: testdata/ca.crt
364364
# Configure mTLS private client key.
365365
# Absolute path to client key file in PEM format. If set, .client_certificate must also be set.
366366
# If omitted or null, mTLS is not used.
367-
client_key_file: /app/cert.pem
367+
client_key_file: testdata/client.key
368368
# Configure mTLS client certificate.
369369
# Absolute path to client certificate file in PEM format. If set, .client_key must also be set.
370370
# If omitted or null, mTLS is not used.
371-
client_certificate_file: /app/cert.pem
371+
client_certificate_file: testdata/client.crt
372372
# Configure headers. Entries have higher priority than entries from .headers_list.
373373
# If an entry's .value is null, the entry is ignored.
374374
headers:
@@ -591,15 +591,15 @@ tracer_provider:
591591
# Configure certificate used to verify a server's TLS credentials.
592592
# Absolute path to certificate file in PEM format.
593593
# If omitted or null, system default certificate verification is used for secure connections.
594-
certificate_file: /app/cert.pem
594+
certificate_file: testdata/ca.crt
595595
# Configure mTLS private client key.
596596
# Absolute path to client key file in PEM format. If set, .client_certificate must also be set.
597597
# If omitted or null, mTLS is not used.
598-
client_key_file: /app/cert.pem
598+
client_key_file: testdata/client.key
599599
# Configure mTLS client certificate.
600600
# Absolute path to client certificate file in PEM format. If set, .client_key must also be set.
601601
# If omitted or null, mTLS is not used.
602-
client_certificate_file: /app/cert.pem
602+
client_certificate_file: testdata/client.crt
603603
# Configure headers. Entries have higher priority than entries from .headers_list.
604604
# If an entry's .value is null, the entry is ignored.
605605
headers:
@@ -633,15 +633,15 @@ tracer_provider:
633633
# Configure certificate used to verify a server's TLS credentials.
634634
# Absolute path to certificate file in PEM format.
635635
# If omitted or null, system default certificate verification is used for secure connections.
636-
certificate_file: /app/cert.pem
636+
certificate_file: testdata/ca.crt
637637
# Configure mTLS private client key.
638638
# Absolute path to client key file in PEM format. If set, .client_certificate must also be set.
639639
# If omitted or null, mTLS is not used.
640-
client_key_file: /app/cert.pem
640+
client_key_file: testdata/client.key
641641
# Configure mTLS client certificate.
642642
# Absolute path to client certificate file in PEM format. If set, .client_key must also be set.
643643
# If omitted or null, mTLS is not used.
644-
client_certificate_file: /app/cert.pem
644+
client_certificate_file: testdata/client.crt
645645
# Configure headers. Entries have higher priority than entries from .headers_list.
646646
# If an entry's .value is null, the entry is ignored.
647647
headers:

0 commit comments

Comments
 (0)