Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/bin/hostname/tests/hostname_test.sh
39492 views
1
#-
2
# SPDX-License-Identifier: BSD-2-Clause
3
#
4
# Copyright (c) 2024 Lin Lee <[email protected]>
5
#
6
# Redistribution and use in source and binary forms, with or without
7
# modification, are permitted provided that the following conditions
8
# are met:
9
# 1. Redistributions of source code must retain the above copyright
10
# notice, this list of conditions and the following disclaimer.
11
# 2. Redistributions in binary form must reproduce the above copyright
12
# notice, this list of conditions and the following disclaimer in the
13
# documentation and/or other materials provided with the distribution.
14
#
15
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25
# SUCH DAMAGE.
26
#
27
28
#
29
# These tests need to run in a multibyte locale with non-localized
30
# error messages.
31
#
32
export LC_CTYPE=C.UTF-8
33
export LC_MESSAGES=C
34
35
test_jail_name="test-hostname-jail"
36
37
test_jail_conf='%%test_jail_name%% {
38
host.hostname = "test-hostname.example.org";
39
path = "/";
40
persist;
41
}'
42
43
init()
44
{
45
echo "${test_jail_conf}" | \
46
sed -e "s/%%test_jail_name%%/${test_jail_name}/" > "./jail.conf"
47
jail -f "./jail.conf" -c ${test_jail_name}
48
}
49
50
recycle()
51
{
52
jail -f "./jail.conf" -r ${test_jail_name}
53
rm "./jail.conf"
54
}
55
56
atf_test_case basic cleanup
57
basic_head()
58
{
59
atf_set require.user root
60
atf_set "descr" "basic test for getting hostname"
61
atf_set execenv jail
62
}
63
basic_body()
64
{
65
init
66
67
result=$(jexec ${test_jail_name} "hostname")
68
atf_check_equal "test-hostname.example.org" "${result}"
69
70
result=$(jexec ${test_jail_name} "hostname" -s)
71
atf_check_equal "test-hostname" "${result}"
72
73
result=$(jexec ${test_jail_name} "hostname" -d)
74
atf_check_equal "example.org" "${result}"
75
76
jexec ${test_jail_name} "hostname" "test-bsd2"
77
result=$(jexec ${test_jail_name} "hostname")
78
atf_check_equal "test-bsd2" "${result}"
79
}
80
basic_cleanup()
81
{
82
recycle
83
}
84
85
atf_init_test_cases()
86
{
87
atf_add_test_case basic
88
}
89
90