-
Notifications
You must be signed in to change notification settings - Fork 1
/
_tests.sh
executable file
·197 lines (171 loc) · 5.2 KB
/
_tests.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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#!/bin/bash
clear
set -euo pipefail
[[ ${debug:-} == true ]] && set -x
PATH=$(pwd):$PATH
which git
git --version
cd .test
root_folder=$(pwd)
echo "Cleaning $(pwd)"
git clean -xffdq .
local_tester_repo=.local
remote_tester_repo=.remote
clone_tester_repo=.clone
function testcase_header() {
[[ ${verbose:-} == true ]] || return 0
echo
echo "--------------------------------------------------------------------------------"
echo " Testcase begin: ${test} : $testcase_synopsis"
echo "--------------------------------------------------------------------------------"
}
function eval_testcase() {
# expect to be in repo to test against
if [[ -s "${root_folder}/${test}/git-test.log" ]]; then
echo "INFO: ${root_folder}/${test}/git-test.log is not empty - use it"
else
git log --graph --all --oneline --decorate --format="%d %s" > "${root_folder}/${test}/git-test.log"
fi
cd "${root_folder}/${test}"
if diff -w git-test.log git-reference.log ; then
if [[ ${verbose:-} == true ]] ; then
cat git-test.log
echo "INFO: Test $test : OK"
echo
else
echo "INFO: Test $test : OK : ${testcase_synopsis}"
fi
else
echo "ERROR: Test $test failed: ${testcase_synopsis}"
exit 1
fi
cd "${root_folder}"
}
function generate_base_repo() {
rm -rf "$local_tester_repo/" "$remote_tester_repo/" "$clone_tester_repo/"
git init --bare -b ${default_branch:-main} $remote_tester_repo
git -C $remote_tester_repo symbolic-ref HEAD refs/heads/${default_branch:-main}
git artifact init --url=$(pwd)/$remote_tester_repo --path $local_tester_repo -b ${default_branch:-main}
cd $local_tester_repo
touch test.txt
git artifact add-n-push -t v1.0
sleep 1
touch test2.txt
git artifact add-n-tag -t v2.0
git artifact push -t v2.0
git artifact reset
sleep 1
cd ..
}
echo "Running testcases; You can find run details for each test in <test>/run.log"
echo
export test="1"
testcase_synopsis="base-repo default-branch; clone"
testcase_header
{
cd $test
generate_base_repo
cd $local_tester_repo
} > ${test}/run.log 2>&1
eval_testcase
export test="1.1"
testcase_synopsis="base-repo master-branch; clone"
testcase_header
{
cd $test
export default_branch=master
generate_base_repo
cd $local_tester_repo
unset default_branch
} > ${test}/run.log 2>&1
eval_testcase
export test="2"
testcase_synopsis="base-repo ; clone; fetch-co : the repo has two tags and the latest is checked out"
testcase_header
{
cd $test
generate_base_repo
git artifact clone --url=$(pwd)/$remote_tester_repo --path $clone_tester_repo
cd $clone_tester_repo
git artifact fetch-co -t v1.0
git artifact fetch-co -t v2.0
} > ${test}/run.log 2>&1
eval_testcase
export test="3"
testcase_synopsis="base-repo ; clone - gives a repo without any artifacts"
testcase_header
{
cd $test
generate_base_repo "latest"
git artifact clone --url=$(pwd)/$remote_tester_repo --path $clone_tester_repo
cd $clone_tester_repo
} > ${test}/run.log 2>&1
eval_testcase
test="4"
testcase_synopsis="base-repo ; clone; add-n-push with branch"
testcase_header
{
cd $test
generate_base_repo
git artifact clone --url=$(pwd)/$remote_tester_repo -b latest --path $clone_tester_repo
cd $clone_tester_repo
touch test$test.txt
git artifact add-n-push -t v${test}.0 -b latest
touch test$test.1.txt
git artifact add-n-push -t v${test}.1 -b latest
} > ${test}/run.log 2>&1
eval_testcase
test="5"
testcase_synopsis="base-repo ; clone; fetch-co-latest pattern"
testcase_header
{
cd $test
generate_base_repo
sleep 1
git artifact clone --url=$(pwd)/$remote_tester_repo --path $clone_tester_repo
cd $clone_tester_repo
git artifact fetch-co-latest -r 'v*.*'
git artifact reset
cd ../$local_tester_repo
touch test$test.txt
git artifact add-n-push -t v${test}.0
sleep 1
cd ../$clone_tester_repo
git artifact fetch-co-latest -r 'v*.*'
git artifact reset
sleep 1
cd ../$local_tester_repo
touch test$test.1.txt
git artifact add-n-push -t v${test}.1
sleep 1
cd ../$clone_tester_repo
git artifact fetch-co-latest --regex 'v*.*'
} > ${test}/run.log 2>&1 || { echo "ERROR_CODE: $?"; pwd && cat ../run.log; }
eval_testcase
test="5.1"
testcase_synopsis="base-repo ; clone; find-latest pattern"
testcase_header
{
cd $test
generate_base_repo
sleep 1
git artifact clone --url=$(pwd)/$remote_tester_repo --path $clone_tester_repo
cd $clone_tester_repo
git ls-remote origin --tags
git artifact find-latest -r 'v*.*' > ${root_folder}/${test}/git-test.log
} > ${root_folder}/${test}/run.log 2>&1 || { pwd && cat ${root_folder}/${test}/run.log; }
eval_testcase
test="6"
testcase_synopsis="base-repo ; clone; fetch-tags"
testcase_header
{
cd $test
generate_base_repo
git artifact clone --url=$(pwd)/$remote_tester_repo -b latest --path $clone_tester_repo
cd $clone_tester_repo
git artifact fetch-co --tag v1.0
sha1=$(git rev-parse HEAD)
git tag -d v1.0
git artifact fetch-tags --sha1 "$sha1"
} > ${test}/run.log 2>&1 || cat ../${test}/run.log
eval_testcase