Skip to content

Commit dd0e6b2

Browse files
committed
test: add testcases, support test report generation
1 parent b2b8aac commit dd0e6b2

File tree

20 files changed

+442
-141
lines changed

20 files changed

+442
-141
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,5 @@ cython_debug/
142142

143143
# Testing playground
144144
playground/
145-
test/repo/
145+
test/repo/
146+
test/report/

.pre-commit-config.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
repos:
3+
- repo: https://github.com/psf/black
4+
rev: 22.10.0
5+
hooks:
6+
- id: black
7+
args: [
8+
--line-length=121,
9+
]
10+
exclude: ^(venv/|docs/)
11+
types: ['python']
12+
- repo: https://github.com/PyCQA/flake8
13+
rev: 5.0.4
14+
hooks:
15+
- id: flake8
16+
args: [
17+
--max-line-length=121,
18+
--ignore=E402
19+
]
20+
exclude: ^(venv/|docs/)
21+
types: ['python']

GitHacker/__init__.py

Lines changed: 104 additions & 66 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,44 @@ githacker --brute --url-file websites.txt --output-folder result
8383
- [x] Try common tags and branches when Index disabled
8484
- [x] [find packed refs](https://github.com/WangYihang/GitHacker/issues/1#issuecomment-487135667)
8585

86+
## Test
87+
88+
### Setup Development Environment
89+
90+
```
91+
# Install docker and docker-compose
92+
apt install docker-desktop
93+
apt install docker-compose
94+
95+
# Download GitHacker
96+
git clone https://github.com/WangYihang/GitHacker
97+
cd GitHacker
98+
python -m venv venv
99+
source venv/bin/activate
100+
pip install -r requirements.txt
101+
```
102+
103+
### Run tests
104+
105+
```
106+
# Generate testing repo
107+
python utils/gen.py
108+
109+
# Run testcases
110+
sudo su
111+
source venv/bin/activate
112+
pip install -r requirements.txt
113+
python utils/test.py
114+
exit
115+
116+
# Diff results
117+
python utils/diff.py
118+
```
119+
120+
## Check report
121+
122+
See `test/report/YYYY-MM-DD/index.html`
123+
86124
## Videos
87125
### asciinema
88126

requirements.txt

Lines changed: 100 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,100 @@
1-
requests
2-
coloredlogs
3-
GitPython
4-
beautifulsoup4
5-
semver
6-
twine
1+
beautifulsoup4==4.11.1
2+
bleach==5.0.1
3+
certifi==2022.12.7
4+
cffi==1.15.1
5+
cfgv==3.3.1
6+
charset-normalizer==2.1.1
7+
coloredlogs==15.0.1
8+
commonmark==0.9.1
9+
cryptography==38.0.4
10+
distlib==0.3.6
11+
docutils==0.19
12+
filelock==3.8.2
13+
gitdb==4.0.10
14+
GitPython==3.1.29
15+
humanfriendly==10.0
16+
identify==2.5.9
17+
idna==3.4
18+
importlib-metadata==5.1.0
19+
jaraco.classes==3.2.3
20+
jeepney==0.8.0
21+
Jinja2==3.1.2
22+
keyring==23.11.0
23+
MarkupSafe==2.1.1
24+
more-itertools==9.0.0
25+
nodeenv==1.7.0
26+
pkginfo==1.9.2
27+
platformdirs==2.6.0
28+
pre-commit==2.20.0
29+
pycparser==2.21
30+
Pygments==2.13.0
31+
pytz==2022.6
32+
PyYAML==6.0
33+
readme-renderer==37.3
34+
requests==2.28.1
35+
requests-toolbelt==0.10.1
36+
rfc3986==2.0.0
37+
rich==12.6.0
38+
SecretStorage==3.3.3
39+
semver==2.13.0
40+
six==1.16.0
41+
smmap==5.0.0
42+
soupsieve==2.3.2.post1
43+
toml==0.10.2
44+
twine==4.0.2
45+
urllib3==1.26.13
46+
verboselogs==1.7
47+
virtualenv==20.17.1
48+
webencodings==0.5.1
49+
zipp==3.11.0
50+
zope.interface==5.5.2
51+
beautifulsoup4==4.11.1
52+
bleach==5.0.1
53+
certifi==2022.12.7
54+
cffi==1.15.1
55+
cfgv==3.3.1
56+
charset-normalizer==2.1.1
57+
coloredlogs==15.0.1
58+
commonmark==0.9.1
59+
cryptography==38.0.4
60+
distlib==0.3.6
61+
docutils==0.19
62+
filelock==3.8.2
63+
gitdb==4.0.10
64+
GitPython==3.1.29
65+
humanfriendly==10.0
66+
identify==2.5.9
67+
idna==3.4
68+
importlib-metadata==5.1.0
69+
jaraco.classes==3.2.3
70+
jeepney==0.8.0
71+
Jinja2==3.1.2
72+
keyring==23.11.0
73+
MarkupSafe==2.1.1
74+
more-itertools==9.0.0
75+
nodeenv==1.7.0
76+
pkginfo==1.9.2
77+
platformdirs==2.6.0
78+
pre-commit==2.20.0
79+
pycparser==2.21
80+
Pygments==2.13.0
81+
pytz==2022.6
82+
PyYAML==6.0
83+
readme-renderer==37.3
84+
requests==2.28.1
85+
requests-toolbelt==0.10.1
86+
rfc3986==2.0.0
87+
rich==12.6.0
88+
SecretStorage==3.3.3
89+
semver==2.13.0
90+
six==1.16.0
91+
smmap==5.0.0
92+
soupsieve==2.3.2.post1
93+
toml==0.10.2
94+
twine==4.0.2
95+
urllib3==1.26.13
96+
verboselogs==1.7
97+
virtualenv==20.17.1
98+
webencodings==0.5.1
99+
zipp==3.11.0
100+
zope.interface==5.5.2

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
setuptools.setup(
88
name="GitHacker",
99
version=GitHacker.__version__,
10-
author="Wang Yihang",
10+
author="Yihang Wang",
1111
author_email="[email protected]",
12-
description="This is a multiple threads tool to download the `.git` folder and rebuild git repository locally.",
12+
description="A multiple threads tool to download the `.git` folder and rebuild git repository locally.",
1313
long_description=long_description,
1414
long_description_content_type="text/markdown",
1515
url="https://github.com/WangYihang/GitHacker",

templates/index.html

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<h2>Reports</h2>
2+
<style>
3+
table, th, td {
4+
text-align: center;
5+
border: 1px solid black;
6+
}
7+
</style>
8+
<table>
9+
<thead>
10+
<th>testcase</th>
11+
<th>correct files</th>
12+
<th>total files</th>
13+
<th>correct ratio</th>
14+
<th>different files</th>
15+
<th>abscent files</th>
16+
</thead>
17+
<tbody>
18+
{% for name, result in results.items() %}
19+
<tr>
20+
<td><a href="{{ name }}.html">{{ name }}</a></td>
21+
<td>{{ result["correct"] }}</td>
22+
<td>{{ result["total"] }}</td>
23+
<td>{{ "%.4f"|format(result["ratio"]) }}%</td>
24+
<td>{{ result["difference"]|length }}</td>
25+
<td>{{ result["abscence"]|length }}</td>
26+
</tr>
27+
{% endfor %}
28+
</tbody>
29+
</table>

templates/result.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<title>{{ tool }}-v{{ version }}</title>
2+
<h2>Summary</h2>
3+
<div>
4+
Date: {{ time }}<br>
5+
Total files: {{ total }}, Correct files: {{ correct }}, Correct Ratio: {{ "%.4f"|format(ratio) }}%<br>
6+
Different files: {{ difference|length }}, Absent files: {{ abscence|length }}<br>
7+
</div>
8+
9+
<h2>Different file</h2>
10+
11+
<table>
12+
{% for filename in difference %}
13+
<TR><TD>{{ filename }}</TD></TR>
14+
{% endfor %}
15+
</table>
16+
17+
<h2>Absent file</h2>
18+
19+
<table>
20+
{% for filename in abscence %}
21+
<TR><TD>{{ filename }}</TD></TR>
22+
{% endfor %}
23+
</table>

test/docker/apache-index-disabled/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ services:
77
ports:
88
- 80:80
99
volumes:
10-
- ./www:/usr/local/apache2/htdocs
10+
- ../../repo:/usr/local/apache2/htdocs
1111
- ./httpd.conf:/usr/local/apache2/conf/httpd.conf

test/docker/apache-index-disabled/www

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/docker/apache-index-enabled/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ services:
77
ports:
88
- 80:80
99
volumes:
10-
- ./www:/usr/local/apache2/htdocs
10+
- ../../repo:/usr/local/apache2/htdocs

test/docker/apache-index-enabled/www

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/docker/nginx-index-disabled/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ services:
77
ports:
88
- 80:80
99
volumes:
10-
- ./www:/usr/share/nginx/html
10+
- ../../repo:/usr/share/nginx/html

test/docker/nginx-index-disabled/www

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/docker/nginx-index-enabled/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ services:
77
ports:
88
- 80:80
99
volumes:
10-
- ./www:/usr/share/nginx/html
10+
- ../../repo:/usr/share/nginx/html
1111
- ./nginx.conf:/etc/nginx/nginx.conf:ro

test/docker/nginx-index-enabled/www

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/docker/php-lfi/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ services:
77
ports:
88
- 80:80
99
volumes:
10-
- ./www:/var/www/html
10+
- ../../repo:/var/www/html

test/docker/php-lfi/www

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)