mirror of
https://github.com/msmhq/msm.git
synced 2024-08-30 18:12:35 +00:00
Added tests for offline server commands up to <server> jar
.
This commit is contained in:
parent
d48bd7c577
commit
fe8687f546
209
test.sh
209
test.sh
@ -1,5 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
USERNAME="minecraft"
|
||||||
DIR="${MSM_DIR:-$(pwd)}"
|
DIR="${MSM_DIR:-$(pwd)}"
|
||||||
DEFUALT_CONF="${MSM_DEFAULT_CONF:-${DIR}/msm.conf}"
|
DEFUALT_CONF="${MSM_DEFAULT_CONF:-${DIR}/msm.conf}"
|
||||||
TESTS_DIR="${MSM_TESTS_DIR:-${DIR}/tests}"
|
TESTS_DIR="${MSM_TESTS_DIR:-${DIR}/tests}"
|
||||||
@ -31,7 +32,7 @@ setUp() {
|
|||||||
mkdir -p "$TMP_DIR" && chown "$USERNAME" "$TMP_DIR"
|
mkdir -p "$TMP_DIR" && chown "$USERNAME" "$TMP_DIR"
|
||||||
cp "$DEFUALT_CONF" "$MSM_CONF" && chown "$USERNAME" "$MSM_CONF"
|
cp "$DEFUALT_CONF" "$MSM_CONF" && chown "$USERNAME" "$MSM_CONF"
|
||||||
|
|
||||||
# Overwrite the directories to use for testing purposes
|
# Overwrite variables to use for testing purposes
|
||||||
echo "" >> "$MSM_CONF"
|
echo "" >> "$MSM_CONF"
|
||||||
echo "# Auto appended by test script:" >> "$MSM_CONF"
|
echo "# Auto appended by test script:" >> "$MSM_CONF"
|
||||||
echo "SERVER_STORAGE_PATH=\"${TMP_DIR}/servers\"" >> "$MSM_CONF"
|
echo "SERVER_STORAGE_PATH=\"${TMP_DIR}/servers\"" >> "$MSM_CONF"
|
||||||
@ -41,8 +42,11 @@ setUp() {
|
|||||||
echo "LOG_ARCHIVE_PATH=\"${TMP_DIR}/archives/logs\"" >> "$MSM_CONF"
|
echo "LOG_ARCHIVE_PATH=\"${TMP_DIR}/archives/logs\"" >> "$MSM_CONF"
|
||||||
echo "BACKUP_ARCHIVE_PATH=\"${TMP_DIR}/archives/backups\"" >> "$MSM_CONF"
|
echo "BACKUP_ARCHIVE_PATH=\"${TMP_DIR}/archives/backups\"" >> "$MSM_CONF"
|
||||||
echo "DEBUG=\"true\"" >> "$MSM_CONF"
|
echo "DEBUG=\"true\"" >> "$MSM_CONF"
|
||||||
|
echo "DEFAULT_USERNAME=\"${USERNAME}\"" >> "$MSM_CONF"
|
||||||
echo "DEFAULT_SCREEN_NAME=\"msmtest-{SERVER_NAME}\"" >> "$MSM_CONF"
|
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"
|
echo "DEFAULT_INVOCATION=\"java -Xmx${TEST_RAM}M -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalPacing -XX:+AggressiveOpts -jar {JAR} nogui\"" >> "$MSM_CONF"
|
||||||
|
|
||||||
|
source $SCRIPT
|
||||||
|
|
||||||
# Variables accessible by all tests, which are set by the stdall, stderr,
|
# Variables accessible by all tests, which are set by the stdall, stderr,
|
||||||
# stdout and quiet utility functions.
|
# stdout and quiet utility functions.
|
||||||
@ -54,6 +58,8 @@ tearDown() {
|
|||||||
# Clear the variables used in test functions
|
# Clear the variables used in test functions
|
||||||
unset EXIT_CODE
|
unset EXIT_CODE
|
||||||
unset OUTPUT
|
unset OUTPUT
|
||||||
|
|
||||||
|
manager_dirty_all
|
||||||
|
|
||||||
# Remove the temporary testing directory
|
# Remove the temporary testing directory
|
||||||
if [ -d "${TMP_DIR}" ]; then
|
if [ -d "${TMP_DIR}" ]; then
|
||||||
@ -136,31 +142,35 @@ test_listing_no_servers() {
|
|||||||
### "msm server create" tests
|
### "msm server create" tests
|
||||||
|
|
||||||
test_reserved_server_names() {
|
test_reserved_server_names() {
|
||||||
|
manager_property SERVER_STORAGE_PATH
|
||||||
for name in "start" "stop" "restart" "server" "version" "jargroup" "all"; do
|
for name in "start" "stop" "restart" "server" "version" "jargroup" "all"; do
|
||||||
expect_stderr $SCRIPT server create $name
|
expect_stderr $SCRIPT server create $name
|
||||||
assertEquals "Incorrect exit code when creating server name \"$name\"." $EX_INVALID_ARGUMENT $EXIT_CODE
|
assertEquals "Incorrect exit code when creating server name \"$name\"." $EX_INVALID_ARGUMENT $EXIT_CODE
|
||||||
assertFalse "Server \"$name\" directory was created when it should not have been." "[ -d \"$SERVER_STORAGE_PATH/$name\" ]"
|
assertFalse "Server \"$name\" directory was created when it should not have been." "[ -d \"$SETTINGS_SERVER_STORAGE_PATH/$name\" ]"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
test_common_invalid_server_names() {
|
test_common_invalid_server_names() {
|
||||||
|
manager_property SERVER_STORAGE_PATH
|
||||||
expect_stderr $SCRIPT server create "name with spaces"
|
expect_stderr $SCRIPT server create "name with spaces"
|
||||||
assertEquals "Incorrect exit code when creating server name \"name with spaces\"." $EX_INVALID_ARGUMENT $EXIT_CODE
|
assertEquals "Incorrect exit code when creating server name \"name with spaces\"." $EX_INVALID_ARGUMENT $EXIT_CODE
|
||||||
assertFalse "Server \"name with spaces\" directory was created when it should not have been." "[ -d \"$SERVER_STORAGE_PATH/name with spaces\" ]"
|
assertFalse "Server \"name with spaces\" directory was created when it should not have been." "[ -d \"$SETTINGS_SERVER_STORAGE_PATH/name with spaces\" ]"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_valid_edge_case_server_names() {
|
test_valid_edge_case_server_names() {
|
||||||
|
manager_property SERVER_STORAGE_PATH
|
||||||
for name in "serverstart" "CapitalLetters" "0987654321" "name-with-dashes" "name_with_underscores" "Combination-of_different1Things2"; do
|
for name in "serverstart" "CapitalLetters" "0987654321" "name-with-dashes" "name_with_underscores" "Combination-of_different1Things2"; do
|
||||||
expect_stderr_empty $SCRIPT server create $name
|
expect_stderr_empty $SCRIPT server create $name
|
||||||
assertEquals "Incorrect exit code when creating server name \"$name\"." $EX_OK $EXIT_CODE
|
assertEquals "Incorrect exit code when creating server name \"$name\"." $EX_OK $EXIT_CODE
|
||||||
assertTrue "Server \"$name\" directory was NOT created when it should have been." "[ -d \"$SERVER_STORAGE_PATH/$name\" ]"
|
assertTrue "Server \"$name\" directory was NOT created when it should have been." "[ -d \"$SETTINGS_SERVER_STORAGE_PATH/$name\" ]"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
test_creating_server_without_any_jargroups() {
|
test_creating_server_without_any_jargroups() {
|
||||||
|
manager_property SERVER_STORAGE_PATH
|
||||||
expect_stderr_empty $SCRIPT server create example
|
expect_stderr_empty $SCRIPT server create example
|
||||||
assertEquals "Incorrect exit code." $EX_OK $EXIT_CODE
|
assertEquals "Incorrect exit code." $EX_OK $EXIT_CODE
|
||||||
assertTrue "Server was not created." "[ -d \"$SERVER_STORAGE_PATH/example\" ]"
|
assertTrue "Server was not created." "[ -d \"$SETTINGS_SERVER_STORAGE_PATH/example\" ]"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Assumes: test_create_server_without_any_jargroups
|
# Assumes: test_create_server_without_any_jargroups
|
||||||
@ -181,9 +191,18 @@ test_creating_server_with_jar_groups() {
|
|||||||
# Create a new server that will use the "minecraft" jar group.
|
# Create a new server that will use the "minecraft" jar group.
|
||||||
expect_stderr_empty $SCRIPT server create example
|
expect_stderr_empty $SCRIPT server create example
|
||||||
|
|
||||||
|
# Script must be sourced again to recognise the new server
|
||||||
|
source $SCRIPT
|
||||||
|
|
||||||
|
manager_property SERVER_STORAGE_PATH
|
||||||
|
server_get_id "example"
|
||||||
|
local sid="$RETURN"
|
||||||
|
server_property "$sid" JAR_PATH
|
||||||
|
server_property "$sid" PATH
|
||||||
|
|
||||||
assertEquals "Incorrect exit code." $EX_OK $EXIT_CODE
|
assertEquals "Incorrect exit code." $EX_OK $EXIT_CODE
|
||||||
assertTrue "Server direcotry was not created." "[ -d \"$SERVER_STORAGE_PATH/example\" ]"
|
assertTrue "Server direcotry was not created." "[ -d \"${SERVER_PATH[$sid]}\" ]"
|
||||||
assertTrue "Server jar ($SERVER_STORAGE_PATH/example/$DEFAULT_JAR_PATH) was not linked." "[ -f \"$SERVER_STORAGE_PATH/example/$DEFAULT_JAR_PATH\" ]"
|
assertTrue "Server jar (${SERVER_JAR_PATH[$sid]}) was not linked." "[ -f \"${SERVER_JAR_PATH[$sid]}\" ]"
|
||||||
}
|
}
|
||||||
|
|
||||||
### "msm server delete" tests
|
### "msm server delete" tests
|
||||||
@ -213,13 +232,182 @@ test_renaming_server_that_does_not_exist() {
|
|||||||
test_renaming_server_that_exists_and_is_stopped() {
|
test_renaming_server_that_exists_and_is_stopped() {
|
||||||
quiet $SCRIPT server create example
|
quiet $SCRIPT server create example
|
||||||
expect_stderr_empty $SCRIPT server rename example example_new_name
|
expect_stderr_empty $SCRIPT server rename example example_new_name
|
||||||
|
|
||||||
|
manager_property SERVER_STORAGE_PATH
|
||||||
|
|
||||||
assertEquals "Incorrect exit code." $EX_OK $EXIT_CODE
|
assertEquals "Incorrect exit code." $EX_OK $EXIT_CODE
|
||||||
assertFalse "Original server name directory still exists." "[ -d \"$SERVER_STORAGE_PATH/example\" ]"
|
assertFalse "Original server name directory still exists." "[ -d \"$SETTINGS_SERVER_STORAGE_PATH/example\" ]"
|
||||||
assertTrue "New server name directory was not created." "[ -d \"$SERVER_STORAGE_PATH/example_new_name\" ]"
|
assertTrue "New server name directory was not created." "[ -d \"$SETTINGS_SERVER_STORAGE_PATH/example_new_name\" ]"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Stopped Server Tests
|
||||||
|
# --------------------
|
||||||
|
|
||||||
|
### "msm <server> stop" tests
|
||||||
|
|
||||||
|
test_stopped_server_stop() {
|
||||||
|
quiet $SCRIPT server create stoppedserver
|
||||||
|
expect_stdout $SCRIPT stoppedserver stop
|
||||||
|
assertEquals "Incorrect exit code." $EX_OK $EXIT_CODE
|
||||||
|
}
|
||||||
|
|
||||||
|
### "msm <server> status" tests
|
||||||
|
|
||||||
|
test_stopped_server_status() {
|
||||||
|
quiet $SCRIPT server create stoppedserver
|
||||||
|
expect_stdout $SCRIPT stoppedserver status
|
||||||
|
assertEquals "Incorrect exit code." $EX_OK $EXIT_CODE
|
||||||
|
}
|
||||||
|
|
||||||
|
### "msm <server> connected" tests
|
||||||
|
|
||||||
|
test_stopped_server_connected() {
|
||||||
|
quiet $SCRIPT server create stoppedserver
|
||||||
|
expect_stdout $SCRIPT stoppedserver connected
|
||||||
|
assertEquals "Incorrect exit code." $EX_OK $EXIT_CODE
|
||||||
|
}
|
||||||
|
|
||||||
|
### "msm <server> worlds list" tests
|
||||||
|
|
||||||
|
test_stopped_server_worlds_list_none() {
|
||||||
|
quiet $SCRIPT server create stoppedserver
|
||||||
|
expect_stdout $SCRIPT stoppedserver worlds list
|
||||||
|
assertEquals "Incorrect exit code." $EX_OK $EXIT_CODE
|
||||||
|
}
|
||||||
|
|
||||||
|
### "msm <server> worlds load" tests
|
||||||
|
|
||||||
|
test_stopped_server_worlds_load_none() {
|
||||||
|
quiet $SCRIPT server create stoppedserver
|
||||||
|
expect_stdout $SCRIPT stoppedserver worlds load
|
||||||
|
assertEquals "Incorrect exit code." $EX_OK $EXIT_CODE
|
||||||
|
}
|
||||||
|
|
||||||
|
### "msm <server> worlds ram" tests
|
||||||
|
|
||||||
|
test_stopped_server_worlds_ram_name_not_found() {
|
||||||
|
quiet $SCRIPT server create stoppedserver
|
||||||
|
expect_stderr $SCRIPT stoppedserver worlds ram non_existant_world_name
|
||||||
|
assertEquals "Incorrect exit code." $EX_NAME_NOT_FOUND $EXIT_CODE
|
||||||
|
}
|
||||||
|
|
||||||
|
### "msm <server> worlds todisk" tests
|
||||||
|
|
||||||
|
test_stopped_server_worlds_todisk_none() {
|
||||||
|
quiet $SCRIPT server create stoppedserver
|
||||||
|
expect_stdout $SCRIPT stoppedserver worlds todisk
|
||||||
|
assertEquals "Incorrect exit code." $EX_OK $EXIT_CODE
|
||||||
|
}
|
||||||
|
|
||||||
|
### "msm <server> worlds backup" tests
|
||||||
|
|
||||||
|
test_stopped_server_worlds_todisk_none() {
|
||||||
|
quiet $SCRIPT server create stoppedserver
|
||||||
|
expect_stdout $SCRIPT stoppedserver worlds backup
|
||||||
|
assertEquals "Incorrect exit code." $EX_OK $EXIT_CODE
|
||||||
|
}
|
||||||
|
|
||||||
|
### "msm <server> worlds on" tests
|
||||||
|
|
||||||
|
### "msm <server> worlds off" tests
|
||||||
|
|
||||||
|
### "msm <server> logroll" tests
|
||||||
|
|
||||||
|
test_stopped_server_logroll_empty() {
|
||||||
|
quiet $SCRIPT server create stoppedserver
|
||||||
|
expect_stdout $SCRIPT stoppedserver logroll
|
||||||
|
assertEquals "Incorrect exit code." $EX_OK $EXIT_CODE
|
||||||
|
}
|
||||||
|
|
||||||
|
### "msm <server> backup" tests
|
||||||
|
|
||||||
|
test_stopped_server_backup() {
|
||||||
|
manager_property BACKUP_ARCHIVE_PATH
|
||||||
|
|
||||||
|
quiet $SCRIPT server create stoppedserver
|
||||||
|
expect_stdout $SCRIPT stoppedserver backup
|
||||||
|
assertEquals "Incorrect exit code." $EX_OK $EXIT_CODE
|
||||||
|
assertNotNull "Server backup was not created." "find '$SETTINGS_BACKUP_ARCHIVE_PATH/stoppedserver' -mindepth 1 -maxdepth 1 -type f -name '*.zip'"
|
||||||
|
}
|
||||||
|
|
||||||
|
### "msm <server> jar" tests
|
||||||
|
|
||||||
|
test_stopped_server_jar() {
|
||||||
|
quiet $SCRIPT server create stoppedserver
|
||||||
|
|
||||||
|
source $SCRIPT
|
||||||
|
|
||||||
|
server_get_id "stoppedserver"
|
||||||
|
local sid="$RETURN"
|
||||||
|
|
||||||
|
server_property "$sid" JAR_PATH
|
||||||
|
|
||||||
|
# Remove the existing jar file
|
||||||
|
rm -f "$JAR_PATH"
|
||||||
|
|
||||||
|
# Create new jargroup
|
||||||
|
quiet $SCRIPT jargroup create newgroup "https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft_server.jar"
|
||||||
|
|
||||||
|
# Assign jargroup's latest jar to server
|
||||||
|
expect_stdout $SCRIPT stoppedserver jar newgroup
|
||||||
|
|
||||||
|
assertEquals "Incorrect exit code." $EX_OK $EXIT_CODE
|
||||||
|
assertTrue "Server jar (${SERVER_JAR_PATH[$sid]}) was not linked." "[ -f \"${SERVER_JAR_PATH[$sid]}\" ]"
|
||||||
|
}
|
||||||
|
|
||||||
|
### "msm <server> whitelist on" tests
|
||||||
|
|
||||||
|
### "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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Individual Server Tests
|
# Individual Server Tests
|
||||||
# -----------------------
|
# -----------------------
|
||||||
|
|
||||||
@ -326,10 +514,11 @@ test_common_invalid_jargroups_names() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
test_valid_edge_case_jargroup_names() {
|
test_valid_edge_case_jargroup_names() {
|
||||||
|
manager_property JAR_STORAGE_PATH
|
||||||
for name in "serverstart" "CapitalLetters" "0987654321" "name-with-dashes" "name_with_underscores" "Combination-of_different1Things2"; do
|
for name in "serverstart" "CapitalLetters" "0987654321" "name-with-dashes" "name_with_underscores" "Combination-of_different1Things2"; do
|
||||||
expect_stderr_empty $SCRIPT jargroup create $name https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft_server.jar
|
expect_stderr_empty $SCRIPT jargroup create $name https://s3.amazonaws.com/MinecraftDownload/launcher/minecraft_server.jar
|
||||||
assertEquals "Incorrect exit code when creating jar group name \"$name\"." $EX_OK $EXIT_CODE
|
assertEquals "Incorrect exit code when creating jar group name \"$name\"." $EX_OK $EXIT_CODE
|
||||||
assertTrue "Jar group \"$name\" directory was NOT created when it should have been." "[ -d \"$JAR_STORAGE_PATH/$name\" ]"
|
assertTrue "Jar group \"$name\" directory was NOT created when it should have been." "[ -d \"$SETTINGS_JAR_STORAGE_PATH/$name\" ]"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user