vtest "vinylstatdiff coverage"

feature cmd "command -v diff"

server s1 {
	rxreq
	txresp
} -start

vinyl v1 -vcl+backend "" -start

shell {
	vinylstat -n ${v1_name} -1 \
		-I MAIN.n_object -I MAIN.cache_* -I MAIN.client_req |
	tee stat1.txt
}

client c1 {
	txreq
	rxresp
} -start

vinyl v1 -vsl_catchup

shell {
	vinylstat -n ${v1_name} -1 \
		-I MAIN.n_object -I MAIN.cache_* -I MAIN.esi_req |
	tee stat2.txt
}

shell -expect Usage: {vinylstatdiff -h}
shell -expect "Error: not enough arguments" -err {vinylstatdiff}
shell -expect "Error: not enough arguments" -err {vinylstatdiff a}
shell -expect "Error: too many arguments" -err {vinylstatdiff a b c}

shell {
	vinylstatdiff stat1.txt stat2.txt | tee diff.txt
}

shell {
	sed 's/@/ /' >expected.txt <<-EOF
	--- stat1.txt
	+++ stat2.txt
	@MAIN.cache_miss  -0  -0.00  Cache misses
	@                 +1  +0.00
	-MAIN.client_req   0   0.00  Good client requests received
	+MAIN.esi_req      0   0.00  ESI subrequests
	@MAIN.n_object    -0   .     object structs made
	@                 +1   .
	EOF

	diff -u expected.txt diff.txt
}
