2012-06-04 20:41:22 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
DIR="${MSM_DIR:-$(pwd)}"
|
|
|
|
DEFUALT_CONF="${MSM_DEFAULT_CONF:-${DIR}/msm.conf}"
|
|
|
|
TESTS_DIR="${MSM_TESTS_DIR:-${DIR}/tests}"
|
|
|
|
TMP_DIR="/tmp/msmtest"
|
2012-06-05 21:38:21 +00:00
|
|
|
TEST_RAM="256"
|
2012-06-04 20:41:22 +00:00
|
|
|
|
2012-06-05 18:40:32 +00:00
|
|
|
# Exit codes
|
|
|
|
declare -r EX_OK=0
|
|
|
|
declare -r EX_INVALID_USER=64
|
|
|
|
declare -r EX_INVALID_COMMAND=65
|
|
|
|
declare -r EX_INVALID_ARGUMENT=66
|
|
|
|
declare -r EX_SERVER_STOPPED=67
|
|
|
|
declare -r EX_SERVER_RUNNING=68
|
|
|
|
declare -r EX_NAME_NOT_FOUND=69
|
|
|
|
declare -r EX_FILE_NOT_FOUND=70
|
|
|
|
declare -r EX_DUPLICATE_NAME=71
|
|
|
|
declare -r EX_LOGS_NOT_ROLLED=72
|
|
|
|
declare -r EX_CONF_ERROR=73
|
|
|
|
|
2012-06-04 20:41:22 +00:00
|
|
|
oneTimeSetUp() {
|
|
|
|
# Variables used in tests
|
|
|
|
SCRIPT="${MSM_SCRIPT:-${DIR}/init/msm}"
|
2012-06-04 20:51:49 +00:00
|
|
|
export MSM_CONF="${TMP_DIR}/msm.conf"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setUp() {
|
2012-06-04 20:41:22 +00:00
|
|
|
source "$DEFUALT_CONF"
|
|
|
|
|
|
|
|
# Create the testing conf from the default one
|
2012-06-06 00:08:42 +00:00
|
|
|
mkdir -p "$TMP_DIR" && chown "$USERNAME" "$TMP_DIR"
|
2012-06-06 00:11:56 +00:00
|
|
|
cp "$DEFUALT_CONF" "$MSM_CONF" && chown "$USERNAME" "$MSM_CONF"
|
2012-06-04 20:41:22 +00:00
|
|
|
|
|
|
|
# Overwrite the directories to use for testin purposes
|
|
|
|
echo "" >> "$MSM_CONF"
|
|
|
|
echo "# Auto appended by test script:" >> "$MSM_CONF"
|
|
|
|
echo "SERVER_STORAGE_PATH=\"${TMP_DIR}/servers\"" >> "$MSM_CONF"
|
|
|
|
echo "JAR_STORAGE_PATH=\"${TMP_DIR}/jars\"" >> "$MSM_CONF"
|
|
|
|
echo "RAMDISK_STORAGE_PATH=\"${TMP_DIR}/fakeramdisk\"" >> "$MSM_CONF"
|
|
|
|
echo "WORLD_ARCHIVE_PATH=\"${TMP_DIR}/archives/worlds\"" >> "$MSM_CONF"
|
|
|
|
echo "LOG_ARCHIVE_PATH=\"${TMP_DIR}/archives/logs\"" >> "$MSM_CONF"
|
|
|
|
echo "BACKUP_ARCHIVE_PATH=\"${TMP_DIR}/archives/backups\"" >> "$MSM_CONF"
|
|
|
|
echo "DEBUG=\"true\"" >> "$MSM_CONF"
|
2012-06-05 21:38:21 +00:00
|
|
|
echo "DEFAULT_SCREEN_NAME=\"msmtest-{SERVER_NAME}\"" >> "$MSM_CONF"
|
|
|
|
echo "DEFAULT_INVOCATION=\"java -Xmx${TEST_RAM}M -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalPacing -XX:+AggressiveOpts -jar {JAR} nogui\"" >> "$MSM_CONF"
|
2012-06-05 18:40:32 +00:00
|
|
|
|
|
|
|
source "$MSM_CONF"
|
2012-06-05 20:08:23 +00:00
|
|
|
|
|
|
|
# Variables accessible by all tests, which are set by the stdall, stderr,
|
|
|
|
# stdout and quiet utility functions.
|
|
|
|
declare OUTPUT
|
|
|
|
declare EXIT_CODE
|
2012-06-04 20:41:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tearDown() {
|
2012-06-05 20:08:23 +00:00
|
|
|
# Clear the variables used in test functions
|
|
|
|
unset EXIT_CODE
|
|
|
|
unset OUTPUT
|
|
|
|
|
2012-06-04 20:41:22 +00:00
|
|
|
# Remove the temporary testing directory
|
|
|
|
if [ -d "${TMP_DIR}" ]; then
|
|
|
|
rm -rf "${TMP_DIR}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2012-06-04 23:09:54 +00:00
|
|
|
|
|
|
|
# Utils
|
|
|
|
# -----
|
|
|
|
|
2012-06-05 20:08:23 +00:00
|
|
|
reset_vars() {
|
|
|
|
unset OUTPUT
|
|
|
|
unset EXIT_CODE
|
|
|
|
}
|
|
|
|
|
|
|
|
# Ensure there is output in stderr
|
|
|
|
expect_stderr() {
|
|
|
|
reset_vars
|
|
|
|
OUTPUT=$("$@" 2>&1 1>/dev/null)
|
|
|
|
EXIT_CODE=$?
|
|
|
|
assertNotNull "No stderr given when expected." "$OUTPUT"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Ensure there is NO output in stderr
|
|
|
|
expect_stderr_empty() {
|
|
|
|
reset_vars
|
|
|
|
OUTPUT=$("$@" 2>&1 1>/dev/null)
|
|
|
|
EXIT_CODE=$?
|
|
|
|
assertNull "$OUTPUT" "$OUTPUT"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Ensure there is output in stdout
|
|
|
|
expect_stdout() {
|
|
|
|
reset_vars
|
|
|
|
OUTPUT=$("$@")
|
|
|
|
EXIT_CODE=$?
|
|
|
|
assertNotNull "No stdout given when expected." "$OUTPUT"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Ensure there is NO output in stdout
|
|
|
|
expect_stdout_empty() {
|
|
|
|
reset_vars
|
|
|
|
OUTPUT=$("$@")
|
|
|
|
EXIT_CODE=$?
|
|
|
|
assertNull "$OUTPUT" "$OUTPUT"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Execute a command silently (ignore stdout and stderr)
|
2012-06-05 18:40:32 +00:00
|
|
|
quiet() {
|
2012-06-05 20:08:23 +00:00
|
|
|
reset_vars
|
2012-06-05 18:40:32 +00:00
|
|
|
"$@" >& /dev/null
|
2012-06-05 20:08:23 +00:00
|
|
|
EXIT_CODE=$?
|
2012-06-04 23:09:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-05 00:41:18 +00:00
|
|
|
# Global Command Tests
|
|
|
|
# -----------------------
|
|
|
|
|
|
|
|
### "msm start" tests
|
|
|
|
|
|
|
|
### "msm stop" tests
|
|
|
|
|
|
|
|
### "msm restart" tests
|
|
|
|
|
|
|
|
### "msm version" tests
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Server Management Tests
|
|
|
|
# -----------------------
|
|
|
|
|
|
|
|
### "msm server list" tests
|
|
|
|
|
2012-06-05 20:08:23 +00:00
|
|
|
test_listing_no_servers() {
|
|
|
|
expect_stderr_empty $SCRIPT server list
|
|
|
|
assertEquals "Incorrect exit code." $EX_OK $EXIT_CODE
|
|
|
|
}
|
|
|
|
|
2012-06-05 00:41:18 +00:00
|
|
|
### "msm server create" tests
|
2012-06-04 20:41:22 +00:00
|
|
|
|
2012-06-04 23:50:24 +00:00
|
|
|
test_reserved_server_names() {
|
2012-06-04 23:09:54 +00:00
|
|
|
for name in "start" "stop" "restart" "server" "version" "jargroup" "all"; do
|
2012-06-05 20:08:23 +00:00
|
|
|
expect_stderr $SCRIPT server create $name
|
|
|
|
assertEquals "Incorrect exit code when creating server name \"$name\"." $EX_INVALID_ARGUMENT $EXIT_CODE
|
2012-06-04 23:50:24 +00:00
|
|
|
assertFalse "Server \"$name\" directory was created when it should not have been." "[ -d \"$SERVER_STORAGE_PATH/$name\" ]"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
test_common_invalid_server_names() {
|
2012-06-05 20:08:23 +00:00
|
|
|
expect_stderr $SCRIPT server create "name with spaces"
|
|
|
|
assertEquals "Incorrect exit code when creating server name \"name with spaces\"." $EX_INVALID_ARGUMENT $EXIT_CODE
|
2012-06-05 18:40:32 +00:00
|
|
|
assertFalse "Server \"name with spaces\" directory was created when it should not have been." "[ -d \"$SERVER_STORAGE_PATH/$name\" ]"
|
2012-06-04 23:50:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test_valid_edge_case_server_names() {
|
|
|
|
for name in "serverstart" "CapitalLetters" "0987654321" "name-with-dashes" "name_with_underscores" "Combination-of_different1Things2"; do
|
2012-06-05 20:08:23 +00:00
|
|
|
expect_stderr_empty $SCRIPT server create $name
|
|
|
|
assertEquals "Incorrect exit code when creating server name \"$name\"." $EX_OK $EXIT_CODE
|
2012-06-04 23:50:24 +00:00
|
|
|
assertTrue "Server \"$name\" directory was NOT created when it should not have been." "[ -d \"$SERVER_STORAGE_PATH/$name\" ]"
|
2012-06-04 23:09:54 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2012-06-05 21:38:21 +00:00
|
|
|
test_creating_server_without_any_jargroups() {
|
2012-06-05 20:08:23 +00:00
|
|
|
expect_stderr_empty $SCRIPT server create example
|
|
|
|
assertEquals "Incorrect exit code." $EX_OK $EXIT_CODE
|
2012-06-05 00:38:33 +00:00
|
|
|
assertTrue "Server was not created." "[ -d \"$SERVER_STORAGE_PATH/example\" ]"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Assumes: test_create_server_without_any_jargroups
|
|
|
|
test_creating_server_when_that_name_already_exists() {
|
2012-06-05 18:40:32 +00:00
|
|
|
# Create server "example"
|
|
|
|
quiet $SCRIPT server create example
|
|
|
|
# Create another server called "example", should be prevented
|
2012-06-05 20:08:23 +00:00
|
|
|
expect_stderr $SCRIPT server create example
|
2012-06-05 00:38:33 +00:00
|
|
|
|
2012-06-05 20:08:23 +00:00
|
|
|
assertEquals "Incorrect exit code." $EX_DUPLICATE_NAME $EXIT_CODE
|
2012-06-04 20:42:08 +00:00
|
|
|
}
|
2012-06-04 20:41:22 +00:00
|
|
|
|
2012-06-05 18:40:32 +00:00
|
|
|
# Assumes: test_creating_jargroup
|
2012-06-05 21:38:21 +00:00
|
|
|
test_creating_server_with_jar_groups() {
|
2012-06-05 18:40:32 +00:00
|
|
|
# Create the "minecraft" jar group, which is used by default when creating
|
|
|
|
# new servers.
|
|
|
|
quiet $SCRIPT jargroup create minecraft "https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft_server.jar"
|
|
|
|
# Create a new server that will use the "minecraft" jar group.
|
2012-06-05 20:08:23 +00:00
|
|
|
expect_stderr_empty $SCRIPT server create example
|
2012-06-05 21:38:21 +00:00
|
|
|
|
2012-06-05 20:08:23 +00:00
|
|
|
assertEquals "Incorrect exit code." $EX_OK $EXIT_CODE
|
2012-06-05 18:40:32 +00:00
|
|
|
assertTrue "Server direcotry was not created." "[ -d \"$SERVER_STORAGE_PATH/example\" ]"
|
2012-06-04 23:09:54 +00:00
|
|
|
assertTrue "Server jar was not linked." "[ -f \"$SERVER_STORAGE_PATH/example/$DEFAULT_JAR\" ]"
|
2012-06-04 20:52:13 +00:00
|
|
|
}
|
|
|
|
|
2012-06-05 00:41:18 +00:00
|
|
|
### "msm server delete" tests
|
|
|
|
|
2012-06-05 00:40:28 +00:00
|
|
|
test_deleting_server_that_does_not_exist() {
|
2012-06-05 20:08:23 +00:00
|
|
|
expect_stderr $SCRIPT server delete example
|
|
|
|
assertEquals "Incorrect exit code." $EX_NAME_NOT_FOUND $EXIT_CODE
|
2012-06-05 00:40:28 +00:00
|
|
|
}
|
|
|
|
|
2012-06-12 01:02:20 +00:00
|
|
|
# Assumes: test_creating_server_without_any_jargroups
|
2012-06-05 21:38:21 +00:00
|
|
|
test_deleting_server_that_exists_and_is_stopped() {
|
2012-06-05 20:27:42 +00:00
|
|
|
quiet $SCRIPT server create example
|
|
|
|
expect_stderr_empty $SCRIPT server delete example <<< "y"
|
|
|
|
|
|
|
|
assertEquals "Incorrect exit code." $EX_OK $EXIT_CODE
|
|
|
|
assertFalse "Server directory was not removed." "[ -d \"$SERVER_STORAGE_PATH/example\" ]"
|
|
|
|
}
|
|
|
|
|
2012-06-05 00:43:17 +00:00
|
|
|
### "msm server rename" tests
|
|
|
|
|
2012-06-05 21:38:21 +00:00
|
|
|
test_renaming_server_that_does_not_exist() {
|
|
|
|
expect_stderr $SCRIPT server rename example example_new_name
|
|
|
|
assertEquals "Incorrect exit code." $EX_NAME_NOT_FOUND $EXIT_CODE
|
|
|
|
}
|
|
|
|
|
2012-06-12 01:02:20 +00:00
|
|
|
# Assumes: test_creating_server_without_any_jargroups
|
2012-06-05 21:38:21 +00:00
|
|
|
test_renaming_server_that_exists_and_is_stopped() {
|
|
|
|
quiet $SCRIPT server create example
|
|
|
|
expect_stderr_empty $SCRIPT server rename example example_new_name
|
|
|
|
|
|
|
|
assertEquals "Incorrect exit code." $EX_OK $EXIT_CODE
|
|
|
|
assertFalse "Original server name directory still exists." "[ -d \"$SERVER_STORAGE_PATH/example\" ]"
|
|
|
|
assertTrue "New server name directory was not created." "[ -d \"$SERVER_STORAGE_PATH/example_new_name\" ]"
|
|
|
|
}
|
|
|
|
|
2012-06-04 20:41:22 +00:00
|
|
|
|
2012-06-05 00:41:18 +00:00
|
|
|
# Individual Server Tests
|
|
|
|
# -----------------------
|
|
|
|
|
|
|
|
### "msm <server> start" tests
|
|
|
|
|
|
|
|
### "msm <server> stop" tests
|
|
|
|
|
|
|
|
### "msm <server> restart" tests
|
|
|
|
|
|
|
|
### "msm <server> status" tests
|
|
|
|
|
|
|
|
### "msm <server> connected" tests
|
|
|
|
|
|
|
|
### "msm <server> worlds list" tests
|
|
|
|
|
|
|
|
### "msm <server> worlds load" tests
|
|
|
|
|
|
|
|
### "msm <server> worlds ram" tests
|
|
|
|
|
|
|
|
### "msm <server> worlds todisk" tests
|
|
|
|
|
|
|
|
### "msm <server> worlds backup" tests
|
|
|
|
|
|
|
|
### "msm <server> worlds on" tests
|
|
|
|
|
|
|
|
### "msm <server> worlds off" tests
|
|
|
|
|
|
|
|
### "msm <server> worlds off" tests
|
|
|
|
|
|
|
|
### "msm <server> logroll" tests
|
|
|
|
|
|
|
|
### "msm <server> backup" tests
|
|
|
|
|
|
|
|
### "msm <server> jar" tests
|
|
|
|
|
|
|
|
### "msm <server> whitelist on" tests
|
2012-06-04 20:41:22 +00:00
|
|
|
|
2012-06-05 00:41:18 +00:00
|
|
|
### "msm <server> whitelist off" tests
|
|
|
|
|
|
|
|
### "msm <server> whitelist add" tests
|
|
|
|
|
|
|
|
### "msm <server> whitelist remove" tests
|
|
|
|
|
|
|
|
### "msm <server> whitelist list" tests
|
|
|
|
|
|
|
|
### "msm <server> blacklist player add" tests
|
|
|
|
|
|
|
|
### "msm <server> blacklist player remove" tests
|
|
|
|
|
|
|
|
### "msm <server> blacklist ip add" tests
|
|
|
|
|
|
|
|
### "msm <server> blacklist ip remove" tests
|
|
|
|
|
|
|
|
### "msm <server> blacklist list" tests
|
|
|
|
|
|
|
|
### "msm <server> operator add" tests
|
|
|
|
|
|
|
|
### "msm <server> operator remove" tests
|
|
|
|
|
|
|
|
### "msm <server> operator list" tests
|
|
|
|
|
|
|
|
### "msm <server> gamemode" tests
|
|
|
|
|
|
|
|
### "msm <server> kick" tests
|
|
|
|
|
|
|
|
### "msm <server> say" tests
|
|
|
|
|
|
|
|
### "msm <server> time set" tests
|
|
|
|
|
|
|
|
### "msm <server> time add" tests
|
|
|
|
|
|
|
|
### "msm <server> toggledownfall" tests
|
|
|
|
|
|
|
|
### "msm <server> save on" tests
|
|
|
|
|
|
|
|
### "msm <server> save off" tests
|
|
|
|
|
|
|
|
### "msm <server> save all" tests
|
|
|
|
|
|
|
|
### "msm <server> cmd" tests
|
|
|
|
|
|
|
|
### "msm <server> cmdlog" tests
|
|
|
|
|
|
|
|
### "msm <server> console" tests
|
2012-06-04 20:41:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Jargroup Tests
|
|
|
|
# --------------
|
|
|
|
|
2012-06-05 00:41:18 +00:00
|
|
|
### "msm jargroup list" test
|
|
|
|
|
|
|
|
### "msm jargroup create" test
|
|
|
|
|
2012-06-05 18:40:32 +00:00
|
|
|
# test_creating_jargroup() {
|
|
|
|
#
|
|
|
|
# }
|
|
|
|
|
2012-06-05 00:41:18 +00:00
|
|
|
### "msm jargroup delete" test
|
|
|
|
|
|
|
|
### "msm jargroup rename" test
|
|
|
|
|
|
|
|
### "msm jargroup changetarget" test
|
2012-06-04 20:41:22 +00:00
|
|
|
|
2012-06-05 00:41:18 +00:00
|
|
|
### "msm jargroup getlatest" test
|
2012-06-04 20:41:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Perform tests
|
|
|
|
source shunit2
|