Skip to content

Commit fc04594

Browse files
committed
tests: harden encoding payload dumps and fix otlp destroy helper
Signed-off-by: Eduardo Silva <eduardo@chronosphere.io>
1 parent f75a037 commit fc04594

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

tests/encoding.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -540,10 +540,10 @@ curl -v 'http://localhost:9090/receive' -H 'Content-Type: application/x-protobuf
540540
--data-binary '@prometheus_remote_write_payload.snp'\n\n");
541541

542542
sample_file = fopen("prometheus_remote_write_payload.bin", "wb+");
543-
544-
fwrite(payload, 1, cfl_sds_len(payload), sample_file);
545-
546-
fclose(sample_file);
543+
if (sample_file != NULL) {
544+
fwrite(payload, 1, cfl_sds_len(payload), sample_file);
545+
fclose(sample_file);
546+
}
547547

548548
cmt_encode_prometheus_remote_write_destroy(payload);
549549

@@ -604,12 +604,12 @@ curl -v 'http://localhost:9090/v1/metrics' -H 'Content-Type: application/x-proto
604604
--data-binary '@opentelemetry_payload.bin'\n\n");
605605

606606
sample_file = fopen("opentelemetry_payload.bin", "wb+");
607+
if (sample_file != NULL) {
608+
fwrite(payload, 1, cfl_sds_len(payload), sample_file);
609+
fclose(sample_file);
610+
}
607611

608-
fwrite(payload, 1, cfl_sds_len(payload), sample_file);
609-
610-
fclose(sample_file);
611-
612-
cmt_encode_prometheus_remote_write_destroy(payload);
612+
cmt_encode_opentelemetry_destroy(payload);
613613

614614
cmt_destroy(cmt);
615615
}
@@ -644,10 +644,10 @@ we need to encode it as JSON and to send AWS Cloudwatch with out_cloudwatch plug
644644
fluent-bit\n\n");
645645

646646
sample_file = fopen("cloudwatch_emf_payload.bin", "wb+");
647-
648-
fwrite(mp_buf, 1, mp_size, sample_file);
649-
650-
fclose(sample_file);
647+
if (sample_file != NULL) {
648+
fwrite(mp_buf, 1, mp_size, sample_file);
649+
fclose(sample_file);
650+
}
651651

652652
cmt_encode_cloudwatch_emf_destroy(mp_buf);
653653

0 commit comments

Comments
 (0)