varnishtest "Test dynamic backends listening at Unix domain sockets"

server s1 -listen "${tmpdir}/s1.sock" {
	rxreq
	txresp
} -start

varnish v1 -vcl {
	import debug;

	backend dummy { .host = "${bad_ip}"; }

	sub vcl_init {
		new s1 = debug.dyn_uds("${s1_sock}");
	}

	sub vcl_recv {
		set req.backend_hint = s1.backend();
	}
} -start

varnish v1 -expect MAIN.n_backend == 2

client c1 {
	txreq
	rxresp
	expect resp.status == 200
} -run

varnish v1 -errvcl {path must be an absolute path} {
	import debug;

	backend dummy { .host = "${bad_ip}"; }

	sub vcl_init {
		new s1 = debug.dyn_uds("");
	}
}

varnish v1 -errvcl {path must be an absolute path} {
	import debug;

	backend dummy { .host = "${bad_ip}"; }

	sub vcl_init {
		new s1 = debug.dyn_uds("s1.sock");
	}
}

shell { rm -f ${tmpdir}/foo }

varnish v1 -errvcl {Cannot stat path} {
	import debug;

	backend dummy { .host = "${bad_ip}"; }

	sub vcl_init {
		new s1 = debug.dyn_uds("${tmpdir}/foo");
	}
}

varnish v1 -errvcl {is not a socket} {
	import debug;

	backend dummy { .host = "${bad_ip}"; }

	sub vcl_init {
		new s1 = debug.dyn_uds("${tmpdir}");
	}
}
