[master] b7de3a9da Allow multiple -q options for VUTs
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Wed Jun 12 04:58:11 UTC 2019
commit b7de3a9da43bb45bb93c71a02b912ef627bfd7fa
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Fri May 17 12:05:56 2019 +0200
Allow multiple -q options for VUTs
This makes the following queries equivalent:
vut -g request -q '*Error' -q 'BerespStatus >= 500'
vut -g request -q '
*Error
BerespStatus >= 500
'
vut -g request -q '(*Error) or (BerespStatus >= 500)'
We now have two ways to express "compound" VSL queries, although this
ultimately relies on multiline queries.
diff --git a/bin/varnishtest/tests/u00014.vtc b/bin/varnishtest/tests/u00014.vtc
index 648bc45e6..244dcc08f 100644
--- a/bin/varnishtest/tests/u00014.vtc
+++ b/bin/varnishtest/tests/u00014.vtc
@@ -89,3 +89,8 @@ shell -match "^500 503 $" {
RespStatus == 503 # query 2
'
}
+
+shell -match "^500 503 $" {
+ # multiple -q options
+ ./ncsa.sh -q 'RespStatus == 500' -q 'RespStatus == 503'
+}
diff --git a/include/vut_options.h b/include/vut_options.h
index d6941e1fe..f2c47deb1 100644
--- a/include/vut_options.h
+++ b/include/vut_options.h
@@ -75,7 +75,9 @@
#define VUT_OPT_q \
VOPT("q:", "[-q <query>]", "VSL query", \
- "Specifies the VSL query to use." \
+ "Specifies the VSL query to use. When multiple -q" \
+ " options are specified, all queries are considered" \
+ " as if the 'or' operator was used to combine them." \
)
#define VUT_OPT_r \
diff --git a/lib/libvarnishapi/vut.c b/lib/libvarnishapi/vut.c
index 91be51925..bb46128a9 100644
--- a/lib/libvarnishapi/vut.c
+++ b/lib/libvarnishapi/vut.c
@@ -50,6 +50,7 @@
#include "vas.h"
#include "miniobj.h"
#include "vcs.h"
+#include "vsb.h"
#include "vut.h"
@@ -126,6 +127,30 @@ VUT_Error(struct VUT *vut, int status, const char *fmt, ...)
exit(status);
}
+static void
+vut_arg_q(struct VUT *vut, const char *arg)
+{
+ struct vsb *vsb;
+ char *s;
+
+ AN(arg);
+ if (vut->q_arg == NULL) {
+ REPLACE(vut->q_arg, arg);
+ return;
+ }
+
+ vsb = VSB_new_auto();
+ AN(vsb);
+ AZ(VSB_printf(vsb, "%s\n%s", vut->q_arg, arg));
+ AZ(VSB_finish(vsb));
+
+ s = strdup(VSB_data(vsb));
+ REPLACE(vut->q_arg, s);
+
+ VSB_clear(vsb);
+ VSB_destroy(&vsb);
+}
+
int
VUT_Arg(struct VUT *vut, int opt, const char *arg)
{
@@ -169,8 +194,7 @@ VUT_Arg(struct VUT *vut, int opt, const char *arg)
return (1);
case 'q':
/* Query to use */
- AN(arg);
- REPLACE(vut->q_arg, arg);
+ vut_arg_q(vut, arg);
return (1);
case 'r':
/* Binary file input */
More information about the varnish-commit
mailing list