vtest "Test fileread for std VMOD"

shell {
	printf "File One" > "${tmpdir}/one"
	printf "File Two" > "${tmpdir}/two"
	printf "File Three" > "${tmpdir}/three"
}

server s1 {
	loop 3 {
		rxreq
		txresp
	}
} -start


vinyl v1 -vcl+backend {
	import std;

	sub vcl_deliver {
	    set resp.http.foo = std.fileread("${tmpdir}" + req.url);
	    set resp.http.fooblob = std.blobread("${tmpdir}" + req.url);
	}
} -start


client c1 {
	txreq -url "/one"
	rxresp
	expect resp.http.foo == "File One"
	expect resp.http.fooblob == :RmlsZSBPbmU=:

	txreq -url "/two"
	rxresp
	expect resp.http.foo == "File Two"
	expect resp.http.fooblob == :RmlsZSBUd28=:

	txreq -url "/three"
	rxresp
	expect resp.http.foo == "File Three"
	expect resp.http.fooblob == :RmlsZSBUaHJlZQ==:
} -run

client c1 -run
client c1 -run
