# Test that the install command creates necessary directories and files.
#
# @TEST-EXEC: bash %INPUT
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff standalone
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff cluster

. zeekctl-test-setup

# Verify that various files don't exist before running "zeekctl install".
while read line; do
    test ! -e $ZEEKCTL_INSTALL_PREFIX/$line
done << EOF
logs/current
spool/state.db
spool/installed-scripts-do-not-touch
EOF

files_exist() {
test -h $ZEEKCTL_INSTALL_PREFIX/logs/current

while read line; do
    test -e $ZEEKCTL_INSTALL_PREFIX/$line
done << EOF
spool/state.db
spool/installed-scripts-do-not-touch/site/local.zeek
spool/installed-scripts-do-not-touch/auto/zeekctl-config.zeek
spool/installed-scripts-do-not-touch/auto/local-networks.zeek
EOF
}

installed_dir=$ZEEKCTL_INSTALL_PREFIX/spool/installed-scripts-do-not-touch

# Test with a standalone config.

zeekctl install > standalone

files_exist

# Verify that the correct layout file was created.
test -e $installed_dir/auto/standalone-layout.zeek
test ! -e $installed_dir/auto/cluster-layout.zeek

# Test with a cluster config.

while read line; do installfile $line; done << EOF
etc/node.cfg__cluster
EOF

zeekctl install > cluster

files_exist

# Verify that the correct layout file was created.
test ! -e $installed_dir/auto/standalone-layout.zeek
test -e $installed_dir/auto/cluster-layout.zeek
