Skip to content

Commit 79077b9

Browse files
committed
tests: runtime: azure blob compression coverage
Signed-off-by: Nico Berlee <[email protected]>
1 parent a475cc7 commit 79077b9

File tree

2 files changed

+279
-0
lines changed

2 files changed

+279
-0
lines changed

tests/runtime/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ if(FLB_IN_LIB)
204204
FLB_RT_TEST(FLB_OUT_LIB "core_routes.c")
205205
FLB_RT_TEST(FLB_OUT_LIB "config_map_opts.c")
206206
FLB_RT_TEST(FLB_OUT_COUNTER "out_counter.c")
207+
FLB_RT_TEST(FLB_OUT_AZURE_BLOB "out_azure_blob_compression.c")
207208
FLB_RT_TEST(FLB_OUT_AZURE_KUSTO "out_azure_kusto.c")
208209
FLB_RT_TEST(FLB_OUT_DATADOG "out_datadog.c")
209210
FLB_RT_TEST(FLB_OUT_SKYWALKING "out_skywalking.c")
Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
1+
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2+
3+
/* Fluent Bit
4+
* ==========
5+
* Copyright (C) 2015-2024 The Fluent Bit Authors
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
#include <string.h>
21+
22+
#include <fluent-bit/flb_info.h>
23+
#include <fluent-bit/flb_mem.h>
24+
#include <fluent-bit/flb_sds.h>
25+
#include <fluent-bit/flb_config.h>
26+
#include <fluent-bit/flb_upstream.h>
27+
#include <fluent-bit/flb_http_client.h>
28+
#include <fluent-bit/flb_compression.h>
29+
30+
#include "flb_tests_runtime.h"
31+
32+
#include "../../plugins/out_azure_blob/azure_blob.h"
33+
#include "../../plugins/out_azure_blob/azure_blob_blockblob.h"
34+
#include "../../plugins/out_azure_blob/azure_blob_http.h"
35+
36+
struct azure_blob_fixture {
37+
struct flb_config *config;
38+
struct flb_upstream *upstream;
39+
struct flb_connection *connection;
40+
};
41+
42+
static int azure_blob_fixture_init(struct azure_blob_fixture *fixture)
43+
{
44+
memset(fixture, 0, sizeof(*fixture));
45+
46+
fixture->config = flb_config_init();
47+
if (!TEST_CHECK(fixture->config != NULL)) {
48+
TEST_MSG("flb_config_init failed");
49+
return -1;
50+
}
51+
52+
fixture->upstream = flb_upstream_create(fixture->config, "127.0.0.1",
53+
80, FLB_IO_TCP, NULL);
54+
if (!TEST_CHECK(fixture->upstream != NULL)) {
55+
TEST_MSG("flb_upstream_create failed");
56+
flb_config_exit(fixture->config);
57+
fixture->config = NULL;
58+
return -1;
59+
}
60+
61+
fixture->connection = flb_calloc(1, sizeof(struct flb_connection));
62+
if (!TEST_CHECK(fixture->connection != NULL)) {
63+
flb_errno();
64+
TEST_MSG("flb_calloc(flb_connection) failed");
65+
flb_upstream_destroy(fixture->upstream);
66+
fixture->upstream = NULL;
67+
flb_config_exit(fixture->config);
68+
fixture->config = NULL;
69+
return -1;
70+
}
71+
72+
fixture->connection->upstream = fixture->upstream;
73+
return 0;
74+
}
75+
76+
static void azure_blob_fixture_destroy(struct azure_blob_fixture *fixture)
77+
{
78+
if (fixture->connection != NULL) {
79+
flb_free(fixture->connection);
80+
}
81+
82+
if (fixture->upstream != NULL) {
83+
flb_upstream_destroy(fixture->upstream);
84+
}
85+
86+
if (fixture->config != NULL) {
87+
flb_config_exit(fixture->config);
88+
}
89+
}
90+
91+
static void azure_blob_ctx_init(struct flb_azure_blob *ctx)
92+
{
93+
memset(ctx, 0, sizeof(*ctx));
94+
ctx->base_uri = flb_sds_create("/");
95+
if (!TEST_CHECK(ctx->base_uri != NULL)) {
96+
TEST_MSG("flb_sds_create failed for base_uri");
97+
return;
98+
}
99+
ctx->container_name = flb_sds_create("container");
100+
if (!TEST_CHECK(ctx->container_name != NULL)) {
101+
TEST_MSG("flb_sds_create failed for container_name");
102+
flb_sds_destroy(ctx->base_uri);
103+
ctx->base_uri = NULL;
104+
return;
105+
}
106+
ctx->btype = AZURE_BLOB_BLOCKBLOB;
107+
ctx->atype = AZURE_BLOB_AUTH_KEY;
108+
}
109+
110+
static void azure_blob_ctx_destroy(struct flb_azure_blob *ctx)
111+
{
112+
if (ctx->base_uri != NULL) {
113+
flb_sds_destroy(ctx->base_uri);
114+
}
115+
116+
if (ctx->container_name != NULL) {
117+
flb_sds_destroy(ctx->container_name);
118+
}
119+
}
120+
121+
static void test_block_blob_extension_zstd()
122+
{
123+
struct flb_azure_blob ctx;
124+
flb_sds_t uri;
125+
126+
azure_blob_ctx_init(&ctx);
127+
ctx.compress_blob = FLB_TRUE;
128+
ctx.compression = FLB_COMPRESSION_ALGORITHM_ZSTD;
129+
130+
uri = azb_block_blob_uri(&ctx, "file", "block", 123, "rand");
131+
TEST_CHECK(uri != NULL);
132+
TEST_CHECK(strstr(uri, ".zst?blockid=") != NULL);
133+
134+
flb_sds_destroy(uri);
135+
azure_blob_ctx_destroy(&ctx);
136+
}
137+
138+
static void test_block_blob_extension_gzip_default()
139+
{
140+
struct flb_azure_blob ctx;
141+
flb_sds_t uri;
142+
143+
azure_blob_ctx_init(&ctx);
144+
ctx.compress_blob = FLB_TRUE;
145+
ctx.compression = FLB_COMPRESSION_ALGORITHM_NONE;
146+
147+
/* When no explicit algorithm is configured, gzip remains the
148+
* fallback to preserve legacy behavior. */
149+
150+
uri = azb_block_blob_uri(&ctx, "file", "block", 123, "rand");
151+
TEST_CHECK(uri != NULL);
152+
TEST_CHECK(strstr(uri, ".gz?blockid=") != NULL);
153+
154+
flb_sds_destroy(uri);
155+
azure_blob_ctx_destroy(&ctx);
156+
}
157+
158+
static void test_block_blob_extension_disabled()
159+
{
160+
struct flb_azure_blob ctx;
161+
flb_sds_t uri;
162+
163+
azure_blob_ctx_init(&ctx);
164+
ctx.compress_blob = FLB_FALSE;
165+
ctx.compression = FLB_COMPRESSION_ALGORITHM_ZSTD;
166+
167+
uri = azb_block_blob_uri(&ctx, "file", "block", 123, "rand");
168+
TEST_CHECK(uri != NULL);
169+
TEST_CHECK(strstr(uri, ".gz?blockid=") == NULL);
170+
TEST_CHECK(strstr(uri, ".zst?blockid=") == NULL);
171+
172+
flb_sds_destroy(uri);
173+
azure_blob_ctx_destroy(&ctx);
174+
}
175+
176+
static void test_http_headers_zstd_encoding()
177+
{
178+
struct azure_blob_fixture fixture;
179+
struct flb_http_client *client;
180+
struct flb_azure_blob ctx;
181+
struct flb_output_instance ins;
182+
flb_sds_t header;
183+
int ret;
184+
185+
ret = azure_blob_fixture_init(&fixture);
186+
if (!TEST_CHECK(ret == 0)) {
187+
return;
188+
}
189+
190+
client = flb_http_client(fixture.connection, FLB_HTTP_PUT, "/resource",
191+
NULL, 0, "localhost", 80, NULL, 0);
192+
TEST_CHECK(client != NULL);
193+
if (client == NULL) {
194+
azure_blob_fixture_destroy(&fixture);
195+
return;
196+
}
197+
198+
memset(&ins, 0, sizeof(ins));
199+
azure_blob_ctx_init(&ctx);
200+
ctx.ins = &ins;
201+
ctx.atype = AZURE_BLOB_AUTH_SAS;
202+
203+
ret = azb_http_client_setup(&ctx, client, 1, FLB_FALSE,
204+
AZURE_BLOB_CT_JSON,
205+
AZURE_BLOB_CE_ZSTD);
206+
TEST_CHECK(ret == 0);
207+
208+
header = flb_http_get_header(client, "Content-Encoding", 16);
209+
TEST_CHECK(header != NULL);
210+
if (header != NULL) {
211+
TEST_CHECK(strcmp(header, "zstd") == 0);
212+
flb_sds_destroy(header);
213+
}
214+
215+
header = flb_http_get_header(client, "Content-Type", 12);
216+
TEST_CHECK(header != NULL);
217+
if (header != NULL) {
218+
TEST_CHECK(strcmp(header, "application/json") == 0);
219+
flb_sds_destroy(header);
220+
}
221+
222+
flb_http_client_destroy(client);
223+
azure_blob_ctx_destroy(&ctx);
224+
azure_blob_fixture_destroy(&fixture);
225+
}
226+
227+
static void test_http_headers_zstd_content_type()
228+
{
229+
struct azure_blob_fixture fixture;
230+
struct flb_http_client *client;
231+
struct flb_azure_blob ctx;
232+
struct flb_output_instance ins;
233+
flb_sds_t header;
234+
int ret;
235+
236+
ret = azure_blob_fixture_init(&fixture);
237+
if (!TEST_CHECK(ret == 0)) {
238+
return;
239+
}
240+
241+
client = flb_http_client(fixture.connection, FLB_HTTP_PUT, "/resource",
242+
NULL, 0, "localhost", 80, NULL, 0);
243+
TEST_CHECK(client != NULL);
244+
if (client == NULL) {
245+
azure_blob_fixture_destroy(&fixture);
246+
return;
247+
}
248+
249+
memset(&ins, 0, sizeof(ins));
250+
azure_blob_ctx_init(&ctx);
251+
ctx.ins = &ins;
252+
ctx.atype = AZURE_BLOB_AUTH_SAS;
253+
254+
ret = azb_http_client_setup(&ctx, client, 1, FLB_FALSE,
255+
AZURE_BLOB_CT_ZSTD,
256+
AZURE_BLOB_CE_NONE);
257+
TEST_CHECK(ret == 0);
258+
259+
header = flb_http_get_header(client, "Content-Type", 12);
260+
TEST_CHECK(header != NULL);
261+
if (header != NULL) {
262+
TEST_CHECK(strcmp(header, "application/zstd") == 0);
263+
flb_sds_destroy(header);
264+
}
265+
266+
flb_http_client_destroy(client);
267+
azure_blob_ctx_destroy(&ctx);
268+
azure_blob_fixture_destroy(&fixture);
269+
}
270+
271+
TEST_LIST = {
272+
{"block_blob_extension_zstd", test_block_blob_extension_zstd},
273+
{"block_blob_extension_gzip_default", test_block_blob_extension_gzip_default},
274+
{"block_blob_extension_disabled", test_block_blob_extension_disabled},
275+
{"http_headers_zstd_encoding", test_http_headers_zstd_encoding},
276+
{"http_headers_zstd_content_type", test_http_headers_zstd_content_type},
277+
{ 0 }
278+
};

0 commit comments

Comments
 (0)