vtest "Does anything get through Unix domain sockets at all ?"

server s1 -listen "${tmpdir}/s1.sock" {
	rxreq
	txresp -body "012345\n"
} -start

vinyl v1 -arg "-a ${tmpdir}/v1.sock -a ${listen_addr}" -vcl+backend {
	sub vcl_backend_response {
		set beresp.do_stream = false;
	}
	sub vcl_deliver {
		# make s_resp_hdrbytes deterministic
		unset resp.http.via;
	}
} -start

vinyl v1 -cliok "param.set debug +workspace"
vinyl v1 -cliok "param.set debug +witness"

vinyl v1 -expect n_object == 0
vinyl v1 -expect sess_conn == 0
vinyl v1 -expect client_req == 0
vinyl v1 -expect cache_miss == 0

client c1 -connect "${v1_sock}" {
	txreq -url "/"
	rxresp
	expect resp.status == 200
} -run

vinyl v1 -expect n_object == 1
vinyl v1 -expect sess_conn == 1
vinyl v1 -expect client_req == 1
vinyl v1 -expect cache_miss == 1
vinyl v1 -expect s_sess == 1
vinyl v1 -expect s_resp_bodybytes == 7
vinyl v1 -expect s_resp_hdrbytes == 156

# vinyltest "vtc v_* macros when the listen address is UDS" (a00019)

vinyl v2 -arg "-a ${tmpdir}/v1.sock -b '${bad_backend}'" -start

vinyl v2 -syntax 4.0 -errvcl {Compiled VCL version (4.0) not supported.} {
	backend default None;
}

vinyl v2 -syntax 4.0 -errvcl \
	{Unix socket backends only supported in VCL4.1 and higher.} \
	{backend default { .path = "${tmpdir}/v1.sock"; }}

vinyl v3 -vcl {
	backend default None;

	sub vcl_recv {
		return(synth(200));
	}

	sub vcl_synth {
		set resp.http.addr = "${v1_addr}";
		set resp.http.port = "${v1_port}";
		set resp.http.sock = "${v1_sock}";
		set resp.http.a0_addr = "${v1_a0_addr}";
		set resp.http.a0_port = "${v1_a0_port}";
		set resp.http.a0_sock = "${v1_a0_sock}";
		set resp.http.a1_addr = "${v1_a1_addr}";
		set resp.http.a1_port = "${v1_a1_port}";
		set resp.http.a1_sock = "${v1_a1_sock}";
	}
} -start

client c1 -connect ${v3_sock} {
	txreq
	rxresp
	expect resp.http.addr == "0.0.0.0"
	expect resp.http.port == "0"
	expect resp.http.sock == "${tmpdir}/v1.sock"
	expect resp.http.a0_addr == "0.0.0.0"
	expect resp.http.a0_port == "0"
	expect resp.http.a0_sock == "${tmpdir}/v1.sock"
	expect resp.http.a1_addr != "0.0.0.0"
	expect resp.http.a1_port != "0"
	expect resp.http.a1_sock ~ "[^ ]+:[^ ]+"
} -run
