vtest "The active VCL must always be warm"

shell {
	cat >${tmpdir}/f1 <<-EOF
	vcl 4.1;
	backend default none;
	EOF
}

# Load a cold VCL. This should not become the active VCL.
vinyl v1 -cliok "vcl.load vcl_cold ${tmpdir}/f1 cold"
vinyl v1 -cliexpect "available *cold *cold *- *vcl_cold" "vcl.list"

# The cache should not start without a warm VCL.
vinyl v1 -clierr 300 "start"

# Load a warm VCL and make it the active VCL.
vinyl v1 -cliok "vcl.load vcl_warm ${tmpdir}/f1 warm"
vinyl v1 -cliok "vcl.use vcl_warm"
vinyl v1 -cliexpect "active *warm *warm *- *vcl_warm" "vcl.list"

# The cache now starts.
vinyl v1 -cliok "start"
vinyl v1 -cliexpect "available *cold *cold *0 *vcl_cold" "vcl.list"
vinyl v1 -cliexpect "active *warm *warm *0 *vcl_warm" "vcl.list"

# Load an automatically warming VCL, and set it as the active VCL.
vinyl v1 -cliok "vcl.load vcl_auto ${tmpdir}/f1 warm"
vinyl v1 -cliok "vcl.use vcl_auto"
vinyl v1 -cliexpect "available *warm *warm *0 *vcl_warm" "vcl.list"
vinyl v1 -cliexpect "active *warm *warm *0 *vcl_auto" "vcl.list"

# Cool the previous active VCL.
vinyl v1 -cliok "vcl.state vcl_warm cold"
vinyl v1 -cliexpect "available *cold *cold *0 *vcl_warm" "vcl.list"

# Restart the cache.
vinyl v1 -cliok "stop" -cliok "start"
vinyl v1 -cliexpect "available *cold *cold *0 *vcl_cold" "vcl.list"
vinyl v1 -cliexpect "available *cold *cold *0 *vcl_warm" "vcl.list"
vinyl v1 -cliexpect "active *warm *warm *0 *vcl_auto" "vcl.list"
