pacemaker  2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
pcmk_hostname_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2021 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU General Public License version 2
7  * or later (GPLv2+) WITHOUT ANY WARRANTY.
8  */
9 
10 #include <crm_internal.h>
11 
13 
14 #include "mock_private.h"
15 
16 #include <sys/utsname.h>
17 
18 static void
19 uname_succeeded_test(void **state)
20 {
21  char *retval;
22 
23  // Set uname() return value and buf parameter node name
24  pcmk__mock_uname = true;
25 
26  expect_any(__wrap_uname, buf);
27  will_return(__wrap_uname, 0);
28  will_return(__wrap_uname, "somename");
29 
30  retval = pcmk_hostname();
31  assert_non_null(retval);
32  assert_string_equal("somename", retval);
33 
34  free(retval);
35 
36  pcmk__mock_uname = false;
37 }
38 
39 static void
40 uname_failed_test(void **state)
41 {
42  // Set uname() return value and buf parameter node name
43  pcmk__mock_uname = true;
44 
45  expect_any(__wrap_uname, buf);
46  will_return(__wrap_uname, -1);
47  will_return(__wrap_uname, NULL);
48 
49  assert_null(pcmk_hostname());
50 
51  pcmk__mock_uname = false;
52 }
53 
54 PCMK__UNIT_TEST(NULL, NULL,
55  cmocka_unit_test(uname_succeeded_test),
56  cmocka_unit_test(uname_failed_test))
bool pcmk__mock_uname
Definition: mock.c:428
PCMK__UNIT_TEST(NULL, NULL, cmocka_unit_test(bad_input), cmocka_unit_test(not_found), cmocka_unit_test(find_attrB), cmocka_unit_test(find_attrA_matching))
char * pcmk_hostname(void)
Get the local hostname.
Definition: utils.c:535
int __wrap_uname(struct utsname *buf)
Definition: mock.c:431