-
Notifications
You must be signed in to change notification settings - Fork 71
/
test_almalinux-deploy.bats
executable file
·176 lines (153 loc) · 4.82 KB
/
test_almalinux-deploy.bats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/env bats
source almalinux-deploy.sh -t
setup() {
if [[ ${BATS_TEST_DESCRIPTION} =~ 'get_os_release_var' ]] \
|| [[ ${BATS_TEST_DESCRIPTION} =~ 'get_os_version' ]]; then
MOCKED_OS_RELEASE=$(mktemp -p ${BATS_TMPDIR} osrel_XXXX )
fi
}
teardown() {
if [[ ${BATS_TEST_NAME} =~ 'get_os_release_var' ]] \
|| [[ ${BATS_TEST_DESCRIPTION} =~ 'get_os_version' ]]; then
rm -f ${MOCKED_OS_RELEASE}
fi
}
@test 'get_system_arch returns x86_64 architecture' {
function uname() { echo 'x86_64'; }
export -f uname
run get_system_arch
[[ ${status} -eq 0 ]]
[[ ${output} == 'x86_64' ]]
}
@test 'get_system_arch returns aarch64 architecture' {
function uname() { echo 'aarch64'; }
export -f uname
run get_system_arch
[[ ${status} -eq 0 ]]
[[ ${output} == 'aarch64' ]]
}
@test 'get_system_arch returns ppc64le architecture' {
function uname() { echo 'ppc64le'; }
export -f uname
run get_system_arch
[[ ${status} -eq 0 ]]
[[ ${output} == 'ppc64le' ]]
}
@test 'get_system_arch returns s390x architecture' {
function uname() { echo 's390x'; }
export -f uname
run get_system_arch
[[ ${status} -eq 0 ]]
[[ ${output} == 's390x' ]]
}
@test 'assert_run_as_root passes for root' {
function id() { echo 0; }
export -f id
run assert_run_as_root
[[ ${status} -eq 0 ]]
}
@test 'assert_run_as_root fails for user' {
function id() { echo 1000; }
export -f id
run assert_run_as_root
[[ ${status} -ne 0 ]]
}
@test 'assert_secureboot_disabled fails on enabled Secure Boot' {
function mokutil() {
case "$1" in
'--sb-state' ) echo 'SecureBoot enabled' ;;
esac
}
export -f mokutil
run assert_secureboot_disabled
[[ ${status} -ne 0 ]]
}
@test 'assert_secureboot_disabled passes on disabled Secure Boot' {
function mokutil() {
case "$1" in
'--sb-state' ) echo 'SecureBoot disabled' ;;
esac
}
export -f mokutil
run assert_secureboot_disabled
[[ ${status} -eq 0 ]]
}
@test 'get_os_release_var extracts VERSION_ID' {
echo 'VERSION_ID="8"' >> ${MOCKED_OS_RELEASE}
export OS_RELEASE_PATH="${MOCKED_OS_RELEASE}"
run get_os_release_var 'VERSION_ID'
[[ ${status} -eq 0 ]]
[[ ${output} -eq 8 ]]
}
@test 'get_os_release_var extracts ID' {
echo 'ID="centos"' >> ${MOCKED_OS_RELEASE}
export OS_RELEASE_PATH="${MOCKED_OS_RELEASE}"
run get_os_release_var 'ID'
[[ ${status} -eq 0 ]]
[[ ${output} == 'centos' ]]
}
@test 'get_os_release_var fails on missing variable' {
export OS_RELEASE_PATH="${MOCKED_OS_RELEASE}"
run get_os_release_var 'VERSION_ID'
[[ ${status} -ne 0 ]]
[[ ${output} =~ 'Error' ]]
}
@test 'get_release_file_url returns default URL' {
run get_release_file_url '8' 'x86_64'
[[ ${status} -eq 0 ]]
[[ ${output} == 'https://repo.almalinux.org/almalinux/almalinux-release-latest-8.x86_64.rpm' ]]
}
@test 'get_release_file_url returns ALMA_RELEASE_URL environment variable' {
export ALMA_RELEASE_URL='https://example.com/almalinux-release-latest-8.aarch64.rpm'
run get_release_file_url '8' 'aarch64'
[[ ${status} -eq 0 ]]
[[ ${output} == "${ALMA_RELEASE_URL}" ]]
}
@test 'assert_supported_system passes on CentOS-8 x86_64' {
for os_version in 8 9; do
run assert_supported_system 'centos' "${os_version}" 'x86_64'
[[ ${status} -eq 0 ]]
done
}
@test 'assert_supported_system fails on unsupported architectures' {
for arch in 'i686' 'armv7l'; do
run assert_supported_system 'centos' '8' "${arch}"
[[ ${status} -ne 0 ]]
[[ ${output} =~ 'ERROR' ]]
done
}
@test 'assert_supported_system fails on non-EL8' {
for os_version in 6 7; do
run assert_supported_system 'centos' "${os_version}" 'x86_64'
[[ ${status} -ne 0 ]]
[[ ${output} =~ 'ERROR' ]]
done
}
@test 'assert_supported_system fails on unsupported distributions' {
for os_id in 'fedora'; do
run assert_supported_system "${os_id}" '8' 'x86_64'
[[ ${status} -ne 0 ]]
[[ ${output} =~ 'ERROR' ]]
done
}
@test 'get_os_version detects CentOS 8.2 Core' {
echo 'CentOS Linux release 8.2.2004 (Core)' >> ${MOCKED_OS_RELEASE}
export REDHAT_RELEASE_PATH="${MOCKED_OS_RELEASE}"
run get_os_version 'centos'
[[ ${status} -eq 0 ]]
[[ ${output} == '8.2' ]]
}
@test 'get_os_version detects CentOS 8.3' {
echo 'CentOS Linux release 8.3.2011' >> ${MOCKED_OS_RELEASE}
export REDHAT_RELEASE_PATH="${MOCKED_OS_RELEASE}"
run get_os_version 'centos'
[[ ${status} -eq 0 ]]
[[ ${output} == '8.3' ]]
}
@test 'get_os_version reads OS_RELEASE' {
echo 'VERSION_ID="8"' >> ${MOCKED_OS_RELEASE}
export OS_RELEASE_PATH="${MOCKED_OS_RELEASE}"
run get_os_version 'weirdos'
[[ ${status} -eq 0 ]]
[[ ${output} == '8' ]]
}