#!/usr/bin/env bash
# Check that the Cobbler HTTP endpoint /autoinstall/ is callable

source ${SYSTESTS_PRELUDE} && prepare

set -x -e -o pipefail

# Arrange
cobbler distro add --name fake --arch x86_64 --kernel ${fake_kernel} \
	--initrd ${fake_initramfs}
cobbler profile add --name fake --distro fake
cobbler system add --name testbed --profile fake
# Prepare expected result
cat >${tmp}/a <<-EOF
bootstate=0
title=Loading ESXi installer
prefix=/images/fake
kernel=b.b00
kernelopt=runweasel ks=http://192.168.1.1:80/cblr/svc/op/ks/profile/fake
modules=\$esx_modules
build=
updated=0
EOF

cat >${tmp}/b <<-EOF
bootstate=0
title=Loading ESXi installer
prefix=/images/fake
kernel=b.b00
kernelopt=runweasel ks=http://192.168.1.1:80/cblr/svc/op/ks/system/testbed
modules=\$esx_modules
build=
updated=0
EOF

# Act
curl --output ${tmp}/c http://localhost/cblr/svc/op/bootcfg/system/testbed
curl --output ${tmp}/d http://localhost/cblr/svc/op/bootcfg/profile/fake

# Assert
diff ${tmp}/{a,d}
diff ${tmp}/{b,c}