Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
xs-test
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patrick Chen
xs-test
Commits
5d7ea9c4
Commit
5d7ea9c4
authored
Aug 28, 2018
by
Patrick Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add params in expectation
parent
af54a7e8
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
9 deletions
+21
-9
Makefile
Makefile
+1
-1
greeting.json
example/greeting.json
+1
-0
Expectation.h
include/test/Expectation.h
+3
-2
Expectation.cc
src/test/Expectation.cc
+11
-1
Tester.cc
src/test/Tester.cc
+5
-5
No files found.
Makefile
View file @
5d7ea9c4
...
...
@@ -32,7 +32,7 @@ XSTEST_OBJS=$(subst $(REPO_DIR),$(BUILD_DIR),$(XSTEST_SRCS:.cc=.o))
GREETING_SRCS
=
$(REPO_DIR)
/example/greeting.cc
GREETING_OBJS
=
$
(
subst
$(REPO_DIR)
,
$(BUILD_DIR)
,
$
(
GREETING_SRCS:.cc
=
.o
))
all
:
$(BUILD_DIR)/xs-test
all
:
$(BUILD_DIR)/xs-test
example
$(BUILD_DIR)/xs-test
:
$(XSTEST_OBJS)
$(CXX)
-o
$@
$(XSTEST_OBJS)
$(LD_FLAGS)
...
...
example/greeting.json
View file @
5d7ea9c4
...
...
@@ -11,6 +11,7 @@
"script"
:
[
{
"command"
:
"GetMessage"
,
"params"
:
{},
"expect"
:
{
"response"
:
"Hello, Master!"
,
"runs"
:
[
"GetName"
],
...
...
include/test/Expectation.h
View file @
5d7ea9c4
...
...
@@ -9,7 +9,7 @@
namespace
xs
{
namespace
test
{
class
Expectation
class
Expectation
final
{
public
:
Expectation
()
=
delete
;
...
...
@@ -25,7 +25,8 @@ namespace xs { namespace test
public
:
std
::
string
name_
;
nlohmann
::
json
value_
;
nlohmann
::
json
params_
;
nlohmann
::
json
response_
;
std
::
unordered_set
<
std
::
string
>
runs_
;
std
::
unordered_set
<
std
::
string
>
posts_
;
};
...
...
src/test/Expectation.cc
View file @
5d7ea9c4
...
...
@@ -9,8 +9,10 @@ namespace xs { namespace test
Expectation
::
Expectation
(
const
nlohmann
::
json
&
object
)
:
name_
(
object
[
"command"
].
get
<
std
::
string
>
())
{
params_
=
object
[
"params"
];
const
auto
&
expect
=
object
[
"expect"
];
valu
e_
=
expect
[
"response"
];
respons
e_
=
expect
[
"response"
];
if
(
expect
.
count
(
"runs"
))
{
for
(
const
auto
&
element
:
expect
[
"runs"
])
{
...
...
@@ -41,6 +43,14 @@ namespace xs { namespace test
return
false
;
}
if
(
!
object
.
count
(
"params"
))
{
return
false
;
}
if
(
!
(
object
[
"params"
].
is_string
()
||
object
[
"params"
].
is_object
()))
{
return
false
;
}
if
(
!
(
object
.
count
(
"expect"
)
&&
object
[
"expect"
].
is_object
()))
{
return
false
;
}
...
...
src/test/Tester.cc
View file @
5d7ea9c4
...
...
@@ -62,11 +62,11 @@ void Tester::resetCounters() noexcept
Tester
::
Report
Tester
::
createReport
(
const
std
::
string
&
response
,
const
Expectation
&
expectation
)
noexcept
{
Report
report
;
if
(
expectation
.
valu
e_
.
is_string
())
{
report
.
pass
=
(
response
==
expectation
.
valu
e_
.
get
<
std
::
string
>
());
if
(
expectation
.
respons
e_
.
is_string
())
{
report
.
pass
=
(
response
==
expectation
.
respons
e_
.
get
<
std
::
string
>
());
}
else
{
try
{
report
.
pass
=
(
nlohmann
::
json
::
parse
(
response
)
==
expectation
.
valu
e_
);
report
.
pass
=
(
nlohmann
::
json
::
parse
(
response
)
==
expectation
.
respons
e_
);
}
catch
(...)
{
}
...
...
@@ -114,7 +114,7 @@ void Tester::run() noexcept
for
(
const
auto
&
expectation
:
config_
.
getExpectations
())
{
resetCounters
();
const
auto
response
=
server_
.
runCmd
(
expectation
.
name_
,
""
);
const
auto
response
=
server_
.
runCmd
(
expectation
.
name_
,
expectation
.
params_
.
dump
()
);
// wait 100ms for upcoming events
using
namespace
std
::
chrono_literals
;
...
...
@@ -130,7 +130,7 @@ void Tester::run() noexcept
std
::
cout
<<
"[FAILED] run command: "
<<
expectation
.
name_
<<
std
::
endl
;
if
(
report
.
missedCommands
.
empty
()
&&
report
.
missedEvents
.
empty
())
{
std
::
cout
<<
boost
::
format
(
R"([REASON] unexpected response: "%1%"(real) vs %2%(expect))"
)
%
response
%
detail
::
toString
(
expectation
.
valu
e_
)
%
response
%
detail
::
toString
(
expectation
.
respons
e_
)
<<
std
::
endl
;
}
else
if
(
!
report
.
missedCommands
.
empty
())
{
std
::
cout
<<
boost
::
format
(
"[REASON] missed commands: [%1%]"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment