[master] 76876e7 Add -cliexpect which matches a regexp to the cli response
Poul-Henning Kamp
phk at FreeBSD.org
Sat Nov 26 09:46:04 CET 2016
commit 76876e7a5b0cb5f4e5adf92be217946f4f1f0301
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Sat Nov 26 08:45:31 2016 +0000
Add -cliexpect which matches a regexp to the cli response
diff --git a/bin/varnishtest/tests/v00045.vtc b/bin/varnishtest/tests/v00045.vtc
index fe23158..1c4ac7b 100644
--- a/bin/varnishtest/tests/v00045.vtc
+++ b/bin/varnishtest/tests/v00045.vtc
@@ -16,24 +16,16 @@ varnish v1 -cliok "vcl.state vcl1 cold"
# We should now see it as cooling
delay 1
-shell {
- varnishadm -n ${v1_name} vcl.list |
- grep "auto/cooling.*vcl1" >/dev/null
-}
+
+varnish v1 -cliexpect "auto/cooling.*vcl1" vcl.list
# It can't be warmed up yet
delay 1
-shell {
- varnishadm -n ${v1_name} vcl.state vcl1 warm 2>/dev/null |
- grep "vmod-debug ref on vcl1" >/dev/null
-}
+varnish v1 -cliexpect "vmod-debug ref on vcl1" "vcl.state vcl1 warm"
# It will eventually cool down
delay 2
-shell {
- varnishadm -n ${v1_name} vcl.list |
- grep "auto/cold.*vcl1" >/dev/null
-}
+varnish v1 -cliexpect "auto/cold.*vcl1" vcl.list
# At this point it becomes possible to warm up again
varnish v1 -cliok "vcl.state vcl1 warm"
diff --git a/bin/varnishtest/vtc_varnish.c b/bin/varnishtest/vtc_varnish.c
index 9a0d6ee..a3a9128 100644
--- a/bin/varnishtest/vtc_varnish.c
+++ b/bin/varnishtest/vtc_varnish.c
@@ -49,6 +49,7 @@
#include "vapi/vsl.h"
#include "vapi/vsm.h"
#include "vcli.h"
+#include "vre.h"
#include "vss.h"
#include "vsub.h"
#include "vtcp.h"
@@ -692,18 +693,33 @@ varnish_wait(struct varnish *v)
*/
static void
-varnish_cli(struct varnish *v, const char *cli, unsigned exp)
+varnish_cli(struct varnish *v, const char *cli, unsigned exp, const char *re)
{
enum VCLI_status_e u;
-
+ vre_t *vre = NULL;
+ char *resp = NULL;
+ const char *errptr;
+ int err;
+
+ if (re != NULL) {
+ vre = VRE_compile(re, 0, &errptr, &err);
+ if (vre == NULL)
+ vtc_log(v->vl, 0, "Illegal regexp");
+ }
if (v->cli_fd < 0)
varnish_launch(v);
if (vtc_error)
return;
- u = varnish_ask_cli(v, cli, NULL);
+ u = varnish_ask_cli(v, cli, &resp);
vtc_log(v->vl, 2, "CLI %03u <%s>", u, cli);
if (exp != 0 && exp != (unsigned)u)
vtc_log(v->vl, 0, "FAIL CLI response %u expected %u", u, exp);
+ if (vre != NULL) {
+ err = VRE_exec(vre, resp, strlen(resp), 0, 0, NULL, 0, NULL);
+ if (err < 1)
+ vtc_log(v->vl, 0, "Expect failed (%d)", err);
+ VRE_free(&vre);
+ }
}
/**********************************************************************
@@ -1058,10 +1074,11 @@ varnish_expect(const struct varnish *v, char * const *av)
* varnish vNAME [-cli STRING] [-cliok STRING] [-clierr STRING]
* [-expect STRING OP NUMBER]
*
- * \-cli STRING|-cliok STRING|-clierr STATUS STRING
- * All three of these will send STRING to the CLI, the only difference
- * is what they expect the return code to be. -cli doesn't expect
- * anything, -cliok expects 200 and -clierr expects STATUS
+ * \-cli STRING|-cliok STRING|-clierr STATUS STRING|-cliexpect REGEXP STRING
+ * All four of these will send STRING to the CLI, the only difference
+ * is what they expect the result to be. -cli doesn't expect
+ * anything, -cliok expects 200, -clierr expects STATUS, and
+ * -cliexpect expects the REGEXP to match the returned response.
*
* \-expect STRING OP NUMBER
* Look into the VSM and make sure the counter identified by STRING has
@@ -1117,27 +1134,34 @@ cmd_varnish(CMD_ARGS)
av++;
continue;
}
+ if (!strcmp(*av, "-cleanup")) {
+ AZ(av[1]);
+ varnish_cleanup(v);
+ continue;
+ }
if (!strcmp(*av, "-cli")) {
AN(av[1]);
- varnish_cli(v, av[1], 0);
+ varnish_cli(v, av[1], 0, NULL);
av++;
continue;
}
if (!strcmp(*av, "-clierr")) {
AN(av[1]);
AN(av[2]);
- varnish_cli(v, av[2], atoi(av[1]));
+ varnish_cli(v, av[2], atoi(av[1]), NULL);
av += 2;
continue;
}
- if (!strcmp(*av, "-cleanup")) {
- AZ(av[1]);
- varnish_cleanup(v);
+ if (!strcmp(*av, "-cliexpect")) {
+ AN(av[1]);
+ AN(av[2]);
+ varnish_cli(v, av[2], 0, av[1]);
+ av += 2;
continue;
}
if (!strcmp(*av, "-cliok")) {
AN(av[1]);
- varnish_cli(v, av[1], (unsigned)CLIS_OK);
+ varnish_cli(v, av[1], (unsigned)CLIS_OK, NULL);
av++;
continue;
}
More information about the varnish-commit
mailing list