varnishtest "varnishstat coverage"

feature cmd "command -v cmp"

server s1 {
	rxreq
	txresp
} -start

varnish v1 -vcl+backend {} -start

# On fast systems the next varnishstat will return "inf" counters
# if we don't give varnishd a chance to get going.

delay 1

process p1 {varnishstat -1 -n ${v1_name} -f ^LCK.vbe.destroy \
	-f LCK.vbe.* -f LCK.mempool.creat | tr '[1-9]' '0'} -run

shell "grep -q vbe ${p1_out}"
shell "grep -q LCK.mempool.creat ${p1_out}"
shell -err "grep -q LCK.vbe.destroy ${p1_out}"

process p2 {varnishstat -1 -n ${v1_name} -f ^*vbe.destroy -f *vbe* \
	-f LCK.mempool.c* | tr '[1-9]' '0'} -run

process p3 {varnishstat -1 -n ${v1_name} -X *vbe.destroy -I *vbe* \
	-f LCK.mempool.c* | tr '[1-9]' '0'} -run

shell "cmp -s ${p1_out} ${p2_out}"
shell "cmp -s ${p1_out} ${p3_out}"

shell -expect "MGT.uptime" \
	"varnishstat -1 -n ${v1_name} -f ^MAIN*"
shell -match "^MGT" \
	"varnishstat -1 -n ${v1_name} -f ^foo"

shell -match "Usage: .*varnishstat <options>" \
	"varnishstat -h"
shell -expect "Varnishstat -f option fields:" \
	"varnishstat -n ${v1_name} -l"
shell -expect "Copyright (c) 2006 Verdens Gang AS" \
	"varnishstat -V"
shell -err -match "Usage: .*varnishstat <options>" \
	"varnishstat extra"
shell -err -expect "-t: Invalid argument: -1" \
	"varnishstat -t -1"
shell -err -expect "-t: Invalid argument: Nan" \
	"varnishstat -t Nan"
shell -err -expect "-t: Invalid argument: foo" \
	"varnishstat -t foo"
shell -err -expect "Could not get hold of varnishd" \
	"varnishstat -n /nonexistent -t 1"
shell -expect "MAIN.uptime" \
	"varnishstat -n ${v1_name} -1"
shell -expect "<name>MAIN.uptime</name>" \
	"varnishstat -n ${v1_name} -x"
shell -match {"MAIN.uptime":} \
	"varnishstat -n ${v1_name} -j"
