pacemaker  2.1.9-49aab99839
Scalable High-Availability cluster resource manager
pcmk__get_tmpdir_test.c
Go to the documentation of this file.
1 /*
2  * Copyright 2021-2022 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 static void
17 getenv_returns_invalid(void **state)
18 {
19  const char *result;
20 
21  pcmk__mock_getenv = true;
22 
23  expect_string(__wrap_getenv, name, "TMPDIR");
24  will_return(__wrap_getenv, NULL); // getenv("TMPDIR") return value
26  assert_string_equal(result, "/tmp");
27 
28  expect_string(__wrap_getenv, name, "TMPDIR");
29  will_return(__wrap_getenv, ""); // getenv("TMPDIR") return value
31  assert_string_equal(result, "/tmp");
32 
33  expect_string(__wrap_getenv, name, "TMPDIR");
34  will_return(__wrap_getenv, "subpath"); // getenv("TMPDIR") return value
36  assert_string_equal(result, "/tmp");
37 
38  pcmk__mock_getenv = false;
39 }
40 
41 static void
42 getenv_returns_valid(void **state)
43 {
44  const char *result;
45 
46  pcmk__mock_getenv = true;
47 
48  expect_string(__wrap_getenv, name, "TMPDIR");
49  will_return(__wrap_getenv, "/var/tmp"); // getenv("TMPDIR") return value
51  assert_string_equal(result, "/var/tmp");
52 
53  expect_string(__wrap_getenv, name, "TMPDIR");
54  will_return(__wrap_getenv, "/"); // getenv("TMPDIR") return value
56  assert_string_equal(result, "/");
57 
58  expect_string(__wrap_getenv, name, "TMPDIR");
59  will_return(__wrap_getenv, "/tmp/abcd.1234"); // getenv("TMPDIR") return value
61  assert_string_equal(result, "/tmp/abcd.1234");
62 
63  pcmk__mock_getenv = false;
64 }
65 
66 PCMK__UNIT_TEST(NULL, NULL,
67  cmocka_unit_test(getenv_returns_invalid),
68  cmocka_unit_test(getenv_returns_valid))
const char * name
Definition: cib.c:26
#define PCMK__UNIT_TEST(group_setup, group_teardown,...)
const char * pcmk__get_tmpdir(void)
Definition: io.c:547
pcmk__action_result_t result
Definition: pcmk_fence.c:35
char * __wrap_getenv(const char *name)
Definition: mock.c:118
bool pcmk__mock_getenv
Definition: mock.c:115