Skip to content

Commit ca91ac5

Browse files
committed
✨ Integration tests sources updates to be optional
1 parent 3a623e4 commit ca91ac5

File tree

3 files changed

+60
-39
lines changed

3 files changed

+60
-39
lines changed

tests/0014-http-posts.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,4 @@
1-
#include <curl/curl.h>
2-
#include <fcntl.h>
3-
#include <signal.h>
4-
#include <stdio.h>
5-
#include <stdlib.h>
6-
#include <string.h>
7-
#include <unistd.h>
8-
#include <zlib.h>
9-
10-
#include <setjmp.h>
11-
#include <stdarg.h>
12-
#include <stddef.h>
13-
14-
#include <cmocka.h>
1+
#include "integration_tests.h"
152

163
#define VALID_MESSAGE "{\"message\": \"Hello world\"}"
174
#define VALID_TOPIC "/rb_flow"
@@ -23,6 +10,8 @@
2310

2411
// It should returns 200 when UUID, TOPIC and MESSAGE are valids
2512
static void Test_Valid_POST() {
13+
SKIP_IF_NOT_INTEGRATION;
14+
2615
CURL *curl;
2716
CURLcode res;
2817
long http_code = 0;
@@ -53,6 +42,8 @@ static void Test_Valid_POST() {
5342

5443
// It should returns 401 when UUID is not valid
5544
static void Test_Invalid_UUID() {
45+
SKIP_IF_NOT_INTEGRATION;
46+
5647
CURL *curl;
5748
CURLcode res;
5849
long http_code = 0;
@@ -83,6 +74,8 @@ static void Test_Invalid_UUID() {
8374

8475
// It should returns 403 when Topic is not valid
8576
static void Test_Invalid_Topic() {
77+
SKIP_IF_NOT_INTEGRATION;
78+
8679
CURL *curl;
8780
CURLcode res;
8881
long http_code = 0;
@@ -112,6 +105,8 @@ static void Test_Invalid_Topic() {
112105
}
113106

114107
static void Test_No_Topic() {
108+
SKIP_IF_NOT_INTEGRATION;
109+
115110
CURL *curl;
116111
CURLcode res;
117112
long http_code = 0;
@@ -140,6 +135,8 @@ static void Test_No_Topic() {
140135
}
141136

142137
static void Test_Empty_Body() {
138+
SKIP_IF_NOT_INTEGRATION;
139+
143140
CURL *curl;
144141
CURLcode res;
145142
long http_code = 0;
@@ -170,6 +167,8 @@ static void Test_Empty_Body() {
170167

171168
// It should returns 403 when Topic is not valid
172169
static void Test_Invalid_URL() {
170+
SKIP_IF_NOT_INTEGRATION;
171+
173172
CURL *curl;
174173
CURLcode res;
175174
long http_code = 0;
@@ -200,6 +199,8 @@ static void Test_Invalid_URL() {
200199

201200
// It should returns 403 when Topic is not valid
202201
static void Test_Deflate() {
202+
SKIP_IF_NOT_INTEGRATION;
203+
203204
z_stream defstream;
204205
defstream.zalloc = Z_NULL;
205206
defstream.zfree = Z_NULL;
@@ -251,6 +252,7 @@ static void Test_Deflate() {
251252
}
252253

253254
int main() {
255+
#ifdef TESTS_KAFKA_HOST
254256
curl_global_init(CURL_GLOBAL_ALL);
255257

256258
printf("Initializing n2kafka\n");
@@ -265,28 +267,29 @@ int main() {
265267
(void)(dup(0) + 1);
266268
(void)(dup(0) + 1);
267269

268-
execlp("./n2kafka", "n2kafka", "configs_example/n2kafka_config_rbhttp.json",
270+
execlp("./n2kafka", "n2kafka", "configs_example/n2kafka_tests_http.json",
269271
(char *)0);
270272
printf("Error executing n2kafka\n");
271273
exit(1);
272-
273274
} else if (pID < 0) {
274275
exit(1);
275276
}
277+
#endif
276278

277279
// Wait for n2kafka to initialize
278280
sleep(1);
279-
280281
const struct CMUnitTest tests[] = {
281282
cmocka_unit_test(Test_Valid_POST), cmocka_unit_test(Test_Invalid_UUID),
282283
cmocka_unit_test(Test_Invalid_Topic), cmocka_unit_test(Test_No_Topic),
283284
cmocka_unit_test(Test_Invalid_URL), cmocka_unit_test(Test_Deflate),
284285
cmocka_unit_test(Test_Empty_Body)};
285286
const int res = cmocka_run_group_tests(tests, NULL, NULL);
286287

288+
#ifdef TESTS_KAFKA_HOST
287289
curl_global_cleanup();
288290
kill(pID, SIGINT);
289291
sleep(1);
292+
#endif
290293

291294
return res;
292295
}

tests/0015-kafka-producer.c

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,8 @@
1-
#include "assertion_handler.c"
1+
#include "integration_tests.h"
22

3-
#include <curl/curl.h>
4-
#include <fcntl.h>
5-
#include <signal.h>
6-
#include <stdio.h>
7-
#include <stdlib.h>
8-
#include <string.h>
9-
#include <unistd.h>
3+
#include "assertion_handler.c"
104

115
#include <arpa/inet.h>
12-
13-
#include <setjmp.h>
14-
#include <stdarg.h>
15-
#include <stddef.h>
16-
17-
#include <cmocka.h>
18-
196
#include <librdkafka/rdkafka.h>
207

218
#define SENT_MESSAGE_HTTP_1 "{\"message\": \"Hello world HTTP\"}"
@@ -30,12 +17,13 @@
3017
#define TCP_PORT 2056
3118
#define TCP_MESSAGES_DELAY 5
3219

20+
#ifdef TESTS_KAFKA_HOST
3321
static rd_kafka_t *init_kafka() {
3422
rd_kafka_t *rk;
3523

3624
// Kafka
3725
char errstr[512];
38-
char *brokers = "kafka:9092";
26+
char *brokers = TESTS_KAFKA_HOST;
3927
rd_kafka_topic_partition_list_t *topics;
4028
rd_kafka_resp_err_t err;
4129
rd_kafka_conf_t *conf = rd_kafka_conf_new();
@@ -93,12 +81,15 @@ static rd_kafka_t *init_kafka() {
9381

9482
return rk;
9583
}
84+
#endif
9685

9786
/**
9887
* Send a message using curl and expect to receive the enriched message via
9988
* kafka
10089
*/
10190
static void test_send_message_http() {
91+
SKIP_IF_NOT_INTEGRATION;
92+
10293
CURL *curl;
10394
CURLcode res;
10495
long http_code = 0;
@@ -112,12 +103,12 @@ static void test_send_message_http() {
112103

113104
if (pID == 0) {
114105
// Close stdin, stdout, stderr
115-
// close(0);
116-
// close(1);
117-
// close(2);
118-
// open("/dev/null", O_RDWR);
119-
// (void)(dup(0) + 1);
120-
// (void)(dup(0) + 1);
106+
close(0);
107+
close(1);
108+
close(2);
109+
open("/dev/null", O_RDWR);
110+
(void)(dup(0) + 1);
111+
(void)(dup(0) + 1);
121112

122113
execlp("./n2kafka", "n2kafka", "configs_example/n2kafka_tests_http.json",
123114
(char *)0);
@@ -219,6 +210,8 @@ static void test_send_message_http() {
219210
* via kafka
220211
*/
221212
static void test_send_message_tcp() {
213+
SKIP_IF_NOT_INTEGRATION;
214+
222215
int sock;
223216
struct sockaddr_in server;
224217
struct assertion_handler_s *assertion_handler = NULL;

tests/integration_tests.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "../config.h"
2+
3+
#include <curl/curl.h>
4+
#include <fcntl.h>
5+
#include <signal.h>
6+
#include <stdio.h>
7+
#include <stdlib.h>
8+
#include <string.h>
9+
#include <unistd.h>
10+
#include <zlib.h>
11+
12+
#include <setjmp.h>
13+
#include <stdarg.h>
14+
#include <stddef.h>
15+
16+
#include <cmocka.h>
17+
#ifdef TESTS_KAFKA_HOST
18+
#define SKIP_IF_NOT_INTEGRATION
19+
#else
20+
#define SKIP_IF_NOT_INTEGRATION \
21+
do { \
22+
skip(); \
23+
return; \
24+
} while (0)
25+
#endif

0 commit comments

Comments
 (0)