Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
a4232d10
Commit
a4232d10
authored
May 13, 2018
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add -clijson, which checks that CLI output can be parsed as JSON
parent
467f10c5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
1 deletion
+40
-1
vtc_varnish.c
bin/varnishtest/vtc_varnish.c
+40
-1
No files found.
bin/varnishtest/vtc_varnish.c
View file @
a4232d10
...
...
@@ -47,6 +47,7 @@
#include "vapi/vsl.h"
#include "vapi/vsm.h"
#include "vcli.h"
#include "vjsn.h"
#include "vre.h"
#include "vsub.h"
#include "vtcp.h"
...
...
@@ -655,6 +656,34 @@ varnish_wait(struct varnish *v)
}
/**********************************************************************
* Ask a CLI JSON question
*/
static
void
varnish_cli_json
(
struct
varnish
*
v
,
const
char
*
cli
)
{
enum
VCLI_status_e
u
;
char
*
resp
=
NULL
;
const
char
*
errptr
;
struct
vjsn
*
vj
;
if
(
v
->
cli_fd
<
0
)
varnish_launch
(
v
);
if
(
vtc_error
)
return
;
u
=
varnish_ask_cli
(
v
,
cli
,
&
resp
);
vtc_log
(
v
->
vl
,
2
,
"CLI %03u <%s>"
,
u
,
cli
);
if
(
u
!=
CLIS_OK
)
vtc_fatal
(
v
->
vl
,
"FAIL CLI response %u expected %u"
,
u
,
CLIS_OK
);
vj
=
vjsn_parse
(
resp
,
&
errptr
);
if
(
vj
==
NULL
)
vtc_fatal
(
v
->
vl
,
"FAIL CLI, not good JSON: %s"
,
errptr
);
vjsn_delete
(
&
vj
);
free
(
resp
);
}
/**********************************************************************
* Ask a CLI question
*/
...
...
@@ -1005,7 +1034,7 @@ varnish_expect(const struct varnish *v, char * const *av)
* ``varnishadm``) with these additional switches::
*
* varnish vNAME [-cli STRING] [-cliok STRING] [-clierr STRING]
* [-expect STRING OP NUMBER]
* [-
clijson STRING] [-
expect STRING OP NUMBER]
*
* \-cli STRING|-cliok STRING|-clierr STATUS STRING|-cliexpect REGEXP STRING
* All four of these will send STRING to the CLI, the only difference
...
...
@@ -1013,6 +1042,10 @@ varnish_expect(const struct varnish *v, char * const *av)
* anything, -cliok expects 200, -clierr expects STATUS, and
* -cliexpect expects the REGEXP to match the returned response.
*
* \-clijson STRING
* Send STRING to the CLI, expect success (CLIS_OK/200) and check
* that the response is parsable JSON.
*
* \-expect PATTERN OP NUMBER
* Look into the VSM and make sure the first VSC counter identified by
* PATTERN has a correct value. OP can be ==, >, >=, <, <=. For
...
...
@@ -1099,6 +1132,12 @@ cmd_varnish(CMD_ARGS)
av
+=
2
;
continue
;
}
if
(
!
strcmp
(
*
av
,
"-clijson"
))
{
AN
(
av
[
1
]);
varnish_cli_json
(
v
,
av
[
1
]);
av
++
;
continue
;
}
if
(
!
strcmp
(
*
av
,
"-cliok"
))
{
AN
(
av
[
1
]);
varnish_cli
(
v
,
av
[
1
],
(
unsigned
)
CLIS_OK
,
NULL
);
...
...
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