Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
buildItBreakItFixIt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AGSI
Project
buildItBreakItFixIt
Commits
fa64d1f4
Commit
fa64d1f4
authored
4 years ago
by
Oliver Wiese
Browse files
Options
Downloads
Patches
Plain Diff
add test frame work
parent
f9e9f8be
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
testing/Dockerfile
+23
-0
23 additions, 0 deletions
testing/Dockerfile
testing/bibifiTests.py
+138
-0
138 additions, 0 deletions
testing/bibifiTests.py
testing/tests/core/createaccount.json
+1
-0
1 addition, 0 deletions
testing/tests/core/createaccount.json
with
162 additions
and
0 deletions
testing/Dockerfile
0 → 100755
+
23
−
0
View file @
fa64d1f4
FROM
ubuntu:18.04
ARG
ZIP
# Install dependencies
RUN
apt-get update
&&
apt-get
install
-y
python3.7
RUN
apt-get update
&&
apt-get
install
-y
unzip
WORKDIR
/usr/test
COPY
bibifiTests.py .
COPY
tests .
COPY
$ZIP .
RUN
sh
-c
'unzip -q "Archive.zip"'
RUN
mv
Archive/
*
./
RUN
sh
-c
'make'
RUN
chmod
a+wrx atm
RUN
chmod
a+wrx bank
RUN
chmod
a+wrx bibifiTests.py
RUN
chmod
a+wr core
CMD
["python3", "bibifiTests.py"]
\ No newline at end of file
This diff is collapsed.
Click to expand it.
testing/bibifiTests.py
0 → 100755
+
138
−
0
View file @
fa64d1f4
import
subprocess
import
os
import
time
import
json
from
shutil
import
copyfile
"""
Created by Oliver Wiese
Copyright © 2020 fu-berlin.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
PORT
=
3000
IP
=
'
127.0.0.1
'
def
createBank
(
authFile
=
'
bank.auth
'
,
port
=
PORT
):
cmd
=
[
'
./bank
'
,
'
-s
'
,
authFile
,
'
-p
'
,
str
(
port
)]
result
=
subprocess
.
Popen
(
cmd
)
return
result
,
authFile
def
cleanup
(
files
,
accounts
,
server
):
server
.
terminate
()
for
acc
in
accounts
:
name
=
acc
+
'
.card
'
if
not
name
in
files
:
files
.
append
(
name
)
for
f
in
files
:
if
os
.
path
.
isfile
(
f
):
os
.
remove
(
f
)
def
readTestCase
(
file
):
if
os
.
path
.
isfile
(
file
):
fp
=
open
(
file
,
'
r
'
)
data
=
json
.
load
(
fp
)
return
data
return
[]
def
testInput
(
input
,
output
):
args
=
[
w
.
replace
(
'
%PORT%
'
,
str
(
PORT
))
for
w
in
input
]
args
=
[
w
.
replace
(
'
%IP%
'
,
IP
)
for
w
in
args
]
args
=
[
'
./atm
'
]
+
args
atm
=
subprocess
.
run
(
args
,
stdout
=
subprocess
.
PIPE
)
res
=
atm
.
stdout
.
decode
(
'
utf-8
'
)
if
len
(
res
)
>
0
:
res
=
json
.
loads
(
res
)
else
:
res
=
{}
equal
=
(
res
==
output
)
return
equal
,
res
,
output
,
args
def
runTestCase
(
file
):
trace
=
[]
data
=
readTestCase
(
file
)
error
=
False
msg
=
'
OK
'
accounts
=
[]
cards
=
[]
if
data
==
[]:
return
(
True
,
[],
"
No test case error.
"
)
bank
,
authFile
=
createBank
()
time
.
sleep
(
1
)
cards
.
append
(
authFile
)
"""
Example:
{
"
inputs
"
: [
{
"
input
"
: {
"
input
"
: [
"
-p
"
,
"
%PORT%
"
,
"
-i
"
,
"
%IP%
"
,
"
-a
"
,
"
ted
"
,
"
-n
"
,
"
10.30
"
]},
"
output
"
: {
"
output
"
: {
"
initial_balance
"
: 10.3,
"
account
"
:
"
ted
"
},
"
exit
"
: 0}},
{
"
input
"
: {
"
input
"
: [
"
-p
"
,
"
%PORT%
"
,
"
-i
"
,
"
%IP%
"
,
"
-a
"
,
"
alice
"
,
"
-c
"
,
"
alice.card
"
,
"
-n
"
,
"
100.00
"
]},
"
output
"
: {
"
output
"
: {
"
initial_balance
"
: 100,
"
account
"
:
"
alice
"
},
"
exit
"
: 0}}
]}
"""
for
x
in
data
[
'
inputs
'
]:
input
=
x
[
'
input
'
]
# Store account names/cards
if
'
-a
'
in
input
[
'
input
'
]:
i
=
input
[
'
input
'
].
index
(
'
-a
'
)
accounts
.
append
(
input
[
'
input
'
][
i
+
1
])
if
'
-c
'
in
input
[
'
input
'
]:
i
=
input
[
'
input
'
].
index
(
'
-c
'
)
cards
.
append
(
input
[
'
input
'
][
i
+
1
])
output
=
x
[
'
output
'
]
equal
,
res
,
expected
,
call
=
testInput
(
input
[
'
input
'
],
output
[
'
output
'
])
trace
.
append
((
call
,
res
,
expected
))
if
not
equal
:
error
=
True
msg
=
'
Result does not match with expectation.
'
break
cleanup
(
cards
,
accounts
,
bank
)
return
error
,
trace
,
msg
def
runTestSuite
(
path
=
'
../tests/core
'
):
testedFiles
=
[]
for
(
dirpath
,
dirnames
,
filenames
)
in
os
.
walk
(
path
):
for
f
in
filenames
:
f
=
path
+
'
/
'
+
f
if
'
.json
'
in
f
:
testedFiles
.
append
(
f
)
error
,
trace
,
msg
=
runTestCase
(
f
)
if
error
:
return
(
error
,
trace
,
msg
)
return
(
False
,
[],
''
)
def
feedback
(
error
,
trace
,
msg
):
print
(
'
Result:
'
)
if
error
:
print
(
'
ERROR
'
)
print
(
msg
)
print
(
trace
)
text
=
'
Tests failed!
\n
Description:
\n
{0}
\n
Trace:
\n
{1}
'
.
format
(
msg
,
trace
)
return
text
else
:
print
(
'
No failed tests! Looks good.
'
)
return
'
No failed tests! Looks good.
'
def
clean
(
dir
):
if
os
.
path
.
isfile
(
dir
):
os
.
remove
(
dir
)
def
startTests
(
dir
,
move
=
True
):
error
,
trace
,
msg
=
runTestSuite
(
dir
+
'
/core
'
)
if
move
:
clean
(
dir
)
return
feedback
(
error
,
trace
,
msg
)
dir
=
os
.
getcwd
()
msg
=
startTests
(
dir
,
False
)
This diff is collapsed.
Click to expand it.
testing/tests/core/createaccount.json
0 → 100644
+
1
−
0
View file @
fa64d1f4
{
"inputs"
:
[{
"input"
:
{
"input"
:
[
"-p"
,
"%PORT%"
,
"-i"
,
"%IP%"
,
"-a"
,
"ted"
,
"-n"
,
"10.30"
]},
"output"
:
{
"output"
:
{
"initial_balance"
:
10.3
,
"account"
:
"ted"
},
"exit"
:
0
}}]}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment