vtest "Test sub and backend redefinition"

server s1 {
	rxreq
	txresp
} -start

vinyl v1 -vcl+backend { } -start

vinyl v1 -errvcl {Subroutine 'c1' redefined} {
	backend foo { .host = "${localhost}"; }
	sub c1 { }
	sub c1 { }
	sub vcl_recv { call c1; }
}

vinyl v1 -errvcl {Backend 's1' redefined} {
	backend s1 { .host = "${localhost}"; }
	backend s1 { .host = "${localhost}"; }
}

vinyl v1 -errvcl {Probe 'p1' redefined} {
	probe p1 { }
	probe p1 { }
	backend s1 { .host = "${localhost}"; .probe = p1;}
}

vinyl v1 -errvcl {Expected '(' got ';'} {
	backend s1 { .host = "${localhost}"; }
	sub vcl_recv { return; }
}

vinyl v1 -vcl+backend {

	sub foobar {
		set resp.http.foo = "foo";
		return;
		set resp.http.foo = "bar";
	}
	sub vcl_deliver {
		call foobar;
	}
}

client c1 {
	txreq
	rxresp
	expect resp.http.foo == "foo"
	expect resp.http.bar == <undef>
} -run
