// SPDX-License-Identifier: GPL-3.0-or-later
#include "libnetdata/libnetdata.h"
#include "libnetdata/required_dummies.h"
#include "database/rrd.h"
#include "web/server/web_client.h"
#include <setjmp.h>
#include <cmocka.h>
#include <stdbool.h>
RRDHOST *sql_create_host_by_uuid(char *hostname)
{
(void) hostname;
return NULL;
}
RRDHOST *__wrap_sql_create_host_by_uuid(char *hostname)
{
(void) hostname;
return NULL;
}
void repr(char *result, int result_size, char const *buf, int size)
{
int n;
char *end = result + result_size - 1;
unsigned char const *ubuf = (unsigned char const *)buf;
while (size && result_size > 0) {
if (*ubuf <= 0x20 || *ubuf >= 0x80) {
n = snprintf(result, result_size, "\\%02X", *ubuf);
} else {
*result = *ubuf;
n = 1;
}
result += n;
result_size -= n;
ubuf++;
size--;
}
if (result_size > 0)
*(result++) = 0;
else
*end = 0;
}
// ---------------------------------- Mocking accesses from web_client ------------------------------------------------
ssize_t send(int sockfd, const void *buf, size_t len, int flags)
{
info("Mocking send: %zu bytes\n", len);
(void)sockfd;
(void)buf;
(void)flags;
return len;
}
RRDHOST *__wrap_rrdhost_find_by_hostname(const char *hostname, uint32_t hash)
{
(void)hostname;
(void)hash;
return NULL;
}
/* Note: we've got some intricate code inside the global statistics module, might be useful to pull it inside the
test set instead of mocking it. */
void __wrap_finished_web_request_statistics(
uint64_t dt, uint64_t bytes_received, uint64_t bytes_sent, uint64_t content_size, uint64_t compressed_content_size)
{
(void)dt;
(void)bytes_received;
(void)bytes_sent;
(void)content_size;
(void)compressed_content_size;
}
char *__wrap_config_get(struct config *root, const char *section, const char *name, const char *default_value)
{
if (!strcmp(section, CONFIG_SECTION_WEB) && !strcmp(name, "web files owner"))
return "netdata";
(void)root;
(void)default_value;
return "UNKNOWN FIX ME";
}
int __wrap_web_client_api_request_v1(RRDHOST *host, struct web_client *w, char *url)
{
char url_repr[160];
repr(url_repr, sizeof(url_repr), url, strlen(url));
printf("web_client_api_request_v1(url=\"%s\")\n", url_repr);
check_expected_ptr(host);
check_expected_ptr(w);
check_expected_ptr(url_repr);
return HTTP_RESP_OK;
}
int __wrap_mysendfile(struct web_client *w, char *filename)
{
(void)w;
printf("mysendfile(filename=\"%s\"\n", filename);
check_expected_ptr(filename);
return HTTP_RESP_OK;
}
int __wrap_rrdpush_receiver_thread_spawn(RRDHOST *host, struct web_client *w, char *url)
{
(void)host;
(void)w;
(void)url;
return 0;
}
RRDHOST *__wrap_rrdhost_find_by_guid(const char *guid, uint32_t hash)
{
(void)guid;
(void)hash;
printf("FIXME: rrdset_find_guid\n");
return NULL;
}
RRDSET *__wrap_rrdset_find_byname(RRDHOST *host, const char *name)
{
(void)host;
(void)name;
printf("FIXME: rrdset_find_byname\n");
return NULL;
}
RRDSET *__wrap_rrdset_find(RRDHOST *host, const char *id)
{
(void)host;
(void)id;
printf("FIXME: rrdset_find\n");
return NULL;
}
// -------------------------------- Mocking the log - dump straight through --------------------------------------------
void __wrap_debug_int(const char *file, const char *function, const unsigned long line, const char *fmt, ...)
{
(void)file;
(void)function;
(void)line;
va_list args;
va_start(args, fmt);
printf(" DEBUG: ");
printf(fmt, args);
printf("\n");
va_end(args);
}
void __wrap_info_int(const char *file, const char *function, const unsigned long line, const char *fmt, ...)
{
(void)file;
(void)function;
(