pacemaker
2.1.7-0f7f88312f
Scalable High-Availability cluster resource manager
lib
common
tests
io
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
12
#include <
crm/common/unittest_internal.h
>
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
25
result
=
pcmk__get_tmpdir
();
26
assert_string_equal(
result
,
"/tmp"
);
27
28
expect_string(
__wrap_getenv
,
name
,
"TMPDIR"
);
29
will_return(
__wrap_getenv
,
""
);
// getenv("TMPDIR") return value
30
result
=
pcmk__get_tmpdir
();
31
assert_string_equal(
result
,
"/tmp"
);
32
33
expect_string(
__wrap_getenv
,
name
,
"TMPDIR"
);
34
will_return(
__wrap_getenv
,
"subpath"
);
// getenv("TMPDIR") return value
35
result
=
pcmk__get_tmpdir
();
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
50
result
=
pcmk__get_tmpdir
();
51
assert_string_equal(
result
,
"/var/tmp"
);
52
53
expect_string(
__wrap_getenv
,
name
,
"TMPDIR"
);
54
will_return(
__wrap_getenv
,
"/"
);
// getenv("TMPDIR") return value
55
result
=
pcmk__get_tmpdir
();
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
60
result
=
pcmk__get_tmpdir
();
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))
mock_private.h
name
const char * name
Definition:
cib.c:26
PCMK__UNIT_TEST
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))
crm_internal.h
pcmk__get_tmpdir
const char * pcmk__get_tmpdir(void)
Definition:
io.c:547
result
pcmk__action_result_t result
Definition:
pcmk_fence.c:35
unittest_internal.h
__wrap_getenv
char * __wrap_getenv(const char *name)
Definition:
mock.c:96
pcmk__mock_getenv
bool pcmk__mock_getenv
Definition:
mock.c:93
Generated on Tue Dec 19 2023 17:32:56 for pacemaker by
1.8.14