Skip to content
Permalink
Browse files

Add VUT_OPT_Q to get a VSL query from a file

  • Loading branch information...
Dridi committed May 17, 2019
1 parent d704203 commit 8fd8366fd55a7818fd66bff09bca3340de2b28c4
@@ -91,6 +91,7 @@ HIS_OPT_p
#undef HIS_CLIENT
#undef HIS_PROF
HIS_OPT_P
VUT_OPT_Q
VUT_OPT_q
VUT_OPT_r
VUT_OPT_t
@@ -68,6 +68,7 @@ VUT_OPT_k
VSL_OPT_L
VUT_OPT_n
VUT_GLOBAL_OPT_P
VUT_OPT_Q
VUT_OPT_q
VUT_OPT_r
VSL_OPT_R
@@ -86,6 +86,7 @@ VUT_OPT_h
VSL_OPT_L
VUT_OPT_n
VUT_GLOBAL_OPT_P
VUT_OPT_Q
VUT_OPT_q
VUT_OPT_r
VSL_OPT_R
@@ -58,6 +58,15 @@ shell -err -expect "Query expression error" {
'
}

shell -err -expect "Query expression error" {
echo '# empty query file' >empty.vslq
varnishncsa -d -n ${v1_name} -Q empty.vslq
}

shell -err -expect "-Q missing.vslq: No such file or directory" {
varnishncsa -d -n ${v1_name} -Q missing.vslq
}

shell -match "^500 $" {
# single query 1
./ncsa.sh -q 'RespStatus == 500'
@@ -90,7 +99,40 @@ shell -match "^500 503 $" {
'
}

shell -match "^500 503 $" {
cat >query.vslq <<-EOF
# query 1
RespStatus == 500

# query 2
RespStatus == 503
EOF
./ncsa.sh -Q query.vslq
}

shell -match "^500 503 $" {
# multiple -q options
./ncsa.sh -q 'RespStatus == 500' -q 'RespStatus == 503'
}

shell -match "^500 503 $" {
# multiple -Q options

cat >query1.vslq <<-EOF
# query 1
RespStatus == 500
EOF

cat >query2.vslq <<-EOF
# query 2
RespStatus == 503
EOF

./ncsa.sh -Q query1.vslq -Q query2.vslq
}

shell -match "^500 503 $" {
# mix -Q and -q options

./ncsa.sh -Q query1.vslq -q 'RespStatus == 503'
}
@@ -73,6 +73,7 @@ VSL_OPT_I
VSL_OPT_L
VUT_OPT_n
TOP_OPT_p
VUT_OPT_Q
VUT_OPT_q
VUT_OPT_r
VUT_OPT_t
@@ -149,7 +149,7 @@ is identical to this query::
(*Error) or (BerespStatus >= 500)

Comments can be used and will be ignored, they start with the ``'#'``
character.
character, which may be more useful when the query is read from a file.

Record selection criteria
-------------------------
@@ -73,10 +73,18 @@
" the host name is used." \
)

#define VUT_OPT_Q \
VOPT("Q:", "[-Q <file>]", "VSL query file", \
"Specifies the file containing the VSL query to use." \
" When multiple -Q or -q options are specified, all" \
" queries are considered as if the 'or' operator was" \
" used to combine them." \
)

#define VUT_OPT_q \
VOPT("q:", "[-q <query>]", "VSL query", \
"Specifies the VSL query to use. When multiple -q" \
" options are specified, all queries are considered" \
"Specifies the VSL query to use. When multiple -q or" \
" -Q options are specified, all queries are considered" \
" as if the 'or' operator was used to combine them." \
)

@@ -51,6 +51,7 @@
#include "miniobj.h"
#include "vcs.h"
#include "vsb.h"
#include "vfil.h"

#include "vut.h"

@@ -195,8 +196,19 @@ VUT_Arg(struct VUT *vut, int opt, const char *arg)
AN(arg);
REPLACE(vut->P_arg, arg);
return (1);
case 'Q':
AN(arg);
p = VFIL_readfile(NULL, arg, NULL);
if (p == NULL) {
VUT_Error(vut, 1, "-Q %s: %s", arg, strerror(errno));
return (-1);
}
vut_arg_q(vut, p);
free(p);
return (1);
case 'q':
/* Query to use */
AN(arg);
vut_arg_q(vut, arg);
return (1);
case 'r':

0 comments on commit 8fd8366

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