@@ -25,60 +25,81 @@ static void test_health(void) {
25
25
26
26
nrh_set_start_time ();
27
27
28
+ // ensure clean environment
28
29
nr_unlink ("health-bc21b5891f5e44fc9272caef924611a8.yml" );
29
30
nr_unlink ("health-ffffffffffffffffffffffffffffffff.yml" );
30
31
32
+ // invalid location
31
33
location = nrh_get_health_location ("/should/not/exist" );
32
34
tlib_pass_if_true ("initialization to bad path fails" , NULL == location ,
33
35
"location=%s" , NULL == location ? "NULL" : location );
34
36
nr_free (location );
37
+
38
+ // invalid uuid
35
39
rv = nrh_set_uuid ("bc21b5891f5e44fc9272caef924611a" );
36
40
tlib_pass_if_true ("set uuid with invalid length uuid fails" , NR_FAILURE == rv ,
37
41
"rv=%d" , (int )rv );
38
42
43
+ // valid location
39
44
location = nrh_get_health_location ("file://./" );
40
45
tlib_pass_if_true ("initialization to good path succeeds" , NULL != location ,
41
46
"location=%s" , NULL == location ? "NULL" : location );
47
+
48
+ // valid status
42
49
rv = nrh_set_last_error (NRH_INVALID_LICENSE );
50
+
51
+ // write default uuid + valid location + valid status
43
52
rv = nrh_write_health (location );
44
53
tlib_pass_if_true ("health file write succeeds" , NR_SUCCESS == rv , "rv=%d" ,
45
54
(int )rv );
46
55
tlib_pass_if_exists ("./health-bc21b5891f5e44fc9272caef924611a8.yml" );
47
56
57
+ // update to a new uuid
48
58
rv = nrh_set_uuid ("ffffffffffffffffffffffffffffffff" );
49
59
tlib_pass_if_true ("set uuid succeeds" , NR_SUCCESS == rv , "rv=%d" , (int )rv );
60
+
61
+ // update to a new valid status
50
62
rv = nrh_set_last_error (NRH_MISSING_LICENSE );
63
+
64
+ // write new file (uuid) + same location + new status
51
65
rv = nrh_write_health (location );
52
66
tlib_pass_if_true ("health file write succeeds" , NR_SUCCESS == rv , "rv=%d" ,
53
67
(int )rv );
54
68
tlib_pass_if_exists ("./health-ffffffffffffffffffffffffffffffff.yml" );
55
69
70
+ // update to new valid status
56
71
rv = nrh_set_last_error (NRH_MISSING_APPNAME );
57
- rv = nrh_write_health (location );
58
- tlib_pass_if_true ("write_health succeeds" , NR_SUCCESS == rv , "rv=%d" ,
59
- (int )rv );
60
72
61
- rv = nrh_set_last_error ( NRH_HEALTHY );
73
+ // update existing file with new status
62
74
rv = nrh_write_health (location );
63
75
tlib_pass_if_true ("write_health succeeds" , NR_SUCCESS == rv , "rv=%d" ,
64
76
(int )rv );
65
77
78
+ // update new random uuid
66
79
rv = nrh_set_uuid (NULL );
67
80
tlib_pass_if_true ("set random uuid succeeds" , NR_SUCCESS == rv , "rv=%d" ,
68
81
(int )rv );
82
+
83
+ // verify new random uuid != previous
69
84
rand_uuid = nrh_get_uuid ();
70
85
tlib_pass_if_not_null ("get uuid succeeds" , rand_uuid );
71
86
tlib_pass_if_true (
72
87
"manual uuid successfully replaced by random uuid" ,
73
88
0 != nr_strcmp ("ffffffffffffffffffffffffffffffff" , rand_uuid ), "rand=%s" ,
74
89
rand_uuid );
90
+
91
+ // update to valid status
75
92
rv = nrh_set_last_error (NRH_CONNECTION_FAILED );
93
+
94
+ // write new file (random uuid) + existing location + new status
76
95
rv = nrh_write_health (location );
77
96
97
+ // test get_health_filename functionality
78
98
rand_healthfile = nrh_get_health_filename ();
79
99
tlib_pass_if_not_null ("get health filename succeeds" , rand_healthfile );
80
100
tlib_pass_if_exists (rand_healthfile );
81
101
102
+ // clean up
82
103
nr_unlink ("health-bc21b5891f5e44fc9272caef924611a8.yml" );
83
104
nr_unlink ("health-ffffffffffffffffffffffffffffffff.yml" );
84
105
nr_unlink (rand_healthfile );
0 commit comments