vtest "Test feature trace"

server s1 {
	rxreq
	txresp
} -start

vinyl v1 -arg "-p feature=+trace" -vcl+backend {
	sub vcl_deliver {
		set resp.http.vcl = "vclA";
	}
} -start

vinyl v1 -cliok "param.set debug +syncvsl"

vinyl v1 -cliok "vcl.label vclA vcl1"

vinyl v1 -vcl+backend {
	sub vcl_recv {
		if (req.http.vcl == "vcl1") {
			return (vcl(vclA));
		}
		set req.trace = false;
	}
	sub vcl_deliver {
		set resp.http.vcl = "vcl2";
	}
}

vinyl v1 -cliok "vcl.label vclB vcl2"
vinyl v1 -cliok "vcl.list"

# Ensure old VSLs do not confuse l1
vinyl v1 -vsl_catchup

logexpect l1 -v v1 -g raw {
	expect * 1001	VCL_call	"RECV"
	expect 0 1001	VCL_trace	{^vcl2 \d+ \d+\.\d+\.\d+$}
	expect * 1001	VCL_call	"RECV"
	expect 0 1001	VCL_trace	{^vcl1 \d+ \d+\.\d+\.\d+$}
	expect * 1002	VCL_call	"BACKEND_FETCH"
	expect 0 1002	VCL_trace	{^vcl1 \d+ \d+\.\d+\.\d+$}
	expect * 1003	VCL_call	"DELIVER"
	expect 0 1003	RespHeader	{^vcl: vcl2}
} -start

client c1 {
	txreq -hdr "vcl: vcl1"
	rxresp
	expect resp.http.vcl == vclA

	txreq
	rxresp
	expect resp.http.vcl == vcl2
} -run

logexpect l1 -wait
