Commit a4232d10 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add -clijson, which checks that CLI output can be parsed as JSON

parent 467f10c5
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment