vtest "VCL compiler coverage test: vcc_backend.c"

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

vinyl 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";
	}
}

vinyl 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 }

vinyl v1 -vcl { backend b None; }

vinyl 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 Vinyl 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

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

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

server s1 -start

client c1 -run
