-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
executable file
·110 lines (99 loc) · 3.23 KB
/
test.sh
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
#!/bin/sh
## Copyright 2016-2017 Mathieu Parent <math.parent@gmail.com>
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
## You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
set -e
# =================================================================
# Helpers
# =================================================================
check_from_docker() {
cat /proc/1/cgroup | cut -d: -f3 | grep -q ^/docker
}
assert_equal() {
if [ "$1" != "$2" ]; then
echo " $3:"
echo " Actual: $1"
echo " Expected: $2"
return 1
fi
}
# =================================================================
# Tests
# =================================================================
test_only_root() {
local not_root="$(find / -xdev -not -user root -not -path "$PWD" -not -path /var/cache/apt/archives/partial -not -path /var/lib/libuuid -print -quit)"
assert_equal "$not_root" '' 'first file not owned by root'
}
test_path_exclude() {
local path_remaining="$(find /usr/share/doc/ -xdev -not -name copyright -type f -print -quit)"
assert_equal "$path_remaining" '' 'first files excluded from dpkg but found'
}
test_files() {
local files_count="$(ls -d /usr/share/man/man1 /usr/share/man/man2 /usr/share/man/man3 2>/dev/null | wc -l)"
assert_equal "$files_count" 3
}
test_tz() {
if [ "$(date +%Z)" = 'CEST' ]; then
assert_equal "$(date +%Z)" CEST TZ
else
assert_equal "$(date +%Z)" CET TZ
fi
}
test_lang() {
local output="$(ls nonexisting 2>&1 | grep -c 'Aucun fichier ou dossier de ce type')"
assert_equal "$output" '1' 'french'
}
test_packages() {
local pkg
local should_not
for pkg in $(dpkg-query -Wf '${Package}\n'); do
case $pkg in
acl|debconf-i18n)
should_not="$should_not $pkg"
;;
dmsetup|libdevmapper*|libcryptsetup*)
should_not="$should_not $pkg"
;;
init|systemd|systemd-sysv|sysvinit-core|upstart|udev)
should_not="$should_not $pkg"
;;
e2fs*)
should_not="$should_not $pkg"
;;
esac
done
assert_equal "$should_not" '' 'Packages should not be installed'
}
# =================================================================
# main
# =================================================================
check_from_docker || {
echo "ERROR: Tests should be run from a docker container"
exit 1
}
# Show package list
(set -x; dpkg-query --show)
failures=0
for t in only_root path_exclude files tz lang packages; do
echo "========================================"
echo "Test: $t: "
if "test_$t"; then
echo " OK"
else
echo " FAILED!"
failures=$((failures+1))
fi
done
if [ "$failures" != 0 ]; then
exit 1
fi