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
1cd1ef2c
Commit
1cd1ef2c
authored
Aug 27, 2018
by
Patrick Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow simple test
parent
b0be3542
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
11 deletions
+38
-11
hello-world.json
example/hello-world.json
+2
-2
Tester.h
include/test/Tester.h
+1
-1
Tester.cc
src/test/Tester.cc
+34
-7
xs-test.cc
src/xs-test.cc
+1
-1
No files found.
example/hello-world.json
View file @
1cd1ef2c
...
@@ -2,13 +2,13 @@
...
@@ -2,13 +2,13 @@
"mockData"
:
[
"mockData"
:
[
{
{
"command"
:
"GetName"
,
"command"
:
"GetName"
,
"response"
:
"
Patrick
"
"response"
:
"
Master
"
}
}
],
],
"script"
:
[
"script"
:
[
{
{
"command"
:
"GetGreetingMessage"
,
"command"
:
"GetGreetingMessage"
,
"expect"
:
"Hello,
Patrick
!"
"expect"
:
"Hello,
Master
!"
}
}
]
]
}
}
include/test/Tester.h
View file @
1cd1ef2c
...
@@ -26,7 +26,7 @@ namespace xs { namespace test
...
@@ -26,7 +26,7 @@ namespace xs { namespace test
explicit
Tester
(
const
boost
::
filesystem
::
path
&
file
);
explicit
Tester
(
const
boost
::
filesystem
::
path
&
file
);
void
wait
()
noexcept
;
void
run
()
noexcept
;
private
:
private
:
std
::
string
onCommand
(
const
std
::
string
&
name
,
const
std
::
string
&
params
)
noexcept
;
std
::
string
onCommand
(
const
std
::
string
&
name
,
const
std
::
string
&
params
)
noexcept
;
...
...
src/test/Tester.cc
View file @
1cd1ef2c
#include "test/Service.h"
#include "test/Service.h"
#include "test/Tester.h"
#include "test/Tester.h"
#include <boost/format.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/adaptors.hpp>
#include <nlohmann/json.hpp>
#include <chrono>
#include <chrono>
#include <functional>
#include <functional>
...
@@ -10,6 +12,14 @@
...
@@ -10,6 +12,14 @@
namespace
xs
{
namespace
test
{
namespace
xs
{
namespace
test
{
namespace
detail
{
std
::
string
toString
(
const
nlohmann
::
json
&
object
)
{
return
object
.
is_string
()
?
object
.
get
<
std
::
string
>
()
:
object
.
dump
();
}
}
Tester
::
Tester
(
const
boost
::
filesystem
::
path
&
file
)
Tester
::
Tester
(
const
boost
::
filesystem
::
path
&
file
)
:
config_
(
file
)
:
config_
(
file
)
,
server_
(
,
server_
(
...
@@ -49,9 +59,7 @@ std::string Tester::onCommand(const std::string& name, const std::string& params
...
@@ -49,9 +59,7 @@ std::string Tester::onCommand(const std::string& name, const std::string& params
const
auto
&
response
=
service
->
response_
;
const
auto
&
response
=
service
->
response_
;
/// TODO: keep track the status
/// TODO: keep track the status
return
detail
::
toString
(
response
);
return
response
.
is_string
()
?
response
.
get
<
std
::
string
>
()
:
response
.
dump
();
}
}
void
Tester
::
onEvent
(
const
std
::
string
&
name
,
const
std
::
string
&
params
)
noexcept
void
Tester
::
onEvent
(
const
std
::
string
&
name
,
const
std
::
string
&
params
)
noexcept
...
@@ -63,11 +71,30 @@ void Tester::onEvent(const std::string& name, const std::string& params) noexcep
...
@@ -63,11 +71,30 @@ void Tester::onEvent(const std::string& name, const std::string& params) noexcep
/// TODO: keep track the status
/// TODO: keep track the status
}
}
void
Tester
::
wait
()
noexcept
void
Tester
::
run
()
noexcept
{
{
using
namespace
std
::
chrono_literals
;
for
(
const
auto
&
e
:
config_
.
getExpectations
())
{
while
(
true
)
{
const
auto
&
command
=
e
.
name_
;
std
::
this_thread
::
sleep_for
(
1
s
);
const
auto
&
expect
=
e
.
value_
;
const
auto
response
=
server_
.
runCmd
(
command
,
""
);
bool
asExpect
=
false
;
if
(
expect
.
is_string
())
{
asExpect
=
(
response
==
expect
.
get
<
std
::
string
>
());
}
else
{
try
{
asExpect
=
(
nlohmann
::
json
::
parse
(
response
)
==
expect
);
}
catch
(...)
{
}
}
if
(
asExpect
)
{
std
::
cout
<<
"[PASS] run command: "
<<
command
<<
std
::
endl
;
}
else
{
std
::
cout
<<
"[FAILED] run command: "
<<
command
<<
" with unexpected response: "
<<
"
\"
"
<<
response
<<
"
\"
(real) vs "
<<
detail
::
toString
(
expect
)
<<
"(expect)"
<<
std
::
endl
;
}
}
}
}
}
...
...
src/xs-test.cc
View file @
1cd1ef2c
...
@@ -22,5 +22,5 @@ int main(int argc, char* argv[]) {
...
@@ -22,5 +22,5 @@ int main(int argc, char* argv[]) {
}
}
xs
::
test
::
Tester
tester
{
configFile
};
xs
::
test
::
Tester
tester
{
configFile
};
tester
.
wait
();
tester
.
run
();
}
}
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