varnishtest "VCL compiler coverage test: vcc_backend.c"

varnish v1 -errvcl "IPv6 address lacks ']'" {
	backend b1 {
		.host = "[0:0:0:0";
	}
}

varnish v1 -errvcl "IPv6 address has wrong port separator" {
	backend b1 {
		.host = "[0:0:0:0]/0";
	}
}

varnish v1 -errvcl "with exactly three digits" {
	backend b1 {
		.host = "${localhost}";
		.probe = {
			.expected_response = 1000;
		}
	}
}

varnish v1 -errvcl "Must specify .threshold with .window" {
	backend b1 {
		.host = "${localhost}";
		.probe = {
			.window = 32;
		}
	}
}

varnish v1 -errvcl "Threshold must be 64 or less" {
	backend b1 {
		.host = "${localhost}";
		.probe = {
			.threshold = 65;
		}
	}
}

varnish v1 -errvcl "Window must be 64 or less" {
	backend b1 {
		.host = "${localhost}";
		.probe = {
			.window = 65;
			.threshold = 64;
		}
	}
}

varnish v1 -errvcl "Threshold can not be greater than window" {
	backend b1 {
		.host = "${localhost}";
		.probe = {
			.window = 63;
			.threshold = 64;
		}
	}
}

varnish v1 -errvcl "NB: Backend Syntax has changed:" {
	backend b1 {
		set .host = "${localhost}";
	}
}

varnish v1 -errvcl "Expected '{' or name of probe, got" {
	backend b1 {
		.host = "${localhost}";
		.probe = "NONE";
	}
}

varnish v1 -errvcl "Field 'port' redefined at:" {
	backend b1 {
		.host = "${localhost}";
		.port = "NONE";
		.port = "NONE";
	}
}

varnish v1 -errvcl "Unknown field:" {
	backend b1 {
		.host = "${localhost}";
		.fourscoreandsevenyearsago = "NONE";
	}
}

varnish v1 -errvcl "Expected .host or .path." {
	backend b1 {
		.port = "NONE";
	}
}

varnish v1 -errvcl "No default probe defined" {
	backend b1 {
		.probe = default;
	}
}

varnish v1 -errvcl "Only one default director possible." {
	backend b1 { .host = "${localhost}"; }
	backend default { .host = "${localhost}"; }
	backend default { .host = "${localhost}"; }
}

varnish v1 -errvcl "Unused backend b1, defined:" {
	backend b1 { .host = "${localhost}"; }
	backend default { .host = "${localhost}"; }
}

varnish v1 -errvcl "Address redefinition at:" {
	backend b1 {
		.host = "${localhost}";
		.path = "/path/to/uds";
	}
}

varnish v1 -errvcl "Must be a valid path or abstract socket:" {
	backend b1 {
		.path = "server.sock";
	}
}

varnish v1 -errvcl "Path too long for a Unix domain socket" {
	backend b1 {
		.path = "/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path/this/super/long/path";
	}
}

varnish v1 -errvcl "Not a socket:" {
	backend b1 {
		.path = "${tmpdir}";
	}
}

# VCC warns, but does not fail, if stat(UDS) fails with ENOENT.
shell { rm -f ${tmpdir}/foo }

varnish v1 -vcl { backend b None; }

varnish v1 -cliexpect "(?s)Cannot stat:.+That was just a warning" \
	{vcl.inline test "vcl 4.1; backend b {.path=\"${tmpdir}/foo\";}"}

# VCC also warns but doesn't fail for EACCES. Tested in c00086.vtc.

# The following test verifies that Varnish continues connecting to a
# socket file, even if the listener at that location changes.

server s1 -listen "${tmpdir}/server.sock" {
	rxreq
	txresp -hdr "Connection: close" -hdr "Cache-Control: max-age=0"
} -start

varnish v1 -vcl {
	backend b {.path = "${s1_sock}"; }
} -start

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

server s1 -start

client c1 -run
