-
Notifications
You must be signed in to change notification settings - Fork 1
/
test-etckeeper
executable file
·113 lines (96 loc) · 2.88 KB
/
test-etckeeper
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
#!/usr/bin/env bats
#
#
[ -z "$testdir" ] && exit 1
[ ! -d "$testdir" ] && exit 1
export ETCKEEPER_CONF_DIR=$PWD
export PATH=$PWD:$PATH
export VCS=git
export GIT_AUTHOR_EMAIL="nobody@example.com"
export GIT_AUTHOR_NAME="nobody"
export GIT_COMMITTER_NAME="$GIT_AUTHOR_EMAIL"
export GIT_COMMITTER_EMAIL="$GIT_AUTHOR_NAME"
metadata="$testdir/.etckeeper"
chmod_str="maybe chmod"
chown_str="maybe chown"
chgrp_str="maybe chgrp"
mkdir_str="mkdir -p"
run() {
./etckeeper $1 -d "$testdir" "$2"
}
check_root() {
# check if running in fakeroot or similar
[ $(id -u) -eq 0 ]
}
@test "test: etckeeper init" {
run init
}
@test "test: etckeeper commit" {
run commit "initial commit"
[ -f "$metadata" ]
}
@test "test: etckeeper commit empty dir" {
testdir2="testdir"
install -d $testdir/$testdir2
run commit "commit 2"
[ $(grep -E -c "^${mkdir_str} .*${testdir2}'$" $metadata) -eq 1 ]
}
@test "test: etckeeper commit not empty dir" {
local testdir2="testdir"
install /dev/null $testdir/$testdir2/file
run commit "commit 3"
[ $(grep -E -c "^${mkdir_str} .*${testdir2}'$" $metadata) -eq 0 ]
}
@test "test: etckeeper commit non-default mode" {
local testfile="file4"
local mode="0577"
install -m${mode} /dev/null $testdir/$testfile
run commit "commit 4"
[ $(grep -E -c "^${chmod_str} ${mode} .*${testfile}'$" $metadata) -eq 1 ]
}
@test "root_test: check if root" {
if ! check_root; then
skip "need to use fakeroot, the rest of the root tests will be skipped as well"
fi
}
@test "root_test: create file owned by root:root" {
check_root || skip
local testfile="file5"
local mode="0644"
local owner="root"
local group="root"
install -o $owner -g $group -m $mode /dev/null $testdir/$testfile
run commit "commit 5"
[ $(grep -E -c "^${chmod_str} ${mode} .*${testfile}'$" $metadata) -eq 1 ]
[ $(grep -E -c "^${chown_str} '${owner}' .*${testfile}'$" $metadata) -eq 0 ]
[ $(grep -E -c "^${chgrp_str} '${group}' .*${testfile}'$" $metadata) -eq 0 ]
}
@test "root_test: create file owned by bin:daemon" {
check_root || skip
local testfile="file6"
local mode="0644"
local owner="bin"
local group="daemon"
install -o $owner -g $group -m $mode /dev/null $testdir/$testfile
run commit "commit 6"
[ $(grep -E -c "^${chmod_str} ${mode} .*${testfile}'$" $metadata) -eq 1 ]
[ $(grep -E -c "^${chown_str} '${owner}' .*${testfile}'$" $metadata) -eq 1 ]
[ $(grep -E -c "^${chgrp_str} '${group}' .*${testfile}'$" $metadata) -eq 1 ]
}
@test "test: etckeeper commit file with space" {
local testfile="a b c"
local mode="0705"
install -m $mode /dev/null $testdir/"$testfile"
run commit "commit 7"
[ $(grep -E -c "^${chmod_str} ${mode} .*${testfile}'$" $metadata) -eq 1 ]
}
@test "test: etckeeper debug (git)" {
skip
git --git-dir $testdir/.git log --oneline --stat
git --git-dir $testdir/.git show --stat
false # return printouts for above commands
}
@test "test: etckeeper uninit -f" {
run uninit "-f"
[ ! -f "$metadata" ]
}