Skip to content

Commit 3afec2b

Browse files
committed
tests: add initial health file tests
1 parent c57fb0c commit 3afec2b

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

axiom/tests/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ TESTS := \
146146
test_hash \
147147
test_hashmap \
148148
test_header \
149+
test_health \
149150
test_json \
150151
test_labels \
151152
test_log_event \

axiom/tests/test_health.c

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2020 New Relic Corporation. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include "nr_axiom.h"
7+
8+
#include <stdint.h>
9+
#include <stdlib.h>
10+
#include <time.h>
11+
#include <unistd.h>
12+
13+
#include "util_health.h"
14+
#include "util_memory.h"
15+
16+
#include "tlib_main.h"
17+
#include "util_syscalls.h"
18+
19+
static void test_health(void) {
20+
nr_status_t rv;
21+
char* location = NULL;
22+
23+
nrh_set_start_time();
24+
25+
nr_unlink("health-bc21b5891f5e44fc9272caef924611a8.yml");
26+
27+
location = nrh_get_health_location("/should/not/exist");
28+
tlib_pass_if_true("initialization to bad path fails", NULL == location,
29+
"location=%s", NULL == location ? "NULL" : location);
30+
nr_free(location);
31+
32+
nrh_set_health_filename();
33+
34+
location = nrh_get_health_location("file://./");
35+
tlib_pass_if_true("initialization to good path succeeds", NULL != location,
36+
"location=%s", NULL == location ? "NULL" : location);
37+
38+
rv = nrh_set_last_error(NRH_MISSING_LICENSE);
39+
40+
rv = nrh_write_health(location);
41+
tlib_pass_if_true("health file write succeeds", NR_SUCCESS == rv, "rv=%d",
42+
(int)rv);
43+
44+
tlib_pass_if_exists("./health-bc21b5891f5e44fc9272caef924611a8.yml");
45+
46+
rv = nrh_set_last_error(NRH_MISSING_APPNAME);
47+
48+
rv = nrh_write_health(location);
49+
tlib_pass_if_true("write_health succeeds", NR_SUCCESS == rv, "rv=%d",
50+
(int)rv);
51+
52+
rv = nrh_set_last_error(NRH_HEALTHY);
53+
54+
rv = nrh_write_health(location);
55+
tlib_pass_if_true("write_health succeeds", NR_SUCCESS == rv, "rv=%d",
56+
(int)rv);
57+
58+
nr_free(location);
59+
}
60+
61+
tlib_parallel_info_t parallel_info
62+
= {.suggested_nthreads = -1, .state_size = 0};
63+
64+
void test_main(void* p NRUNUSED) {
65+
test_health();
66+
}

0 commit comments

Comments
 (0)