#!/usr/bin/env expect
############################################################################
# Purpose: Test of Slurm functionality
#          lsid wrapper test
############################################################################
# Copyright (C) SchedMD LLC.
#
# This file is part of Slurm, a resource management program.
# For details, see <https://slurm.schedmd.com/>.
# Please also read the included file: DISCLAIMER.
#
# Slurm is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# Slurm is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with Slurm; if not, write to the Free Software Foundation, Inc.
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
############################################################################
source ./globals

if {[file executable $lsid] == 0} {
	skip "$lsid does not exist"
}

set cluster_name [get_config_param "ClusterName"]
regsub {\(.*} [get_config_param {SlurmctldHost[0]}] {} control_machine
set lsid_cluster_name ""
set lsid_control_machine ""
set cluster_name_ok 0
set control_machine_ok 0

spawn $lsid
expect {
	-re "My cluster name is ($re_word_str)" {
		set lsid_cluster_name $expect_out(1,string)
		exp_continue
	}
	-re "My master name is ($re_word_str)" {
		set lsid_control_machine $expect_out(1,string)
		exp_continue
	}
	timeout {
		fail "lsid not responding"
	}
	eof {
		wait
	}
}

subtest {$cluster_name eq $lsid_cluster_name} "Verify lsid's cluster name matches the configured ClusterName" "$cluster_name != $lsid_cluster_name"
subtest {$control_machine eq $lsid_control_machine} "Verify lsid's master name matches the configured SlurmctldHost\[0\]" "$control_machine != $lsid_control_machine"
