Skip to content
Permalink
Browse files

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.
  • Loading branch information...
Dridi committed May 17, 2019
1 parent c061b8e commit b7de3a9da43bb45bb93c71a02b912ef627bfd7fa
Showing with 34 additions and 3 deletions.
  1. +5 −0 bin/varnishtest/tests/u00014.vtc
  2. +3 −1 include/vut_options.h
  3. +26 −2 lib/libvarnishapi/vut.c
@@ -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'
}
@@ -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 \
@@ -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 */

0 comments on commit b7de3a9

Please sign in to comment.
You can’t perform that action at this time.