From 67728be8022808a1887347ccbbd8dea5ed140b92 Mon Sep 17 00:00:00 2001 From: John Dean Date: Thu, 8 Jun 2017 13:21:07 -0500 Subject: [PATCH 01/28] Update default configuration value for PAUSE_WHEN_EMPTY (#82) --- docs/configuration.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index f33cfcc..ad99192 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -150,8 +150,8 @@ Enables/disables the possibility to kick players via voting. **PAUSE_WHEN_EMPTY** Enables/disables pausing of the world when no player is connected. -- true *[default]* -- false +- true +- false *[default]* **STEAM_AUTHENTICATION_PORT** Sets the authentication port-number for Steam. Generally it's not needed to change this. From 523d17276219a2b3e6c7fe0bd1640e5d8ca383cb Mon Sep 17 00:00:00 2001 From: Thomas Deinhamer Date: Thu, 6 Jul 2017 10:56:28 +0200 Subject: [PATCH 02/28] Replace worldgenoverride.lua with leveldataoverride.lua (#85) --- build/static/boot/world.sh | 16 ++++++++-------- docs/configuration.md | 6 +++--- docs/examples/README.md | 2 +- docs/examples/world/README.md | 2 +- docs/examples/world/leveldataoverride.lua | 4 ++++ docs/examples/world/start.sh | 2 +- docs/examples/world/world.env | 2 +- docs/examples/world/worldgenoverride.lua | 5 ----- test/boot-world/run.sh | 16 ++++++++-------- 9 files changed, 27 insertions(+), 28 deletions(-) create mode 100644 docs/examples/world/leveldataoverride.lua delete mode 100644 docs/examples/world/worldgenoverride.lua diff --git a/build/static/boot/world.sh b/build/static/boot/world.sh index f7db590..27fc077 100755 --- a/build/static/boot/world.sh +++ b/build/static/boot/world.sh @@ -1,26 +1,26 @@ #!/usr/bin/env bash -file_world_override="$CLUSTER_PATH/$SHARD_NAME/worldgenoverride.lua" +file_leveldata_override="$CLUSTER_PATH/$SHARD_NAME/leveldataoverride.lua" -if [ -f $file_world_override ]; then +if [ -f $file_leveldata_override ]; then exit 0 fi -if [ -n "$WORLD_OVERRIDES" ]; then - echo "$WORLD_OVERRIDES" > $file_world_override +if [ -n "$LEVELDATA_OVERRIDES" ]; then + echo "$LEVELDATA_OVERRIDES" > $file_leveldata_override elif [ -n "$WORLD_PRESET" ]; then source "`dirname "$0"`/functions.sh" validate_option "WORLD_PRESET" SURVIVAL_TOGETHER SURVIVAL_TOGETHER_CLASSIC SURVIVAL_DEFAULT_PLUS COMPLETE_DARKNESS DST_CAVE - cat <<- EOF > $file_world_override + cat <<- EOF > $file_leveldata_override return { - override_enabled = true, - preset = "$WORLD_PRESET", + id = "$WORLD_PRESET", + version = 3, } EOF fi -if [ -f $file_world_override ]; then +if [ -f $file_leveldata_override ]; then chown $STEAM_USER:$STEAM_USER $file_world_override fi diff --git a/docs/configuration.md b/docs/configuration.md index ad99192..8c11476 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -227,9 +227,9 @@ Defines some pre-configured world settings for the server. - COMPLETE_DARKNESS - DST_CAVE -**WORLD_OVERRIDES** -Sets the overrides-configuration for world generation. Basically it's just the content for the -`worldgenoverride.lua` file. As this value can be pretty large it's recommended to put the +**LEVELDATA_OVERRIDES** +Sets the overrides-configuration for level-data. Basically it's just the content for the +`leveldataoverride.lua` file. As this value can be pretty large it's recommended to put the configuration into a separate file and read it into the variable beforehand. When this is set `WORLD_PRESET` has no effect. - *string* diff --git a/docs/examples/README.md b/docs/examples/README.md index e7469b9..a0c8f9a 100644 --- a/docs/examples/README.md +++ b/docs/examples/README.md @@ -31,7 +31,7 @@ connected to each other via sinkholes and stairs in each world. ### [World Generation][setup-world] The *World Generation* configuration defines custom world generation rules. Configuration -is loaded from the `worldgenoverride.yml` file and passed to the start command. +is loaded from the `leveldataoverride.yml` file and passed to the start command. [dsta-servers]: https://github.com/dst-academy/deployment-servers [setup-basic]: ./basic/ diff --git a/docs/examples/world/README.md b/docs/examples/world/README.md index b2805c8..8b7ccd8 100644 --- a/docs/examples/world/README.md +++ b/docs/examples/world/README.md @@ -3,4 +3,4 @@ Starts a single server with customized world generation. You can pass a custom world generation configuration by -setting the `WORLD_OVERRIDES` environment variable. +setting the `LEVELDATA_OVERRIDES` environment variable. diff --git a/docs/examples/world/leveldataoverride.lua b/docs/examples/world/leveldataoverride.lua new file mode 100644 index 0000000..686991e --- /dev/null +++ b/docs/examples/world/leveldataoverride.lua @@ -0,0 +1,4 @@ +return { + id="SURVIVAL_DEFAULT_PLUS", + version=3, +} diff --git a/docs/examples/world/start.sh b/docs/examples/world/start.sh index 544637f..fbc39cc 100644 --- a/docs/examples/world/start.sh +++ b/docs/examples/world/start.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash -export WORLD_OVERRIDES=$(< worldgenoverride.lua) +export LEVELDATA_OVERRIDES=$(< leveldataoverride.lua) docker-compose up -d diff --git a/docs/examples/world/world.env b/docs/examples/world/world.env index 43ba605..20ffb54 100644 --- a/docs/examples/world/world.env +++ b/docs/examples/world/world.env @@ -5,4 +5,4 @@ TOKEN=your-server-token NAME=World # WORLD -WORLD_OVERRIDES +LEVELDATA_OVERRIDES diff --git a/docs/examples/world/worldgenoverride.lua b/docs/examples/world/worldgenoverride.lua deleted file mode 100644 index 5a8ace3..0000000 --- a/docs/examples/world/worldgenoverride.lua +++ /dev/null @@ -1,5 +0,0 @@ -return { - override_enabled = true, - misc = { season="shortboth", world_size="huge", season_start="summer" }, - resources = { flint="always", grass="always", sapling="always", trees="always" }, -} diff --git a/test/boot-world/run.sh b/test/boot-world/run.sh index 8cfcf6d..ea9a2c5 100755 --- a/test/boot-world/run.sh +++ b/test/boot-world/run.sh @@ -15,30 +15,30 @@ file2=`mktemp` echo "foo" > $file1 cat <<- EOF > $file2 return { - override_enabled = true, - preset = "bar", + id = "bar", + version = 3, } EOF -container_id=`docker run -d -e WORLD_OVERRIDES="foo" $1 dst-server start --update=none || exit 1` +container_id=`docker run -d -e LEVELDATA_OVERRIDES="foo" $1 dst-server start --update=none || exit 1` sleep 5 -docker cp $container_id:/var/lib/dsta/cluster/shard/worldgenoverride.lua $aux || exit 1 +docker cp $container_id:/var/lib/dsta/cluster/shard/leveldataoverride.lua $aux || exit 1 diff $file1 $aux || exit 1 docker rm -fv $container_id > /dev/null -container_id=`docker run -d -e WORLD_OVERRIDES="foo" -e WORLD_PRESET="bar" $1 dst-server start --update=none || exit 1` +container_id=`docker run -d -e LEVELDATA_OVERRIDES="foo" -e WORLD_PRESET="bar" $1 dst-server start --update=none || exit 1` sleep 5 -docker cp $container_id:/var/lib/dsta/cluster/shard/worldgenoverride.lua $aux || exit 1 +docker cp $container_id:/var/lib/dsta/cluster/shard/leveldataoverride.lua $aux || exit 1 diff $file1 $aux || exit 1 docker rm -fv $container_id > /dev/null container_id=`docker run -d -e WORLD_PRESET="bar" $1 dst-server start --update=none || exit 1` sleep 5 -docker cp $container_id:/var/lib/dsta/cluster/shard/worldgenoverride.lua $aux || exit 1 +docker cp $container_id:/var/lib/dsta/cluster/shard/leveldataoverride.lua $aux || exit 1 diff $file2 $aux || exit 1 docker rm -fv $container_id > /dev/null container_id=`docker run -d $1 dst-server start --update=none || exit 1` sleep 5 -docker cp $container_id:/var/lib/dsta/cluster/shard/worldgenoverride.lua $aux 2> /dev/null && exit 1 +docker cp $container_id:/var/lib/dsta/cluster/shard/leveldataoverride.lua $aux 2> /dev/null && exit 1 docker rm -fv $container_id > /dev/null From 1e74af04fae986fdc56491d78872b84378dc8f42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brais=20Gab=C3=ADn?= Date: Sat, 15 Jul 2017 12:09:17 +0200 Subject: [PATCH 03/28] Fix shard example to workaround #51 --- docs/examples/shard/docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/examples/shard/docker-compose.yml b/docs/examples/shard/docker-compose.yml index f78b853..62730aa 100644 --- a/docs/examples/shard/docker-compose.yml +++ b/docs/examples/shard/docker-compose.yml @@ -11,7 +11,7 @@ services: ports: - "10999:10999/udp" volumes: - - ./world:/var/lib/dsta/cluster + - ./overworld:/var/lib/dsta/cluster underworld: image: dstacademy/dontstarvetogether container_name: underworld @@ -25,4 +25,4 @@ services: links: - overworld volumes: - - ./world:/var/lib/dsta/cluster + - ./underworld:/var/lib/dsta/cluster From 505607ea500c555ee5a46a879387ca0e4b6f15f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brais=20Gab=C3=ADn?= Date: Sat, 15 Jul 2017 12:27:44 +0200 Subject: [PATCH 04/28] Fix console tests (#93) :green_heart: :alien: --- test/attach-console/run.sh | 2 +- test/console/run.sh | 4 ++-- test/dsta-console/run.sh | 26 +++++++++++++------------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/test/attach-console/run.sh b/test/attach-console/run.sh index 575f499..afd38e2 100755 --- a/test/attach-console/run.sh +++ b/test/attach-console/run.sh @@ -26,4 +26,4 @@ timeout --kill-after 1 20 docker wait $container_id >/dev/null || exit 1 docker cp $container_id:/var/lib/dsta/cluster/shard/server_log.txt $file1 docker rm -fv $container_id >/dev/null -grep -Fq "ConsoleInput: \"c_shutdown(true)\"" $file1 || exit 1 +grep -Fq "RemoteCommandInput: \"c_shutdown(true)\"" $file1 || exit 1 diff --git a/test/console/run.sh b/test/console/run.sh index 39577a4..6703e78 100755 --- a/test/console/run.sh +++ b/test/console/run.sh @@ -15,6 +15,6 @@ docker cp console/commands.sh $container_id:/ docker exec $container_id /commands.sh || exit 1 sleep 20 docker cp $container_id:/var/lib/dsta/cluster/shard/server_log.txt $file1 -grep -Fq "ConsoleInput: \"foo\"" $file1 || exit 1 -grep -Fq "ConsoleInput: \"bar\"" $file1 || exit 1 +grep -Fq "RemoteCommandInput: \"foo\"" $file1 || exit 1 +grep -Fq "RemoteCommandInput: \"bar\"" $file1 || exit 1 docker rm -fv $container_id > /dev/null diff --git a/test/dsta-console/run.sh b/test/dsta-console/run.sh index ae374a4..0cc7ed4 100755 --- a/test/dsta-console/run.sh +++ b/test/dsta-console/run.sh @@ -20,21 +20,21 @@ sleep 20 docker cp $container_id:/var/lib/dsta/cluster/shard/server_log.txt $file1 docker rm -fv $container_id > /dev/null -grep -Fq "ConsoleInput: \"foo 1\"" $file1 || exit 1 -grep -Fq "ConsoleInput: \"bar1\"" $file1 || exit 1 +grep -Fq "RemoteCommandInput: \"foo 1\"" $file1 || exit 1 +grep -Fq "RemoteCommandInput: \"bar1\"" $file1 || exit 1 -grep -Fq "ConsoleInput: \"foo 2\"" $file1 || exit 1 -grep -Fq "ConsoleInput: \"bar2\"" $file1 || exit 1 +grep -Fq "RemoteCommandInput: \"foo 2\"" $file1 || exit 1 +grep -Fq "RemoteCommandInput: \"bar2\"" $file1 || exit 1 -grep -Fq "ConsoleInput: \"asdf\"" $file1 || exit 1 +grep -Fq "RemoteCommandInput: \"asdf\"" $file1 || exit 1 -grep -Fq "ConsoleInput: \"abcde\"" $file1 || exit 1 -grep -Fq "ConsoleInput: \"foo 3\"" $file1 || exit 1 -grep -Fq "ConsoleInput: \"bar3\"" $file1 || exit 1 -grep -Fq "ConsoleInput: \"aaaaa\"" $file1 || exit 1 +grep -Fq "RemoteCommandInput: \"abcde\"" $file1 || exit 1 +grep -Fq "RemoteCommandInput: \"foo 3\"" $file1 || exit 1 +grep -Fq "RemoteCommandInput: \"bar3\"" $file1 || exit 1 +grep -Fq "RemoteCommandInput: \"aaaaa\"" $file1 || exit 1 -grep -Fq "ConsoleInput: \"xyz as\"" $file1 || exit 1 -grep -Fq "ConsoleInput: \"1234\"" $file1 || exit 1 -grep -Fq "ConsoleInput: \"foo 4\"" $file1 && exit 1 -grep -Fq "ConsoleInput: \"bar4\"" $file1 && exit 1 +grep -Fq "RemoteCommandInput: \"xyz as\"" $file1 || exit 1 +grep -Fq "RemoteCommandInput: \"1234\"" $file1 || exit 1 +grep -Fq "RemoteCommandInput: \"foo 4\"" $file1 && exit 1 +grep -Fq "RemoteCommandInput: \"bar4\"" $file1 && exit 1 exit 0 From 8c55df7cfa722e761f2d463848bbdafc46937158 Mon Sep 17 00:00:00 2001 From: Thomas Deinhamer Date: Sat, 15 Jul 2017 14:54:08 +0200 Subject: [PATCH 05/28] Install latest Docker version on Travis CI environment (#96) --- .travis.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.travis.yml b/.travis.yml index 209027d..bc9ff1a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,12 @@ services: env: - DOCKER_IMAGE_NAME=dstacademy/dontstarvetogether +before_install: + - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - + - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" + - sudo apt-get update + - sudo apt-get -y install docker-ce + script: - docker build -t $DOCKER_IMAGE_NAME ./build - ./test/run.sh From c075aa6e6b0b0f4d4f7540c570b15202cad74ac7 Mon Sep 17 00:00:00 2001 From: Thomas Deinhamer Date: Sat, 15 Jul 2017 15:04:32 +0200 Subject: [PATCH 06/28] Add HEALTHCHECK configuration (#90) --- build/Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build/Dockerfile b/build/Dockerfile index 9530394..3508876 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -66,6 +66,9 @@ RUN set -x \ # Copy entrypoint script. COPY /docker-entrypoint.sh / +# Set up healthcheck. +HEALTHCHECK --interval=5m --start-period=15m --timeout=30s --retries=3 CMD dst-server version --check + # Expose default server port. EXPOSE $SERVER_PORT/udp From 299be73d5884f05c122c3b68223274797ce6ffe4 Mon Sep 17 00:00:00 2001 From: Thomas Deinhamer Date: Sat, 15 Jul 2017 15:30:09 +0200 Subject: [PATCH 07/28] Upgrade to version 0.3 of the steamcmd base-image (#87) --- build/Dockerfile | 2 +- test/close-cleanly/run.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build/Dockerfile b/build/Dockerfile index 3508876..e7c561b 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -1,4 +1,4 @@ -FROM dstacademy/steamcmd:0.2.1 +FROM dstacademy/steamcmd:0.3 MAINTAINER DST Academy # Set build arguments. diff --git a/test/close-cleanly/run.sh b/test/close-cleanly/run.sh index 14ac8aa..98406c0 100755 --- a/test/close-cleanly/run.sh +++ b/test/close-cleanly/run.sh @@ -30,7 +30,7 @@ grep -q "Shutting down$" $file1 || exit 1 # TERM container_id=`docker run -d $1 dst-server start --update=none || exit 1` sleep 20 -docker exec $container_id kill 1 +docker exec $container_id bash -c "kill 1" timeout --kill-after 1 12 docker wait $container_id > $file1 grep -q "^0$" $file1 || exit 1 docker cp $container_id:/var/lib/dsta/cluster/shard/server_log.txt $file1 @@ -40,7 +40,7 @@ grep -q "Shutting down$" $file1 || exit 1 # INT container_id=`docker run -d $1 dst-server start --update=none || exit 1` sleep 20 -docker exec $container_id kill -SIGINT 1 +docker exec $container_id bash -c "kill -SIGINT 1" timeout --kill-after 1 12 docker wait $container_id > $file1 grep -q "^0$" $file1 || exit 1 docker cp $container_id:/var/lib/dsta/cluster/shard/server_log.txt $file1 From 7e2e9d31bc7988653cf4a2192f088867235e0d1f Mon Sep 17 00:00:00 2001 From: Thomas Deinhamer Date: Sat, 15 Jul 2017 22:41:08 +0200 Subject: [PATCH 08/28] Remove start-period from the HEALTHCHECK due to Docker version incompatibility --- build/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/Dockerfile b/build/Dockerfile index e7c561b..f919650 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -67,7 +67,7 @@ RUN set -x \ COPY /docker-entrypoint.sh / # Set up healthcheck. -HEALTHCHECK --interval=5m --start-period=15m --timeout=30s --retries=3 CMD dst-server version --check +HEALTHCHECK --interval=5m --timeout=30s --retries=3 CMD dst-server version --check # Expose default server port. EXPOSE $SERVER_PORT/udp From 3325c00fc521e135f8a2b093d5f35a05863cb470 Mon Sep 17 00:00:00 2001 From: Thomas Deinhamer Date: Mon, 17 Jul 2017 19:52:08 +0200 Subject: [PATCH 09/28] Fix WORLD_PRESET usage with the new leveldataoverride configuration (#99) --- build/static/boot/world.sh | 13 +++++++++++-- docs/configuration.md | 1 + test/boot-world/run.sh | 5 ++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/build/static/boot/world.sh b/build/static/boot/world.sh index 27fc077..a03fa2f 100755 --- a/build/static/boot/world.sh +++ b/build/static/boot/world.sh @@ -11,12 +11,21 @@ if [ -n "$LEVELDATA_OVERRIDES" ]; then elif [ -n "$WORLD_PRESET" ]; then source "`dirname "$0"`/functions.sh" - validate_option "WORLD_PRESET" SURVIVAL_TOGETHER SURVIVAL_TOGETHER_CLASSIC SURVIVAL_DEFAULT_PLUS COMPLETE_DARKNESS DST_CAVE + validate_option "WORLD_PRESET" SURVIVAL_TOGETHER SURVIVAL_TOGETHER_CLASSIC SURVIVAL_DEFAULT_PLUS COMPLETE_DARKNESS DST_CAVE DST_CAVE_PLUS + + if ["$WORLD_PRESET" == "DST_CAVE"] || ["$WORLD_PRESET" == "DST_CAVE_PLUS"]; then + location="cave" + else + location="forest" + fi cat <<- EOF > $file_leveldata_override return { id = "$WORLD_PRESET", - version = 3, + location = "$location", + name="", + desc="", + overrides={}, } EOF fi diff --git a/docs/configuration.md b/docs/configuration.md index 8c11476..b2e6d44 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -226,6 +226,7 @@ Defines some pre-configured world settings for the server. - SURVIVAL_DEFAULT_PLUS - COMPLETE_DARKNESS - DST_CAVE +- DST_CAVE_PLUS **LEVELDATA_OVERRIDES** Sets the overrides-configuration for level-data. Basically it's just the content for the diff --git a/test/boot-world/run.sh b/test/boot-world/run.sh index ea9a2c5..c5a911b 100755 --- a/test/boot-world/run.sh +++ b/test/boot-world/run.sh @@ -16,7 +16,10 @@ echo "foo" > $file1 cat <<- EOF > $file2 return { id = "bar", - version = 3, + location = "forest", + name="", + desc="", + overrides={}, } EOF From d2f35001aad520629d9bb0a27dee3bdf853391e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brais=20Gab=C3=ADn?= Date: Tue, 18 Jul 2017 22:07:25 +0200 Subject: [PATCH 10/28] Overwrite configuration files by default (#98) --- build/static/bin/start.sh | 61 ++++++++++++++++------------ build/static/boot/lists.sh | 19 ++++++--- build/static/boot/mods.sh | 11 +++-- build/static/boot/settings.sh | 32 ++++++++------- build/static/boot/token.sh | 11 ++++- build/static/boot/world.sh | 14 ++++--- build/static/doc/start.usage | 12 ++++++ test/boot-lists/run.sh | 75 ++++++++++++++++++++++++++++++----- test/boot-mods/run.sh | 13 +++--- test/boot-token/run.sh | 55 +++++++++++++++++++++++++ test/boot-world/run.sh | 62 ++++++++++++++++++++++++++--- test/dsta-help/run.sh | 12 ++++++ test/dsta-start/run.sh | 12 ++++++ 13 files changed, 309 insertions(+), 80 deletions(-) create mode 100755 test/boot-token/run.sh diff --git a/build/static/bin/start.sh b/build/static/bin/start.sh index 5489dfa..3302adb 100755 --- a/build/static/bin/start.sh +++ b/build/static/bin/start.sh @@ -4,31 +4,40 @@ usage(){ cat $DSTA_HOME/doc/start.usage } +update=0 if [ $# -eq 0 ]; then - update=0 + true # no-op elif [ $1 == "--help" ]; then usage exit 0 -elif [ $# -eq 1 ]; then - case $1 in - --update=all) - update=3 - ;; - --update=none) - update=0 - ;; - --update=game) - update=1 - ;; - --update=mods) - update=2 - ;; - esac -fi - -if [ -z "$update" ]; then - usage 1>&2 - exit 1 +else + while [[ $# -gt 0 ]] + do + key="$1" + case $key in + --update=all) + update=3 + ;; + --update=none) + update=0 + ;; + --update=game) + update=1 + ;; + --update=mods) + update=2 + ;; + --keep-configuration=*) + keep="${key#*=}" + keep="${keep//,/ }" + ;; + *) + usage 1>&2 + exit 1 + ;; + esac + shift + done fi if (((update & 1) != 0)); then @@ -39,10 +48,10 @@ if (((update & 2) == 0)); then flag="-skip_update_server_mods" fi -$DSTA_HOME/boot/token.sh -$DSTA_HOME/boot/settings.sh -$DSTA_HOME/boot/lists.sh -$DSTA_HOME/boot/world.sh -$DSTA_HOME/boot/mods.sh +$DSTA_HOME/boot/token.sh "$keep" +$DSTA_HOME/boot/settings.sh "$keep" +$DSTA_HOME/boot/lists.sh "$keep" +$DSTA_HOME/boot/world.sh "$keep" +$DSTA_HOME/boot/mods.sh "$keep" exec dontstarve_dedicated_server_nullrenderer $flag diff --git a/build/static/boot/lists.sh b/build/static/boot/lists.sh index 15d895c..c8fd7d1 100755 --- a/build/static/boot/lists.sh +++ b/build/static/boot/lists.sh @@ -1,19 +1,28 @@ #!/usr/bin/env bash +source "`dirname "$0"`/functions.sh" + create_list(){ list=$1 file=$2 - if [ -n "$list" ] && [ ! -f $file ]; then - echo $list | tr , '\n' > $file + must_keep=$3 + if [[ -f $file ]] && [[ "$must_keep" == "0" ]] ; then + return + fi + + rm -f $file + + if [[ -n "$list" ]] ; then + echo $list | tr , '\n' >$file chown $STEAM_USER:$STEAM_USER $file fi } # Create the adminlist.txt file. -create_list "$ADMINLIST" "$CLUSTER_PATH/adminlist.txt" +create_list "$ADMINLIST" "$CLUSTER_PATH/adminlist.txt" `containsElement adminlist $@ && echo 0 || echo 1` # Create the whitelist.txt file. -create_list "$WHITELIST" "$CLUSTER_PATH/whitelist.txt" +create_list "$WHITELIST" "$CLUSTER_PATH/whitelist.txt" `containsElement whitelist $@ && echo 0 || echo 1` # Create the blocklist.txt file. -create_list "$BLOCKLIST" "$CLUSTER_PATH/blocklist.txt" +create_list "$BLOCKLIST" "$CLUSTER_PATH/blocklist.txt" `containsElement blocklist $@ && echo 0 || echo 1` diff --git a/build/static/boot/mods.sh b/build/static/boot/mods.sh index 2b7fcfe..59ea718 100755 --- a/build/static/boot/mods.sh +++ b/build/static/boot/mods.sh @@ -6,11 +6,14 @@ file_mods_overrides="$CLUSTER_PATH/$SHARD_NAME/modoverrides.lua" IFS="," -# Install and enable regular mods from the Steam workshop. -if [ -n "$MODS" ] && [ ! -f $file_mods_overrides ]; then - echo "" >> $file_mods_setup - echo "" >> $file_mods_setup +if [[ -f "$file_mods_overrides" ]] && containsElement "mods" $@ ; then + exit 0 +fi +rm -f $file_mods_setup $file_mods_settings $file_mods_overrides + +# Install and enable regular mods from the Steam workshop. +if [[ -n "$MODS" ]]; then for mod in $MODS; do echo "ServerModSetup(\"$mod\")" >> $file_mods_setup done diff --git a/build/static/boot/settings.sh b/build/static/boot/settings.sh index 655321e..271959b 100755 --- a/build/static/boot/settings.sh +++ b/build/static/boot/settings.sh @@ -1,20 +1,10 @@ #!/usr/bin/env bash +source "`dirname "$0"`/functions.sh" + file_cluster="$CLUSTER_PATH/cluster.ini" file_server="$CLUSTER_PATH/$SHARD_NAME/server.ini" -if [ -z "$NAME" ]; then - selectRandomLine(){ - mapfile list < $1 - echo ${list[$RANDOM % ${#list[@]}]} - } - - NAME="`selectRandomLine $DSTA_HOME/data/adjectives.txt` `selectRandomLine $DSTA_HOME/data/names.txt`" - echo "'$NAME' has been set as the cluster's name." -fi - -source "`dirname "$0"`/functions.sh" - validate_option "LANGUAGE" \ brazilian bulgarian czech danish dutch english finnish french german \ greek hungarian italian japanese korean norwegian polish portuguese \ @@ -44,7 +34,19 @@ validate_bool "SHARD_ENABLE" validate_bool "SHARD_IS_MASTER" validate_port "SHARD_MASTER_PORT" -if [[ ! -f $file_cluster ]]; then +if [[ -f "$file_cluster" ]] && containsElement "cluster" $@ ; then + true # no-op +else + if [ -z "$NAME" ]; then + selectRandomLine(){ + mapfile list < $1 + echo ${list[$RANDOM % ${#list[@]}]} + } + + NAME="`selectRandomLine $DSTA_HOME/data/adjectives.txt` `selectRandomLine $DSTA_HOME/data/names.txt`" + echo "'$NAME' has been set as the cluster's name." + fi + exec 4>&1 1>$file_cluster echo "[NETWORK]" @@ -96,7 +98,9 @@ if [[ ! -f $file_cluster ]]; then chown $STEAM_USER:$STEAM_USER $file_cluster fi -if [[ ! -f $file_server ]]; then +if [[ -f "$file_server" ]] && containsElement "server" $@ ; then + true # no-op +else exec 4>&1 1>$file_server echo "[NETWORK]" diff --git a/build/static/boot/token.sh b/build/static/boot/token.sh index 23a8a9f..0e3d769 100755 --- a/build/static/boot/token.sh +++ b/build/static/boot/token.sh @@ -1,9 +1,16 @@ #!/usr/bin/env bash +source "`dirname "$0"`/functions.sh" + file_token="$CLUSTER_PATH/cluster_token.txt" -if [[ -n "$TOKEN" ]] && [[ ! -f "$file_token" ]]; then - echo "$TOKEN" > $file_token +if [[ -f "$file_token" ]] && containsElement "token" $@ ; then + exit 0 +fi +if [[ -n "$TOKEN" ]] ; then + printf "$TOKEN" > $file_token chown $STEAM_USER:$STEAM_USER $file_token +else + rm -f $file_token fi diff --git a/build/static/boot/world.sh b/build/static/boot/world.sh index a03fa2f..51e3151 100755 --- a/build/static/boot/world.sh +++ b/build/static/boot/world.sh @@ -1,16 +1,18 @@ #!/usr/bin/env bash +source "`dirname "$0"`/functions.sh" + file_leveldata_override="$CLUSTER_PATH/$SHARD_NAME/leveldataoverride.lua" -if [ -f $file_leveldata_override ]; then +if [[ -f "$file_leveldata_override" ]] && containsElement "world" $@ ; then exit 0 fi -if [ -n "$LEVELDATA_OVERRIDES" ]; then - echo "$LEVELDATA_OVERRIDES" > $file_leveldata_override -elif [ -n "$WORLD_PRESET" ]; then - source "`dirname "$0"`/functions.sh" +rm -f $file_leveldata_override +if [[ -n "$LEVELDATA_OVERRIDES" ]]; then + echo "$LEVELDATA_OVERRIDES" > $file_leveldata_override +elif [[ -n "$WORLD_PRESET" ]]; then validate_option "WORLD_PRESET" SURVIVAL_TOGETHER SURVIVAL_TOGETHER_CLASSIC SURVIVAL_DEFAULT_PLUS COMPLETE_DARKNESS DST_CAVE DST_CAVE_PLUS if ["$WORLD_PRESET" == "DST_CAVE"] || ["$WORLD_PRESET" == "DST_CAVE_PLUS"]; then @@ -30,6 +32,6 @@ return { EOF fi -if [ -f $file_leveldata_override ]; then +if [[ -f $file_leveldata_override ]]; then chown $STEAM_USER:$STEAM_USER $file_world_override fi diff --git a/build/static/doc/start.usage b/build/static/doc/start.usage index c5ce53e..5b143a7 100644 --- a/build/static/doc/start.usage +++ b/build/static/doc/start.usage @@ -1,4 +1,5 @@ usage: dst-server start [--update=all|none|game|mods] + [--keep-configuration=]...>] --update=none Update nothing, just start the server. This is the default behaviour. @@ -8,3 +9,14 @@ usage: dst-server start [--update=all|none|game|mods] Update just the game (no the mods) and launch the server. --update=mods Update the mods and launch the server. + --keep-configuration + Select which configuration you don't want to overwrite. + You must provide one or more of these values separated by commas: + - token + - cluster + - server + - world + - adminlist + - blocklist + - whitelist + - mods diff --git a/test/boot-lists/run.sh b/test/boot-lists/run.sh index 3220b52..efd2d3c 100755 --- a/test/boot-lists/run.sh +++ b/test/boot-lists/run.sh @@ -1,21 +1,27 @@ #!/usr/bin/env bash clean() { - rm -f $aux $adminlist $whitelist $blocklist + rm -f $aux $adminlist $whitelist $blocklist $foo $foo2 if [ -n "`docker ps -qf id=$container_id`" ]; then - docker rm -fv $container_id > /dev/null + docker rm -fv $container_id >/dev/null fi + docker volume rm $volume >/dev/null 2>/dev/null || exit 0 } trap clean EXIT +volume="boot-lists" aux=`mktemp` adminlist=`mktemp` whitelist=`mktemp` blocklist=`mktemp` +foo=`mktemp` +foo2=`mktemp` -printf "foo\nbar\nxy_:z\n" > $adminlist -printf "foo\n" > $whitelist -printf "foo\nbar\n" > $blocklist +printf "foo\nbar\nxy_:z\n" >$adminlist +printf "foo\n" >$whitelist +printf "foo\nbar\n" >$blocklist +printf "foo\n" >$foo +printf "foo2\n" >$foo2 container_id=`docker run -d -e ADMINLIST="foo,bar,xy_:z" -e WHITELIST="foo" -e BLOCKLIST="foo,bar" $1 dst-server start --update=none || exit 1` sleep 20 @@ -29,12 +35,61 @@ docker cp $container_id:/var/lib/dsta/cluster/shard/server_log.txt $aux || exit cat $aux | grep "adminlist.txt" | grep -qF "(Success)" || exit 1 cat $aux | grep "whitelist.txt" | grep -qF "(Success)" || exit 1 cat $aux | grep "blocklist.txt" | grep -qF "(Success)" || exit 1 -docker rm -fv $container_id > /dev/null +docker rm -fv $container_id >/dev/null container_id=`docker run -d -e BLOCKLIST="foo,bar" $1 dst-server start --update=none || exit 1` -sleep 5 -docker cp $container_id:/var/lib/dsta/cluster/adminlist.txt $aux 2> /dev/null && exit 1 -docker cp $container_id:/var/lib/dsta/cluster/whitelist.txt $aux 2> /dev/null && exit 1 +sleep 2 +docker cp $container_id:/var/lib/dsta/cluster/adminlist.txt $aux 2>/dev/null && exit 1 +docker cp $container_id:/var/lib/dsta/cluster/whitelist.txt $aux 2>/dev/null && exit 1 docker cp $container_id:/var/lib/dsta/cluster/blocklist.txt $aux || exit 1 diff $blocklist $aux || exit 1 -docker rm -fv $container_id > /dev/null +docker rm -fv $container_id >/dev/null + +test_lists_with_keep(){ + docker_image=$1 + variable=$2 + keep_flag=$3 + file_name=$3 + + container_id=`docker run -d -v $volume:/var/lib/dsta/cluster -e $variable="foo" $docker_image dst-server start --update=none || exit 1` + sleep 2 + docker cp $container_id:/var/lib/dsta/cluster/$file_name.txt $aux || exit 1 + diff $foo $aux || exit 1 + docker rm -fv $container_id >/dev/null + docker volume rm $volume > /dev/null + + container_id=`docker run -d -v $volume:/var/lib/dsta/cluster -e $variable="foo2" $docker_image dst-server start --update=none --keep-configuration=$keep_flag || exit 1` + sleep 2 + docker cp $container_id:/var/lib/dsta/cluster/$file_name.txt $aux || exit 1 + diff $foo2 $aux || exit 1 + docker rm -fv $container_id >/dev/null + + container_id=`docker run -d -v $volume:/var/lib/dsta/cluster $docker_image dst-server start --update=none --keep-configuration=$keep_flag || exit 1` + sleep 2 + docker cp $container_id:/var/lib/dsta/cluster/$file_name.txt $aux || exit 1 + diff $foo2 $aux || exit 1 + docker rm -fv $container_id >/dev/null + + container_id=`docker run -d -v $volume:/var/lib/dsta/cluster -e $variable="foo" $docker_image dst-server start --update=none || exit 1` + sleep 2 + docker cp $container_id:/var/lib/dsta/cluster/$file_name.txt $aux || exit 1 + diff $foo $aux || exit 1 + docker rm -fv $container_id >/dev/null + + container_id=`docker run -d -v $volume:/var/lib/dsta/cluster -e $variable="foo2" $docker_image dst-server start --update=none --keep-configuration=$keep_flag || exit 1` + sleep 2 + docker cp $container_id:/var/lib/dsta/cluster/$file_name.txt $aux || exit 1 + diff $foo $aux || exit 1 + docker rm -fv $container_id >/dev/null + + container_id=`docker run -d -v $volume:/var/lib/dsta/cluster $docker_image dst-server start --update=none || exit 1` + sleep 2 + docker cp $container_id:/var/lib/dsta/cluster/$file_name.txt $aux 2>/dev/null && exit 1 + diff $foo $aux || exit 1 + docker rm -fv $container_id >/dev/null + docker volume rm $volume > /dev/null +} + +test_lists_with_keep $1 ADMINLIST adminlist +test_lists_with_keep $1 WHITELIST whitelist +test_lists_with_keep $1 BLOCKLIST blocklist diff --git a/test/boot-mods/run.sh b/test/boot-mods/run.sh index 8cc2db2..2cade54 100755 --- a/test/boot-mods/run.sh +++ b/test/boot-mods/run.sh @@ -18,16 +18,13 @@ modoverrides2=`mktemp` modoverrides3=`mktemp` cat <<- EOF > $mods_setup1 - ServerModSetup("foo") EOF cat <<- EOF > $mods_setup2 - ServerModSetup("foo") ServerModSetup("bar") EOF cat <<- EOF > $mods_setup3 - ServerModSetup("foo") ServerModSetup("bar") EOF @@ -45,7 +42,7 @@ EOF echo "xyz" > $modoverrides3 container_id=`docker run -d -e MODS="foo" $1 dst-server start --update=none || exit 1` -sleep 5 +sleep 2 docker cp $container_id:/opt/dst/mods/dedicated_server_mods_setup.lua $aux || exit 1 tail -n 2 $aux > $aux2 diff $mods_setup1 $aux2 || exit 1 @@ -54,7 +51,7 @@ diff $modoverrides1 $aux || exit 1 docker rm -fv $container_id > /dev/null container_id=`docker run -d -e MODS="foo,bar" $1 dst-server start --update=none || exit 1` -sleep 5 +sleep 2 docker cp $container_id:/opt/dst/mods/dedicated_server_mods_setup.lua $aux || exit 1 tail -n 3 $aux > $aux2 diff $mods_setup2 $aux2 || exit 1 @@ -63,7 +60,7 @@ diff $modoverrides2 $aux || exit 1 docker rm -fv $container_id > /dev/null container_id=`docker run -d -e MODS="foo,bar" -e MODS_OVERRIDES="xyz" $1 dst-server start --update=none || exit 1` -sleep 5 +sleep 2 docker cp $container_id:/opt/dst/mods/dedicated_server_mods_setup.lua $aux || exit 1 tail -n 3 $aux > $aux2 diff $mods_setup3 $aux2 || exit 1 @@ -72,11 +69,11 @@ diff $modoverrides3 $aux || exit 1 docker rm -fv $container_id > /dev/null container_id=`docker run -d $1 -e MODS_OVERRIDES="xyz" dst-server start --update=none || exit 1` -sleep 5 +sleep 2 docker cp $container_id:/var/lib/dsta/cluster/shard/modoverrides.lua $aux 2> /dev/null && exit 1 docker rm -fv $container_id > /dev/null container_id=`docker run -d $1 dst-server start --update=none || exit 1` -sleep 5 +sleep 2 docker cp $container_id:/var/lib/dsta/cluster/shard/modoverrides.lua $aux 2> /dev/null && exit 1 docker rm -fv $container_id > /dev/null diff --git a/test/boot-token/run.sh b/test/boot-token/run.sh new file mode 100755 index 0000000..fe34ef5 --- /dev/null +++ b/test/boot-token/run.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash + +clean() { + rm -f $aux $token1 $token2 + if [ -n "`docker ps -qf id=$container_id`" ]; then + docker rm -fv $container_id >/dev/null + fi + docker volume rm $volume >/dev/null 2>/dev/null || exit 0 +} +trap clean EXIT + +volume="boot-token" +aux=`mktemp` +token1=`mktemp` +token2=`mktemp` + +printf "token-1" > $token1 +printf "token-2" > $token2 + +container_id=`docker run -d -v $volume:/var/lib/dsta/cluster -e TOKEN="token-1" $1 dst-server start --update=none || exit 1` +sleep 2 +docker cp $container_id:/var/lib/dsta/cluster/cluster_token.txt $aux || exit 1 +diff $token1 $aux || exit 1 +docker rm -fv $container_id > /dev/null +docker volume rm $volume > /dev/null + +container_id=`docker run -d -v $volume:/var/lib/dsta/cluster -e TOKEN="token-2" $1 dst-server start --update=none --keep-configuration=token || exit 1` +sleep 2 +docker cp $container_id:/var/lib/dsta/cluster/cluster_token.txt $aux || exit 1 +diff $token2 $aux || exit 1 +docker rm -fv $container_id > /dev/null + +container_id=`docker run -d -v $volume:/var/lib/dsta/cluster $1 dst-server start --update=none --keep-configuration=token,whitelist || exit 1` +sleep 2 +docker cp $container_id:/var/lib/dsta/cluster/cluster_token.txt $aux || exit 1 +diff $token2 $aux || exit 1 +docker rm -fv $container_id > /dev/null # No remove volume + +container_id=`docker run -d -v $volume:/var/lib/dsta/cluster -e TOKEN="token-1" $1 dst-server start --update=none --keep-configuration=whitelist || exit 1` +sleep 2 +docker cp $container_id:/var/lib/dsta/cluster/cluster_token.txt $aux || exit 1 +diff $token1 $aux || exit 1 +docker rm -fv $container_id > /dev/null # No remove volume + +container_id=`docker run -d -v $volume:/var/lib/dsta/cluster -e TOKEN="token-3" $1 dst-server start --update=none --keep-configuration=token,whitelist || exit 1` +sleep 2 +docker cp $container_id:/var/lib/dsta/cluster/cluster_token.txt $aux || exit 1 +diff $token1 $aux || exit 1 +docker rm -fv $container_id > /dev/null + +container_id=`docker run -d -v $volume:/var/lib/dsta/cluster $1 dst-server start --update=none || exit 1` +sleep 2 +docker cp $container_id:/var/lib/dsta/cluster/cluster_token.txt 2>/dev/null $aux && exit 1 +docker rm -fv $container_id > /dev/null +docker volume rm $volume > /dev/null diff --git a/test/boot-world/run.sh b/test/boot-world/run.sh index c5a911b..09bc786 100755 --- a/test/boot-world/run.sh +++ b/test/boot-world/run.sh @@ -1,16 +1,20 @@ #!/usr/bin/env bash clean() { - rm -f $aux $file1 $file2 + rm -f $aux $file1 $file2 $foo $foo2 if [ -n "`docker ps -qf id=$container_id`" ]; then docker rm -fv $container_id > /dev/null fi + docker volume rm $volume >/dev/null 2>/dev/null || exit 0 } trap clean EXIT +volume="boot-world" aux=`mktemp` file1=`mktemp` file2=`mktemp` +foo=`mktemp` +foo2=`mktemp` echo "foo" > $file1 cat <<- EOF > $file2 @@ -22,26 +26,74 @@ return { overrides={}, } EOF +printf "foo\n" >$foo +printf "foo2\n" >$foo2 container_id=`docker run -d -e LEVELDATA_OVERRIDES="foo" $1 dst-server start --update=none || exit 1` -sleep 5 +sleep 2 docker cp $container_id:/var/lib/dsta/cluster/shard/leveldataoverride.lua $aux || exit 1 diff $file1 $aux || exit 1 docker rm -fv $container_id > /dev/null container_id=`docker run -d -e LEVELDATA_OVERRIDES="foo" -e WORLD_PRESET="bar" $1 dst-server start --update=none || exit 1` -sleep 5 +sleep 2 docker cp $container_id:/var/lib/dsta/cluster/shard/leveldataoverride.lua $aux || exit 1 diff $file1 $aux || exit 1 docker rm -fv $container_id > /dev/null container_id=`docker run -d -e WORLD_PRESET="bar" $1 dst-server start --update=none || exit 1` -sleep 5 +sleep 2 docker cp $container_id:/var/lib/dsta/cluster/shard/leveldataoverride.lua $aux || exit 1 diff $file2 $aux || exit 1 docker rm -fv $container_id > /dev/null container_id=`docker run -d $1 dst-server start --update=none || exit 1` -sleep 5 +sleep 2 docker cp $container_id:/var/lib/dsta/cluster/shard/leveldataoverride.lua $aux 2> /dev/null && exit 1 docker rm -fv $container_id > /dev/null + +test_world_with_keep(){ + docker_image=$1 + variable=$2 + keep_flag=$3 + + container_id=`docker run -d -v $volume:/var/lib/dsta/cluster -e $variable="foo" $docker_image dst-server start --update=none || exit 1` + sleep 2 + docker cp $container_id:/var/lib/dsta/cluster/shard/leveldataoverride.lua $aux || exit 1 + diff $foo $aux || exit 1 + docker rm -fv $container_id >/dev/null + docker volume rm $volume > /dev/null + + container_id=`docker run -d -v $volume:/var/lib/dsta/cluster -e $variable="foo2" $docker_image dst-server start --update=none --keep-configuration=$keep_flag || exit 1` + sleep 2 + docker cp $container_id:/var/lib/dsta/cluster/shard/leveldataoverride.lua $aux || exit 1 + diff $foo2 $aux || exit 1 + docker rm -fv $container_id >/dev/null + + container_id=`docker run -d -v $volume:/var/lib/dsta/cluster $docker_image dst-server start --update=none --keep-configuration=$keep_flag || exit 1` + sleep 2 + docker cp $container_id:/var/lib/dsta/cluster/shard/leveldataoverride.lua $aux || exit 1 + diff $foo2 $aux || exit 1 + docker rm -fv $container_id >/dev/null + + container_id=`docker run -d -v $volume:/var/lib/dsta/cluster -e $variable="foo" $docker_image dst-server start --update=none || exit 1` + sleep 2 + docker cp $container_id:/var/lib/dsta/cluster/shard/leveldataoverride.lua $aux || exit 1 + diff $foo $aux || exit 1 + docker rm -fv $container_id >/dev/null + + container_id=`docker run -d -v $volume:/var/lib/dsta/cluster -e $variable="foo2" $docker_image dst-server start --update=none --keep-configuration=$keep_flag || exit 1` + sleep 2 + docker cp $container_id:/var/lib/dsta/cluster/shard/leveldataoverride.lua $aux || exit 1 + diff $foo $aux || exit 1 + docker rm -fv $container_id >/dev/null + + container_id=`docker run -d -v $volume:/var/lib/dsta/cluster $docker_image dst-server start --update=none || exit 1` + sleep 2 + docker cp $container_id:/var/lib/dsta/cluster/shard/leveldataoverride.lua $aux 2>/dev/null && exit 1 + diff $foo $aux || exit 1 + docker rm -fv $container_id >/dev/null + docker volume rm $volume > /dev/null +} + +test_world_with_keep $1 LEVELDATA_OVERRIDES world diff --git a/test/dsta-help/run.sh b/test/dsta-help/run.sh index dae9f1c..1ff84a2 100755 --- a/test/dsta-help/run.sh +++ b/test/dsta-help/run.sh @@ -40,6 +40,7 @@ diff $file1 $file2 || exit 1 # dst-server start cat > $file1 <<- EOF usage: dst-server start [--update=all|none|game|mods] + [--keep-configuration=]...>] --update=none Update nothing, just start the server. This is the default behaviour. @@ -49,6 +50,17 @@ usage: dst-server start [--update=all|none|game|mods] Update just the game (no the mods) and launch the server. --update=mods Update the mods and launch the server. + --keep-configuration + Select which configuration you don't want to overwrite. + You must provide one or more of these values separated by commas: + - token + - cluster + - server + - world + - adminlist + - blocklist + - whitelist + - mods EOF docker run --rm -e NAME=bar $1 dst-server help start > $file2 || exit 1 diff --git a/test/dsta-start/run.sh b/test/dsta-start/run.sh index d6db391..02caafc 100755 --- a/test/dsta-start/run.sh +++ b/test/dsta-start/run.sh @@ -60,6 +60,7 @@ docker rm -fv $container_id > /dev/null # Errors cat > $file1 <<- EOF usage: dst-server start [--update=all|none|game|mods] + [--keep-configuration=]...>] --update=none Update nothing, just start the server. This is the default behaviour. @@ -69,6 +70,17 @@ usage: dst-server start [--update=all|none|game|mods] Update just the game (no the mods) and launch the server. --update=mods Update the mods and launch the server. + --keep-configuration + Select which configuration you don't want to overwrite. + You must provide one or more of these values separated by commas: + - token + - cluster + - server + - world + - adminlist + - blocklist + - whitelist + - mods EOF docker run --rm $1 dst-server start foo >/dev/null 2> $file2 && exit 1 diff $file1 $file2 || exit 1 From a1984ffd9c25f641fa0589d2135edef55680b799 Mon Sep 17 00:00:00 2001 From: oshotton Date: Sun, 24 Sep 2017 19:03:36 +0100 Subject: [PATCH 11/28] Update configuration.md (#106) Update documentation regarding adminlist, whitelist and blocklist --- docs/configuration.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/configuration.md b/docs/configuration.md index b2e6d44..305529e 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -107,6 +107,24 @@ players which can connect to the server. The sum of `MAX_PLAYERS` and `WHITELIST how many players can connect to the server simultaneously. - *number* *[default: 0]* +**ADMINLIST** +Klei UserIDs to add to the adminlist.txt file. Gives players in the list Administrator priveliges. +A players Klei UserID can be found my clicking "Account" in the bottom right of the main menu. +- *CSV of Klei UserIDs* + *Example:* `KU_G_cla3ou,KU_yDc5M7bx,KU_ad39dik` + +**WHITELIST** +Klei UserIDs to add to the whitelist.txt file. +A players Klei UserID can be found my clicking "Account" in the bottom right of the main menu. +- *CSV of Klei UserIDs* + *Example:* `KU_G_cla3ou,KU_yDc5M7bx,KU_ad39dik` + +**BLOCKLIST** +Klei UserIDs to add to the blocklist.txt file. +A players Klei UserID can be found my clicking "Account" in the bottom right of the main menu. +- *CSV of Klei UserIDs* + *Example:* `KU_G_cla3ou,KU_yDc5M7bx,KU_ad39dik` + **PVP_ENABLE** Enables/disables PVP, which basically defines if players can attack each other. - true From e47a36b7df3563bf898c68801e649dcb2bbd3740 Mon Sep 17 00:00:00 2001 From: Thomas Deinhamer Date: Sun, 22 Oct 2017 01:43:45 +0200 Subject: [PATCH 12/28] Fix syntax error of an if statement in the world shell script --- build/static/boot/world.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/static/boot/world.sh b/build/static/boot/world.sh index 51e3151..4c758c8 100755 --- a/build/static/boot/world.sh +++ b/build/static/boot/world.sh @@ -15,7 +15,7 @@ if [[ -n "$LEVELDATA_OVERRIDES" ]]; then elif [[ -n "$WORLD_PRESET" ]]; then validate_option "WORLD_PRESET" SURVIVAL_TOGETHER SURVIVAL_TOGETHER_CLASSIC SURVIVAL_DEFAULT_PLUS COMPLETE_DARKNESS DST_CAVE DST_CAVE_PLUS - if ["$WORLD_PRESET" == "DST_CAVE"] || ["$WORLD_PRESET" == "DST_CAVE_PLUS"]; then + if [[ "$WORLD_PRESET" == "DST_CAVE" ]] || [[ "$WORLD_PRESET" == "DST_CAVE_PLUS" ]]; then location="cave" else location="forest" From bfa5a2f2edebaa313ec4250587566361301b2630 Mon Sep 17 00:00:00 2001 From: Thomas Deinhamer Date: Sun, 22 Oct 2017 01:54:12 +0200 Subject: [PATCH 13/28] Clean up shell scripts --- build/static/bin/console.sh | 8 ++++---- build/static/bin/log.sh | 20 ++++++++++---------- build/static/bin/start.sh | 24 ++++++++++++------------ build/static/bin/update.sh | 12 ++++++------ build/static/bin/version.sh | 20 ++++++++++---------- build/static/boot/functions.sh | 4 +++- build/static/boot/lists.sh | 14 +++++++------- build/static/boot/mods.sh | 20 ++++++++++---------- build/static/boot/settings.sh | 20 ++++++++++---------- build/static/boot/token.sh | 12 ++++++------ build/static/boot/world.sh | 14 +++++++------- build/static/dst/update.sh | 6 +++--- 12 files changed, 88 insertions(+), 86 deletions(-) diff --git a/build/static/bin/console.sh b/build/static/bin/console.sh index 2c4065d..a2815c8 100755 --- a/build/static/bin/console.sh +++ b/build/static/bin/console.sh @@ -1,20 +1,20 @@ #!/usr/bin/env bash usage(){ - cat $DSTA_HOME/doc/console.usage + cat "$DSTA_HOME/doc/console.usage" } if [ "$1" == "--help" ]; then usage exit 0 elif [ $# -eq 0 ]; then - cat < /proc/self/fd/0 > $DSTA_HOME/console + cat < /proc/self/fd/0 > "$DSTA_HOME/console" else for command in "$@"; do if [ "$command" == "-" ]; then - cat < /proc/self/fd/0 > $DSTA_HOME/console + cat < /proc/self/fd/0 > "$DSTA_HOME/console" else - echo $command > $DSTA_HOME/console + echo "$command" > "$DSTA_HOME/console" fi done fi diff --git a/build/static/bin/log.sh b/build/static/bin/log.sh index 7684543..90c756d 100755 --- a/build/static/bin/log.sh +++ b/build/static/bin/log.sh @@ -1,28 +1,28 @@ #!/usr/bin/env bash usage(){ - cat $DSTA_HOME/doc/log.usage + cat "$DSTA_HOME/doc/log.usage" } -if [ $# -eq 0 ]; then - log=$CLUSTER_PATH/$SHARD_NAME/server_log.txt -elif [ $1 == "--help" ]; then +if [ "$#" -eq 0 ]; then + log="$CLUSTER_PATH/$SHARD_NAME/server_log.txt" +elif [ "$1" == "--help" ]; then usage exit 0 -elif [ $# -eq 1 ]; then - case $1 in +elif [ "$#" -eq 1 ]; then + case "$1" in --server) - log=$CLUSTER_PATH/$SHARD_NAME/server_log.txt + log="$CLUSTER_PATH/$SHARD_NAME/server_log.txt" ;; --chat) - log=$CLUSTER_PATH/$SHARD_NAME/server_log_chat.txt + log="$CLUSTER_PATH/$SHARD_NAME/server_log_chat.txt" ;; esac fi if [ -n "$log" ]; then - if [ -f $log ]; then - exec cat $log + if [ -f "$log" ]; then + exec cat "$log" fi else usage 1>&2 diff --git a/build/static/bin/start.sh b/build/static/bin/start.sh index 3302adb..e64671a 100755 --- a/build/static/bin/start.sh +++ b/build/static/bin/start.sh @@ -1,20 +1,20 @@ #!/usr/bin/env bash usage(){ - cat $DSTA_HOME/doc/start.usage + cat "$DSTA_HOME/doc/start.usage" } update=0 -if [ $# -eq 0 ]; then +if [ "$#" -eq 0 ]; then true # no-op -elif [ $1 == "--help" ]; then +elif [ "$1" == "--help" ]; then usage exit 0 else - while [[ $# -gt 0 ]] + while [[ "$#" -gt 0 ]] do key="$1" - case $key in + case "$key" in --update=all) update=3 ;; @@ -41,17 +41,17 @@ else fi if (((update & 1) != 0)); then - $DSTA_HOME/dst/update.sh + "$DSTA_HOME/dst/update.sh" fi if (((update & 2) == 0)); then flag="-skip_update_server_mods" fi -$DSTA_HOME/boot/token.sh "$keep" -$DSTA_HOME/boot/settings.sh "$keep" -$DSTA_HOME/boot/lists.sh "$keep" -$DSTA_HOME/boot/world.sh "$keep" -$DSTA_HOME/boot/mods.sh "$keep" +"$DSTA_HOME"/boot/token.sh "$keep" +"$DSTA_HOME"/boot/settings.sh "$keep" +"$DSTA_HOME"/boot/lists.sh "$keep" +"$DSTA_HOME"/boot/world.sh "$keep" +"$DSTA_HOME"/boot/mods.sh "$keep" -exec dontstarve_dedicated_server_nullrenderer $flag +exec dontstarve_dedicated_server_nullrenderer "$flag" diff --git a/build/static/bin/update.sh b/build/static/bin/update.sh index af8a042..4834058 100755 --- a/build/static/bin/update.sh +++ b/build/static/bin/update.sh @@ -1,16 +1,16 @@ #!/usr/bin/env bash usage(){ - cat $DSTA_HOME/doc/update.usage + cat "$DSTA_HOME"/doc/update.usage } -if [ $# -eq 0 ]; then +if [ "$#" -eq 0 ]; then update=3 -elif [ $1 == "--help" ]; then +elif [ "$1" == "--help" ]; then usage exit 0 -elif [ $# -eq 1 ]; then - case $1 in +elif [ "$#" -eq 1 ]; then + case "$1" in --all) update=3 ;; @@ -29,7 +29,7 @@ if [ -z "$update" ]; then fi if (((update & 1) != 0)); then - $DSTA_HOME/dst/update.sh + "$DSTA_HOME"/dst/update.sh fi if (((update & 2) != 0)); then diff --git a/build/static/bin/version.sh b/build/static/bin/version.sh index 4b734b4..87595b1 100755 --- a/build/static/bin/version.sh +++ b/build/static/bin/version.sh @@ -1,15 +1,15 @@ #!/usr/bin/env bash usage(){ - cat $DSTA_HOME/doc/version.usage + cat "$DSTA_HOME"/doc/version.usage } local_version(){ - cat $DST_HOME/steamapps/appmanifest_343050.acf | clean_version + cat "$DST_HOME"/steamapps/appmanifest_343050.acf | clean_version } upstream_version(){ - rm -rf $STEAM_HOME/Steam/appcache/* + rm -rf "$STEAM_HOME"/Steam/appcache/* steamcmd +login anonymous +app_info_update 1 +app_info_print 343050 +quit | clean_version } @@ -20,12 +20,12 @@ clean_version(){ if [ "$1" == "--help" ]; then usage exit 0 -elif [ $# -eq 0 ]; then - echo "Local version: `local_version`" - echo "Upstream version: `upstream_version`" +elif [ "$#" -eq 0 ]; then + echo "Local version: $(local_version)" + echo "Upstream version: $(upstream_version)" exit 0 -elif [ $# -eq 1 ]; then - case $1 in +elif [ "$#" -eq 1 ]; then + case "$1" in --local) local_version exit 0 @@ -37,8 +37,8 @@ elif [ $# -eq 1 ]; then ;; --check) - version_local=`local_version` - version_upstream=`upstream_version` + version_local=$(local_version) + version_upstream=$(upstream_version) if [ "$version_local" -eq "$version_upstream" ]; then echo "Version is up to date." diff --git a/build/static/boot/functions.sh b/build/static/boot/functions.sh index c27d024..5952bd2 100644 --- a/build/static/boot/functions.sh +++ b/build/static/boot/functions.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + warning(){ echo "[WARNING] $1" 1>&2 } @@ -19,7 +21,7 @@ validate_int(){ } validate_port(){ - return `validate_int "$1" "1" "65535"` + return "$(validate_int "$1" "1" "65535")" } # http://stackoverflow.com/a/8574392/842697 diff --git a/build/static/boot/lists.sh b/build/static/boot/lists.sh index c8fd7d1..f438118 100755 --- a/build/static/boot/lists.sh +++ b/build/static/boot/lists.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -source "`dirname "$0"`/functions.sh" +source "$(dirname "$0")/functions.sh" create_list(){ list=$1 @@ -10,19 +10,19 @@ create_list(){ return fi - rm -f $file + rm -f "$file" if [[ -n "$list" ]] ; then - echo $list | tr , '\n' >$file - chown $STEAM_USER:$STEAM_USER $file + echo "$list" | tr , '\n' >"$file" + chown "$STEAM_USER":"$STEAM_USER" "$file" fi } # Create the adminlist.txt file. -create_list "$ADMINLIST" "$CLUSTER_PATH/adminlist.txt" `containsElement adminlist $@ && echo 0 || echo 1` +create_list "$ADMINLIST" "$CLUSTER_PATH/adminlist.txt" "$(containsElement adminlist "$@" && echo 0 || echo 1)" # Create the whitelist.txt file. -create_list "$WHITELIST" "$CLUSTER_PATH/whitelist.txt" `containsElement whitelist $@ && echo 0 || echo 1` +create_list "$WHITELIST" "$CLUSTER_PATH/whitelist.txt" "$(containsElement whitelist "$@" && echo 0 || echo 1)" # Create the blocklist.txt file. -create_list "$BLOCKLIST" "$CLUSTER_PATH/blocklist.txt" `containsElement blocklist $@ && echo 0 || echo 1` +create_list "$BLOCKLIST" "$CLUSTER_PATH/blocklist.txt" "$(containsElement blocklist "$@" && echo 0 || echo 1)" diff --git a/build/static/boot/mods.sh b/build/static/boot/mods.sh index 59ea718..d3af7e5 100755 --- a/build/static/boot/mods.sh +++ b/build/static/boot/mods.sh @@ -6,38 +6,38 @@ file_mods_overrides="$CLUSTER_PATH/$SHARD_NAME/modoverrides.lua" IFS="," -if [[ -f "$file_mods_overrides" ]] && containsElement "mods" $@ ; then +if [[ -f "$file_mods_overrides" ]] && containsElement "mods" "$@"; then exit 0 fi -rm -f $file_mods_setup $file_mods_settings $file_mods_overrides +rm -f "$file_mods_setup" "$file_mods_settings" "$file_mods_overrides" # Install and enable regular mods from the Steam workshop. if [[ -n "$MODS" ]]; then for mod in $MODS; do - echo "ServerModSetup(\"$mod\")" >> $file_mods_setup + echo "ServerModSetup(\"$mod\")" >> "$file_mods_setup" done if [ -n "$MODS_OVERRIDES" ]; then - echo "$MODS_OVERRIDES" > $file_mods_overrides + echo "$MODS_OVERRIDES" > "$file_mods_overrides" else - echo "return {" > $file_mods_overrides + echo "return {" > "$file_mods_overrides" for mod in $MODS; do - echo " [\"workshop-$mod\"] = { enabled = true }," >> $file_mods_overrides + echo " [\"workshop-$mod\"] = { enabled = true }," >> "$file_mods_overrides" done - echo "}" >> $file_mods_overrides + echo "}" >> "$file_mods_overrides" fi - chown $STEAM_USER:$STEAM_USER $file_mods_overrides + chown "$STEAM_USER":"$STEAM_USER" "$file_mods_overrides" fi # Enable mods forcefully for mod development. if [ -n "$MODS_FORCE" ]; then for mod in $MODS_FORCE; do - echo "ForceEnableMod(\"$mod\")" >> $file_mods_settings + echo "ForceEnableMod(\"$mod\")" >> "$file_mods_settings" done - chown $STEAM_USER:$STEAM_USER $file_mods_settings + chown "$STEAM_USER":"$STEAM_USER" "$file_mods_settings" fi diff --git a/build/static/boot/settings.sh b/build/static/boot/settings.sh index 271959b..f7dff87 100755 --- a/build/static/boot/settings.sh +++ b/build/static/boot/settings.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -source "`dirname "$0"`/functions.sh" +source "$(dirname "$0")/functions.sh" file_cluster="$CLUSTER_PATH/cluster.ini" file_server="$CLUSTER_PATH/$SHARD_NAME/server.ini" @@ -34,20 +34,20 @@ validate_bool "SHARD_ENABLE" validate_bool "SHARD_IS_MASTER" validate_port "SHARD_MASTER_PORT" -if [[ -f "$file_cluster" ]] && containsElement "cluster" $@ ; then +if [[ -f "$file_cluster" ]] && containsElement "cluster" "$@"; then true # no-op else if [ -z "$NAME" ]; then selectRandomLine(){ - mapfile list < $1 - echo ${list[$RANDOM % ${#list[@]}]} + mapfile list < "$1" + echo "${list[$RANDOM % ${#list[@]}]}" } - NAME="`selectRandomLine $DSTA_HOME/data/adjectives.txt` `selectRandomLine $DSTA_HOME/data/names.txt`" + NAME="$(selectRandomLine "$DSTA_HOME"/data/adjectives.txt) $(selectRandomLine "$DSTA_HOME"/data/names.txt)" echo "'$NAME' has been set as the cluster's name." fi - exec 4>&1 1>$file_cluster + exec 4>&1 1>"$file_cluster" echo "[NETWORK]" conf "cluster_name" "$NAME_PREFIX $NAME" @@ -95,13 +95,13 @@ else exec 1>&4 4>&- - chown $STEAM_USER:$STEAM_USER $file_cluster + chown "$STEAM_USER":"$STEAM_USER" "$file_cluster" fi -if [[ -f "$file_server" ]] && containsElement "server" $@ ; then +if [[ -f "$file_server" ]] && containsElement "server" "$@"; then true # no-op else - exec 4>&1 1>$file_server + exec 4>&1 1>"$file_server" echo "[NETWORK]" conf "server_port" "$SERVER_PORT" @@ -127,5 +127,5 @@ else exec 1>&4 4>&- - chown $STEAM_USER:$STEAM_USER $file_server + chown "$STEAM_USER":"$STEAM_USER" "$file_server" fi diff --git a/build/static/boot/token.sh b/build/static/boot/token.sh index 0e3d769..20a982a 100755 --- a/build/static/boot/token.sh +++ b/build/static/boot/token.sh @@ -1,16 +1,16 @@ #!/usr/bin/env bash -source "`dirname "$0"`/functions.sh" +source "$(dirname "$0")/functions.sh" file_token="$CLUSTER_PATH/cluster_token.txt" -if [[ -f "$file_token" ]] && containsElement "token" $@ ; then +if [[ -f "$file_token" ]] && containsElement "token" "$@"; then exit 0 fi -if [[ -n "$TOKEN" ]] ; then - printf "$TOKEN" > $file_token - chown $STEAM_USER:$STEAM_USER $file_token +if [[ -n "$TOKEN" ]]; then + printf "$TOKEN" > "$file_token" + chown "$STEAM_USER":"$STEAM_USER" "$file_token" else - rm -f $file_token + rm -f "$file_token" fi diff --git a/build/static/boot/world.sh b/build/static/boot/world.sh index 4c758c8..9ca4738 100755 --- a/build/static/boot/world.sh +++ b/build/static/boot/world.sh @@ -1,17 +1,17 @@ #!/usr/bin/env bash -source "`dirname "$0"`/functions.sh" +source "$(dirname "$0")/functions.sh" file_leveldata_override="$CLUSTER_PATH/$SHARD_NAME/leveldataoverride.lua" -if [[ -f "$file_leveldata_override" ]] && containsElement "world" $@ ; then +if [[ -f "$file_leveldata_override" ]] && containsElement "world" "$@"; then exit 0 fi -rm -f $file_leveldata_override +rm -f "$file_leveldata_override" if [[ -n "$LEVELDATA_OVERRIDES" ]]; then - echo "$LEVELDATA_OVERRIDES" > $file_leveldata_override + echo "$LEVELDATA_OVERRIDES" > "$file_leveldata_override" elif [[ -n "$WORLD_PRESET" ]]; then validate_option "WORLD_PRESET" SURVIVAL_TOGETHER SURVIVAL_TOGETHER_CLASSIC SURVIVAL_DEFAULT_PLUS COMPLETE_DARKNESS DST_CAVE DST_CAVE_PLUS @@ -21,7 +21,7 @@ elif [[ -n "$WORLD_PRESET" ]]; then location="forest" fi - cat <<- EOF > $file_leveldata_override + cat <<- EOF > "$file_leveldata_override" return { id = "$WORLD_PRESET", location = "$location", @@ -32,6 +32,6 @@ return { EOF fi -if [[ -f $file_leveldata_override ]]; then - chown $STEAM_USER:$STEAM_USER $file_world_override +if [[ -f "$file_leveldata_override" ]]; then + chown "$STEAM_USER":"$STEAM_USER" "$file_leveldata_override" fi diff --git a/build/static/dst/update.sh b/build/static/dst/update.sh index f3c945a..e5d9d81 100755 --- a/build/static/dst/update.sh +++ b/build/static/dst/update.sh @@ -3,8 +3,8 @@ exec steamcmd \ +@ShutdownOnFailedCommand 1 \ +login anonymous \ - +force_install_dir $DST_HOME \ + +force_install_dir "$DST_HOME" \ +app_update 343050 \ - $([ -n "$DST_BRANCH" ] && printf %s "-beta $DST_BRANCH") \ - $([ -n "$DST_BRANCH_PASSWORD" ] && printf %s "-betapassword $DST_BRANCH_PASSWORD") \ + "$([ -n "$DST_BRANCH" ] && printf %s "-beta $DST_BRANCH")" \ + "$([ -n "$DST_BRANCH_PASSWORD" ] && printf %s "-betapassword $DST_BRANCH_PASSWORD")" \ +quit From b30d495ff8a7ce5e6eb496f74ae6604fea264b48 Mon Sep 17 00:00:00 2001 From: Thomas Deinhamer Date: Sun, 22 Oct 2017 12:07:43 +0200 Subject: [PATCH 14/28] Fix validate_port function --- build/static/boot/functions.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/static/boot/functions.sh b/build/static/boot/functions.sh index 5952bd2..284b89e 100644 --- a/build/static/boot/functions.sh +++ b/build/static/boot/functions.sh @@ -21,7 +21,7 @@ validate_int(){ } validate_port(){ - return "$(validate_int "$1" "1" "65535")" + return $(validate_int "$1" "1" "65535") } # http://stackoverflow.com/a/8574392/842697 From 37024f1dcc4f7d4744fc60a423b4a11f8a8d053d Mon Sep 17 00:00:00 2001 From: Thomas Deinhamer Date: Sun, 22 Oct 2017 12:35:08 +0200 Subject: [PATCH 15/28] Further clean up shell scripts --- build/docker-entrypoint.sh | 10 ++++----- .../dontstarve_dedicated_server_nullrenderer | 14 ++++++------ build/script/dst-server | 15 +++++++------ build/static/bin/console.sh | 8 +++---- build/static/bin/log.sh | 12 +++++----- build/static/bin/start.sh | 7 +++--- build/static/bin/update.sh | 14 ++++++------ build/static/bin/version.sh | 22 +++++++++---------- build/static/boot/functions.sh | 14 ++++++------ build/static/boot/lists.sh | 7 +++--- build/static/boot/mods.sh | 4 ++-- build/static/boot/settings.sh | 4 ++-- build/static/boot/world.sh | 2 +- 13 files changed, 68 insertions(+), 65 deletions(-) diff --git a/build/docker-entrypoint.sh b/build/docker-entrypoint.sh index b58544f..8add059 100755 --- a/build/docker-entrypoint.sh +++ b/build/docker-entrypoint.sh @@ -4,19 +4,19 @@ set -e # Run start command if only options given. -if [ "${1:0:1}" = '-' ]; then +if [[ "${1:0:1}" = '-' ]]; then set -- dst-server start "$@" fi # Run boot scripts before starting the server. -if [ "$1" = 'dst-server' ]; then +if [[ "$1" = 'dst-server' ]]; then # Prepare the shard directory. - mkdir -p $CLUSTER_PATH/$SHARD_NAME - chown -R $STEAM_USER:$STEAM_USER $CLUSTER_PATH + mkdir -p "$CLUSTER_PATH/$SHARD_NAME" + chown -R "$STEAM_USER":"$STEAM_USER" "$CLUSTER_PATH" # Run via steam user if the command is `dst-server`. - set -- gosu $STEAM_USER "$@" + set -- gosu "$STEAM_USER" "$@" fi # Execute the command. diff --git a/build/script/dontstarve_dedicated_server_nullrenderer b/build/script/dontstarve_dedicated_server_nullrenderer index f19d01e..fa19d1d 100755 --- a/build/script/dontstarve_dedicated_server_nullrenderer +++ b/build/script/dontstarve_dedicated_server_nullrenderer @@ -1,18 +1,18 @@ #!/usr/bin/env bash -if [ `whoami` != "$STEAM_USER" ]; then - exec gosu $STEAM_USER $0 "$@" +if [[ "$(whoami)" != "$STEAM_USER" ]]; then + exec gosu "$STEAM_USER" "$0" "$@" fi # We must have at least one writer -sleep infinity > $DSTA_HOME/console & +sleep infinity > "$DSTA_HOME/console" & -cd $DST_HOME/bin +cd "$DST_HOME/bin" exec ./dontstarve_dedicated_server_nullrenderer \ - -persistent_storage_root `dirname $CLUSTER_PATH` \ + -persistent_storage_root "$(dirname "$CLUSTER_PATH")" \ -conf_dir "." \ - -cluster `basename $CLUSTER_PATH` \ + -cluster "$(basename "$CLUSTER_PATH")" \ -shard "$SHARD_NAME" \ -backup_log_count "$BACKUP_LOG_COUNT" \ - "$@" < <({ stdbuf -oL cat $DSTA_HOME/console & stdbuf -oL cat & }) + "$@" < <({ stdbuf -oL cat "$DSTA_HOME/console" & stdbuf -oL cat & }) diff --git a/build/script/dst-server b/build/script/dst-server index 95e1ad8..cdb9b80 100755 --- a/build/script/dst-server +++ b/build/script/dst-server @@ -1,28 +1,29 @@ #!/usr/bin/env bash -usage(){ - cat $DSTA_HOME/doc/dst-server.usage +usage() { + cat "$DSTA_HOME/doc/dst-server.usage" } -if [ $# -eq 0 ]; then +if [[ $# -eq 0 ]]; then usage exit 1 fi -case $@ in +case "$@" in --help|help) usage exit 0 ;; --help\ *|help\ *) - set $2 --help + set "$2" --help ;; esac bin="$DSTA_HOME/bin/$1.sh" -if [ -f $bin ]; then + +if [[ -f "$bin" ]]; then shift - exec $bin "$@" + exec "$bin" "$@" else usage 1>&2 exit 1 diff --git a/build/static/bin/console.sh b/build/static/bin/console.sh index a2815c8..ce0ff1d 100755 --- a/build/static/bin/console.sh +++ b/build/static/bin/console.sh @@ -1,17 +1,17 @@ #!/usr/bin/env bash -usage(){ +usage() { cat "$DSTA_HOME/doc/console.usage" } -if [ "$1" == "--help" ]; then +if [[ "$1" = "--help" ]]; then usage exit 0 -elif [ $# -eq 0 ]; then +elif [[ $# -eq 0 ]]; then cat < /proc/self/fd/0 > "$DSTA_HOME/console" else for command in "$@"; do - if [ "$command" == "-" ]; then + if [[ "$command" = "-" ]]; then cat < /proc/self/fd/0 > "$DSTA_HOME/console" else echo "$command" > "$DSTA_HOME/console" diff --git a/build/static/bin/log.sh b/build/static/bin/log.sh index 90c756d..fe2f9eb 100755 --- a/build/static/bin/log.sh +++ b/build/static/bin/log.sh @@ -1,15 +1,15 @@ #!/usr/bin/env bash -usage(){ +usage() { cat "$DSTA_HOME/doc/log.usage" } -if [ "$#" -eq 0 ]; then +if [[ $# -eq 0 ]]; then log="$CLUSTER_PATH/$SHARD_NAME/server_log.txt" -elif [ "$1" == "--help" ]; then +elif [[ "$1" = "--help" ]]; then usage exit 0 -elif [ "$#" -eq 1 ]; then +elif [[ $# -eq 1 ]]; then case "$1" in --server) log="$CLUSTER_PATH/$SHARD_NAME/server_log.txt" @@ -20,8 +20,8 @@ elif [ "$#" -eq 1 ]; then esac fi -if [ -n "$log" ]; then - if [ -f "$log" ]; then +if [[ -n "$log" ]]; then + if [[ -f "$log" ]]; then exec cat "$log" fi else diff --git a/build/static/bin/start.sh b/build/static/bin/start.sh index e64671a..bf7ebf6 100755 --- a/build/static/bin/start.sh +++ b/build/static/bin/start.sh @@ -1,13 +1,14 @@ #!/usr/bin/env bash -usage(){ +usage() { cat "$DSTA_HOME/doc/start.usage" } update=0 -if [ "$#" -eq 0 ]; then + +if [[ $# -eq 0 ]]; then true # no-op -elif [ "$1" == "--help" ]; then +elif [[ "$1" = "--help" ]]; then usage exit 0 else diff --git a/build/static/bin/update.sh b/build/static/bin/update.sh index 4834058..01ed587 100755 --- a/build/static/bin/update.sh +++ b/build/static/bin/update.sh @@ -1,15 +1,15 @@ #!/usr/bin/env bash -usage(){ - cat "$DSTA_HOME"/doc/update.usage +usage() { + cat "$DSTA_HOME/doc/update.usage" } -if [ "$#" -eq 0 ]; then +if [[ $# -eq 0 ]]; then update=3 -elif [ "$1" == "--help" ]; then +elif [[ "$1" = "--help" ]]; then usage exit 0 -elif [ "$#" -eq 1 ]; then +elif [[ $# -eq 1 ]]; then case "$1" in --all) update=3 @@ -23,13 +23,13 @@ elif [ "$#" -eq 1 ]; then esac fi -if [ -z "$update" ]; then +if [[ -z "$update" ]]; then usage 1>&2 exit 1 fi if (((update & 1) != 0)); then - "$DSTA_HOME"/dst/update.sh + "$DSTA_HOME/dst/update.sh" fi if (((update & 2) != 0)); then diff --git a/build/static/bin/version.sh b/build/static/bin/version.sh index 87595b1..88ad09a 100755 --- a/build/static/bin/version.sh +++ b/build/static/bin/version.sh @@ -1,30 +1,30 @@ #!/usr/bin/env bash -usage(){ - cat "$DSTA_HOME"/doc/version.usage +usage() { + cat "$DSTA_HOME/doc/version.usage" } -local_version(){ - cat "$DST_HOME"/steamapps/appmanifest_343050.acf | clean_version +local_version() { + cat "$DST_HOME/steamapps/appmanifest_343050.acf" | clean_version } -upstream_version(){ - rm -rf "$STEAM_HOME"/Steam/appcache/* +upstream_version() { + rm -rf "$STEAM_HOME/Steam/appcache/*" steamcmd +login anonymous +app_info_update 1 +app_info_print 343050 +quit | clean_version } -clean_version(){ +clean_version() { grep -Po -m 1 "\"buildid\"\s*\"(.*)\"" | grep -Po "\d*" } -if [ "$1" == "--help" ]; then +if [[ "$1" = "--help" ]]; then usage exit 0 -elif [ "$#" -eq 0 ]; then +elif [[ $# -eq 0 ]]; then echo "Local version: $(local_version)" echo "Upstream version: $(upstream_version)" exit 0 -elif [ "$#" -eq 1 ]; then +elif [[ $# -eq 1 ]]; then case "$1" in --local) local_version @@ -40,7 +40,7 @@ elif [ "$#" -eq 1 ]; then version_local=$(local_version) version_upstream=$(upstream_version) - if [ "$version_local" -eq "$version_upstream" ]; then + if [[ "$version_local" -eq "$version_upstream" ]]; then echo "Version is up to date." exit 0 else diff --git a/build/static/boot/functions.sh b/build/static/boot/functions.sh index 284b89e..684f738 100644 --- a/build/static/boot/functions.sh +++ b/build/static/boot/functions.sh @@ -1,10 +1,10 @@ #!/usr/bin/env bash -warning(){ +warning() { echo "[WARNING] $1" 1>&2 } -validate_bool(){ +validate_bool() { local v=${!1} if [[ -n "$v" ]] && [[ "$v" != "true" ]] && [[ "$v" != "false" ]]; then warning "$1 must be \"true\" or \"false\"." @@ -12,7 +12,7 @@ validate_bool(){ fi } -validate_int(){ +validate_int() { local v=${!1} if [[ -n "$v" ]] && [[ "$v" -lt "$2" ]] || [[ "$v" -gt "$3" ]]; then warning "$1 must be between $2 and $3." @@ -20,18 +20,18 @@ validate_int(){ fi } -validate_port(){ +validate_port() { return $(validate_int "$1" "1" "65535") } # http://stackoverflow.com/a/8574392/842697 -containsElement(){ +containsElement() { local e - for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done + for e in "${@:2}"; do [[ "$e" = "$1" ]] && return 0; done return 1 } -validate_option(){ +validate_option() { local v=${!1} if [[ -n "$v" ]] && ! containsElement "$v" "${@:2}"; then warning "$1 must be one of these: ${*:2}." diff --git a/build/static/boot/lists.sh b/build/static/boot/lists.sh index f438118..bcafa11 100755 --- a/build/static/boot/lists.sh +++ b/build/static/boot/lists.sh @@ -2,17 +2,18 @@ source "$(dirname "$0")/functions.sh" -create_list(){ +create_list() { list=$1 file=$2 must_keep=$3 - if [[ -f $file ]] && [[ "$must_keep" == "0" ]] ; then + + if [[ -f $file ]] && [[ "$must_keep" = "0" ]]; then return fi rm -f "$file" - if [[ -n "$list" ]] ; then + if [[ -n "$list" ]]; then echo "$list" | tr , '\n' >"$file" chown "$STEAM_USER":"$STEAM_USER" "$file" fi diff --git a/build/static/boot/mods.sh b/build/static/boot/mods.sh index d3af7e5..0d89f60 100755 --- a/build/static/boot/mods.sh +++ b/build/static/boot/mods.sh @@ -18,7 +18,7 @@ if [[ -n "$MODS" ]]; then echo "ServerModSetup(\"$mod\")" >> "$file_mods_setup" done - if [ -n "$MODS_OVERRIDES" ]; then + if [[ -n "$MODS_OVERRIDES" ]]; then echo "$MODS_OVERRIDES" > "$file_mods_overrides" else echo "return {" > "$file_mods_overrides" @@ -34,7 +34,7 @@ if [[ -n "$MODS" ]]; then fi # Enable mods forcefully for mod development. -if [ -n "$MODS_FORCE" ]; then +if [[ -n "$MODS_FORCE" ]]; then for mod in $MODS_FORCE; do echo "ForceEnableMod(\"$mod\")" >> "$file_mods_settings" done diff --git a/build/static/boot/settings.sh b/build/static/boot/settings.sh index f7dff87..c16c6e5 100755 --- a/build/static/boot/settings.sh +++ b/build/static/boot/settings.sh @@ -37,8 +37,8 @@ validate_port "SHARD_MASTER_PORT" if [[ -f "$file_cluster" ]] && containsElement "cluster" "$@"; then true # no-op else - if [ -z "$NAME" ]; then - selectRandomLine(){ + if [[ -z "$NAME" ]]; then + selectRandomLine() { mapfile list < "$1" echo "${list[$RANDOM % ${#list[@]}]}" } diff --git a/build/static/boot/world.sh b/build/static/boot/world.sh index 9ca4738..93b415c 100755 --- a/build/static/boot/world.sh +++ b/build/static/boot/world.sh @@ -15,7 +15,7 @@ if [[ -n "$LEVELDATA_OVERRIDES" ]]; then elif [[ -n "$WORLD_PRESET" ]]; then validate_option "WORLD_PRESET" SURVIVAL_TOGETHER SURVIVAL_TOGETHER_CLASSIC SURVIVAL_DEFAULT_PLUS COMPLETE_DARKNESS DST_CAVE DST_CAVE_PLUS - if [[ "$WORLD_PRESET" == "DST_CAVE" ]] || [[ "$WORLD_PRESET" == "DST_CAVE_PLUS" ]]; then + if [[ "$WORLD_PRESET" = "DST_CAVE" ]] || [[ "$WORLD_PRESET" = "DST_CAVE_PLUS" ]]; then location="cave" else location="forest" From f175832eeef8633a34e80cf299dda3fc985b97b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brais=20Gab=C3=ADn?= Date: Sun, 22 Oct 2017 13:08:59 +0200 Subject: [PATCH 16/28] Remove EXPOSE from the Dockerfile Fixes #103 --- build/Dockerfile | 3 --- 1 file changed, 3 deletions(-) diff --git a/build/Dockerfile b/build/Dockerfile index f919650..d5ab272 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -69,9 +69,6 @@ COPY /docker-entrypoint.sh / # Set up healthcheck. HEALTHCHECK --interval=5m --timeout=30s --retries=3 CMD dst-server version --check -# Expose default server port. -EXPOSE $SERVER_PORT/udp - # Set up a volume for configuration files. VOLUME ["$CLUSTER_PATH"] From 9763713d0d8a05dc602c6733357cd52ea30cf8cd Mon Sep 17 00:00:00 2001 From: Thomas Deinhamer Date: Sun, 22 Oct 2017 14:59:14 +0200 Subject: [PATCH 17/28] Remove logic regarding world-preset configuration and related documentation --- README.md | 3 +-- build/static/boot/world.sh | 18 ------------------ docs/configuration.md | 12 +----------- test/boot-world/run.sh | 12 ------------ 4 files changed, 2 insertions(+), 43 deletions(-) diff --git a/README.md b/README.md index e70f866..697a943 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,7 @@ for the online multi-player survival game [*Don't Starve Together*][website]. ## Features - [x] Configuration via **ENV** variables. -- [x] World presets including **caves**. -- [x] Customized **world generation**. +- [x] Customized **world generation** via `leveldataoverride.lua`. - [x] Mods and custom **mod-configuration**. - [x] Connected worlds via **sharding**. - [x] Control the server directly on the **CLI**. diff --git a/build/static/boot/world.sh b/build/static/boot/world.sh index 93b415c..95b8145 100755 --- a/build/static/boot/world.sh +++ b/build/static/boot/world.sh @@ -12,24 +12,6 @@ rm -f "$file_leveldata_override" if [[ -n "$LEVELDATA_OVERRIDES" ]]; then echo "$LEVELDATA_OVERRIDES" > "$file_leveldata_override" -elif [[ -n "$WORLD_PRESET" ]]; then - validate_option "WORLD_PRESET" SURVIVAL_TOGETHER SURVIVAL_TOGETHER_CLASSIC SURVIVAL_DEFAULT_PLUS COMPLETE_DARKNESS DST_CAVE DST_CAVE_PLUS - - if [[ "$WORLD_PRESET" = "DST_CAVE" ]] || [[ "$WORLD_PRESET" = "DST_CAVE_PLUS" ]]; then - location="cave" - else - location="forest" - fi - - cat <<- EOF > "$file_leveldata_override" -return { - id = "$WORLD_PRESET", - location = "$location", - name="", - desc="", - overrides={}, -} -EOF fi if [[ -f "$file_leveldata_override" ]]; then diff --git a/docs/configuration.md b/docs/configuration.md index 305529e..76b2edc 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -237,20 +237,10 @@ This needs to be the same for the master-server and all slave-servers. - *text* *Example:* `secret-and-equal-for-all-shards` -**WORLD_PRESET** -Defines some pre-configured world settings for the server. -- SURVIVAL_TOGETHER *[default]* -- SURVIVAL_TOGETHER_CLASSIC -- SURVIVAL_DEFAULT_PLUS -- COMPLETE_DARKNESS -- DST_CAVE -- DST_CAVE_PLUS - **LEVELDATA_OVERRIDES** Sets the overrides-configuration for level-data. Basically it's just the content for the `leveldataoverride.lua` file. As this value can be pretty large it's recommended to put the -configuration into a separate file and read it into the variable beforehand. When this is set -`WORLD_PRESET` has no effect. +configuration into a separate file and read it into the variable beforehand. - *string* **MODS** diff --git a/test/boot-world/run.sh b/test/boot-world/run.sh index 09bc786..85fa194 100755 --- a/test/boot-world/run.sh +++ b/test/boot-world/run.sh @@ -35,18 +35,6 @@ docker cp $container_id:/var/lib/dsta/cluster/shard/leveldataoverride.lua $aux | diff $file1 $aux || exit 1 docker rm -fv $container_id > /dev/null -container_id=`docker run -d -e LEVELDATA_OVERRIDES="foo" -e WORLD_PRESET="bar" $1 dst-server start --update=none || exit 1` -sleep 2 -docker cp $container_id:/var/lib/dsta/cluster/shard/leveldataoverride.lua $aux || exit 1 -diff $file1 $aux || exit 1 -docker rm -fv $container_id > /dev/null - -container_id=`docker run -d -e WORLD_PRESET="bar" $1 dst-server start --update=none || exit 1` -sleep 2 -docker cp $container_id:/var/lib/dsta/cluster/shard/leveldataoverride.lua $aux || exit 1 -diff $file2 $aux || exit 1 -docker rm -fv $container_id > /dev/null - container_id=`docker run -d $1 dst-server start --update=none || exit 1` sleep 2 docker cp $container_id:/var/lib/dsta/cluster/shard/leveldataoverride.lua $aux 2> /dev/null && exit 1 From ae8a84c96d14735d9ecd5705af6436d85679d495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brais=20Gab=C3=ADn?= Date: Sun, 22 Oct 2017 21:48:12 +0200 Subject: [PATCH 18/28] Fix tests * Fix boot-token * Fix update.sh script --- build/static/boot/token.sh | 2 +- build/static/dst/update.sh | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build/static/boot/token.sh b/build/static/boot/token.sh index 20a982a..0670c65 100755 --- a/build/static/boot/token.sh +++ b/build/static/boot/token.sh @@ -4,7 +4,7 @@ source "$(dirname "$0")/functions.sh" file_token="$CLUSTER_PATH/cluster_token.txt" -if [[ -f "$file_token" ]] && containsElement "token" "$@"; then +if [[ -f "$file_token" ]] && containsElement "token" $@; then exit 0 fi diff --git a/build/static/dst/update.sh b/build/static/dst/update.sh index e5d9d81..f3c945a 100755 --- a/build/static/dst/update.sh +++ b/build/static/dst/update.sh @@ -3,8 +3,8 @@ exec steamcmd \ +@ShutdownOnFailedCommand 1 \ +login anonymous \ - +force_install_dir "$DST_HOME" \ + +force_install_dir $DST_HOME \ +app_update 343050 \ - "$([ -n "$DST_BRANCH" ] && printf %s "-beta $DST_BRANCH")" \ - "$([ -n "$DST_BRANCH_PASSWORD" ] && printf %s "-betapassword $DST_BRANCH_PASSWORD")" \ + $([ -n "$DST_BRANCH" ] && printf %s "-beta $DST_BRANCH") \ + $([ -n "$DST_BRANCH_PASSWORD" ] && printf %s "-betapassword $DST_BRANCH_PASSWORD") \ +quit From 8946b4f4caec0e86e355f6300682a0e13ce7f8af Mon Sep 17 00:00:00 2001 From: Thomas Deinhamer Date: Sun, 22 Oct 2017 22:32:52 +0200 Subject: [PATCH 19/28] Update healthcheck command parameters --- build/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/Dockerfile b/build/Dockerfile index d5ab272..afa0d26 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -67,7 +67,7 @@ RUN set -x \ COPY /docker-entrypoint.sh / # Set up healthcheck. -HEALTHCHECK --interval=5m --timeout=30s --retries=3 CMD dst-server version --check +HEALTHCHECK --start-period=15m --interval=5m --timeout=1m --retries=3 CMD dst-server version --check # Set up a volume for configuration files. VOLUME ["$CLUSTER_PATH"] From d4a2ec6845fb942a85946228805d5b5fdf65639c Mon Sep 17 00:00:00 2001 From: Thomas Deinhamer Date: Tue, 24 Oct 2017 00:06:08 +0200 Subject: [PATCH 20/28] Update the CHANGELOG --- CHANGELOG.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1be9c1..529ea58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,20 @@ ## [next] +### Added +- Add support for the `leveldataoverride.lua` file via the `LEVELDATA_OVERRIDES` env-variable. +- Configure the Docker `HEALTHCHECK` command running `dst-server version --check`. +- Add a `keep-configuration` boot option to define how existing configuration files should be handled. + +### Changed +- Update the base-image to `dstacademy/steamcmd:0.3`. +- Overwrite configuration files by default when starting a container. +- Do not expose/configure a default port in the `Dockerfile` anymore. + +### Removed +- Remove the `WORLD_OVERRIDES` env-variable and `worldgenoverride.lua` file. +- Remove support for the `WORLD_PRESET` env-variable in favor of `LEVELDATA_OVERRIDES`. + ## [0.7.1] ### Added From 68cfac18c98b2b2e06c153046a761fb1178318f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brais=20Gab=C3=ADn?= Date: Sat, 11 Nov 2017 18:48:01 +0100 Subject: [PATCH 21/28] Ensure running the update command using the steam user --- build/static/dst/update.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build/static/dst/update.sh b/build/static/dst/update.sh index f3c945a..8620684 100755 --- a/build/static/dst/update.sh +++ b/build/static/dst/update.sh @@ -1,5 +1,9 @@ #!/usr/bin/env bash +if [[ "$(whoami)" != "$STEAM_USER" ]]; then + exec gosu "$STEAM_USER" "$0" "$@" +fi + exec steamcmd \ +@ShutdownOnFailedCommand 1 \ +login anonymous \ From 77748c83d84935273e97b2a4f9ed0a1d8c29d247 Mon Sep 17 00:00:00 2001 From: John Dean Date: Sat, 18 Nov 2017 13:53:43 -0800 Subject: [PATCH 22/28] Update cave example --- docs/examples/shard/README.md | 6 + docs/examples/shard/docker-compose.yml | 185 +++++++++++++++++++++++++ docs/examples/shard/underworld.env | 3 - 3 files changed, 191 insertions(+), 3 deletions(-) diff --git a/docs/examples/shard/README.md b/docs/examples/shard/README.md index a0100c6..1dc2ecc 100644 --- a/docs/examples/shard/README.md +++ b/docs/examples/shard/README.md @@ -3,3 +3,9 @@ This setup configures two servers, one overworld and one underworld (caves) which are connected through sinkholes. + +In order to generate caves you need to provide a +leveldataoverride.lua script to configure world generation. +A good starting place is to create a DST server in game and +then copy over the leveldataoverride.lua created in the +local Klei folder for the shard. diff --git a/docs/examples/shard/docker-compose.yml b/docs/examples/shard/docker-compose.yml index 62730aa..9a7557b 100644 --- a/docs/examples/shard/docker-compose.yml +++ b/docs/examples/shard/docker-compose.yml @@ -8,6 +8,123 @@ services: stdin_open: true command: dst-server start --update=all env_file: overworld.env + environment: + # Defined in YAML because multi-line support, but this can also be injected other ways + # From a vanilla survival leveldataoverride.lua + LEVELDATA_OVERRIDES: | + return { + desc="The standard Don't Starve experience.", + hideminimap=false, + id="SURVIVAL_TOGETHER", + location="forest", + max_playlist_position=999, + min_playlist_position=0, + name="Default", + numrandom_set_pieces=4, + ordered_story_setpieces={ "Sculptures_1", "Maxwell5" }, + override_level_string=false, + overrides={ + alternatehunt="default", + angrybees="default", + antliontribute="default", + autumn="default", + bearger="default", + beefalo="default", + beefaloheat="default", + bees="default", + berrybush="default", + birds="default", + boons="default", + branching="default", + butterfly="default", + buzzard="default", + cactus="default", + carrot="default", + catcoon="default", + chess="default", + day="default", + deciduousmonster="default", + deerclops="default", + disease_delay="default", + dragonfly="default", + flint="default", + flowers="default", + frograin="default", + goosemoose="default", + grass="default", + houndmound="default", + hounds="default", + hunt="default", + krampus="default", + layout_mode="LinkNodesByKeys", + liefs="default", + lightning="default", + lightninggoat="default", + loop="default", + lureplants="default", + marshbush="default", + merm="default", + meteorshowers="default", + meteorspawner="default", + moles="default", + mushroom="default", + penguins="default", + perd="default", + petrification="default", + pigs="default", + ponds="default", + prefabswaps_start="default", + rabbits="default", + reeds="default", + regrowth="default", + roads="default", + rock="default", + rock_ice="default", + sapling="default", + season_start="default", + specialevent="default", + spiders="default", + spring="default", + start_location="default", + summer="default", + tallbirds="default", + task_set="default", + tentacles="default", + touchstone="default", + trees="default", + tumbleweed="default", + walrus="default", + weather="default", + wildfires="default", + winter="default", + world_size="default", + wormhole_prefab="wormhole" + }, + random_set_pieces={ + "Sculptures_2", + "Sculptures_3", + "Sculptures_4", + "Sculptures_5", + "Chessy_1", + "Chessy_2", + "Chessy_3", + "Chessy_4", + "Chessy_5", + "Chessy_6", + "Maxwell1", + "Maxwell2", + "Maxwell3", + "Maxwell4", + "Maxwell6", + "Maxwell7", + "Warzone_1", + "Warzone_2", + "Warzone_3" + }, + required_prefabs={ "multiplayer_portal" }, + substitutes={ }, + version=3 + } ports: - "10999:10999/udp" volumes: @@ -20,6 +137,74 @@ services: stdin_open: true command: dst-server start --update=all env_file: underworld.env + environment: + # Defined in YAML because multi-line support, but this can also be injected other ways + # From a vanilla caves leveldataoverride.lua + LEVELDATA_OVERRIDES: | + return { + background_node_range={ 0, 1 }, + desc="Delve into the caves... together!", + hideminimap=false, + id="DST_CAVE", + location="cave", + max_playlist_position=999, + min_playlist_position=0, + name="The Caves", + numrandom_set_pieces=0, + override_level_string=false, + overrides={ + banana="default", + bats="default", + berrybush="default", + boons="default", + branching="default", + bunnymen="default", + cave_ponds="default", + cave_spiders="default", + cavelight="default", + chess="default", + disease_delay="default", + earthquakes="default", + fern="default", + fissure="default", + flint="default", + flower_cave="default", + grass="default", + layout_mode="RestrictNodesByKey", + lichen="default", + liefs="default", + loop="default", + marshbush="default", + monkey="default", + mushroom="default", + mushtree="default", + petrification="default", + prefabswaps_start="default", + reeds="default", + regrowth="default", + roads="never", + rock="default", + rocky="default", + sapling="default", + season_start="default", + slurper="default", + slurtles="default", + start_location="caves", + task_set="cave_default", + tentacles="default", + touchstone="default", + trees="default", + weather="default", + world_size="default", + wormattacks="default", + wormhole_prefab="tentacle_pillar", + wormlights="default", + worms="default" + }, + required_prefabs={ "multiplayer_portal" }, + substitutes={ }, + version=3 + } ports: - "11000:11000/udp" links: diff --git a/docs/examples/shard/underworld.env b/docs/examples/shard/underworld.env index 0253e9c..cc9a270 100644 --- a/docs/examples/shard/underworld.env +++ b/docs/examples/shard/underworld.env @@ -5,9 +5,6 @@ TOKEN=your-server-token NAME=Underworld SERVER_PORT=11000 -# WORLD -WORLD_PRESET=DST_CAVE - # SHARD SHARD_ENABLE=true SHARD_NAME=underworld From ec571ea9a7749f861f569394bc8adb619c4007e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brais=20Gab=C3=ADn?= Date: Wed, 13 Dec 2017 21:30:26 +0100 Subject: [PATCH 23/28] Change mods integration --- build/Dockerfile | 33 +++++++++++++++++++-------- docs/configuration.md | 12 ++++++---- docs/examples/mods/docker-compose.yml | 5 +++- docs/examples/mods/world.env | 1 - test/boot-mods/run.sh | 2 +- test/run.sh | 2 +- 6 files changed, 36 insertions(+), 19 deletions(-) diff --git a/build/Dockerfile b/build/Dockerfile index afa0d26..6bafb6e 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -1,6 +1,16 @@ FROM dstacademy/steamcmd:0.3 MAINTAINER DST Academy +# Install dependencies. +RUN set -x \ + && dpkg --add-architecture i386 \ + && apt-get update \ + && apt-get install -y --no-install-recommends \ + lib32stdc++6 \ + libcurl4-gnutls-dev:i386 \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* + # Set build arguments. ARG DST_HOME ENV DST_HOME ${DST_HOME:-"/opt/dst"} @@ -23,16 +33,6 @@ ENV DESCRIPTION="Powered by DST Academy." \ # Add labels. LABEL academy.dst.config.update="true" -# Install dependencies. -RUN set -x \ - && dpkg --add-architecture i386 \ - && apt-get update \ - && apt-get install -y --no-install-recommends \ - lib32stdc++6 \ - libcurl4-gnutls-dev:i386 \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* - # Install Don't Starve Together Server. RUN set -x \ && mkdir -p $DST_HOME \ @@ -50,6 +50,19 @@ RUN set -x \ && rm -rf $STEAM_HOME/Steam/logs $STEAM_HOME/Steam/appcache/httpcache \ && find $STEAM_HOME/package -type f ! -name "steam_cmd_linux.installed" ! -name "steam_cmd_linux.manifest" -delete +ARG MODS +ENV MODS ${MODS} + +# Install mods. +RUN set -x \ + && if [ -n "$MODS" ] ; then \ + IFS="," \ + && for mod in $MODS; do echo "ServerModSetup(\"$mod\")" >> "$DST_HOME/mods/dedicated_server_mods_setup.lua"; done \ + && cd "$DST_HOME/bin" \ + && gosu $STEAM_USER ./dontstarve_dedicated_server_nullrenderer -only_update_server_mods \ + && rm -r "$STEAM_HOME/.klei" \ + ; fi + # Copy common scripts. COPY /script/* /usr/local/bin/ diff --git a/docs/configuration.md b/docs/configuration.md index 76b2edc..adadfb0 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -25,6 +25,13 @@ NAME=Name MAX_PLAYERS=10 ``` +## Build Arguments + +**MODS** +Defines mods to install and enable. +- *CSV of workshop IDs* + *Example:* `378160973,492173795,407705132` + ## Environment Variables Environment variables can be used to customize certain settings of the server. Most of the available environment variables correspond to the `settings.ini` variables used by DST. @@ -243,11 +250,6 @@ Sets the overrides-configuration for level-data. Basically it's just the content configuration into a separate file and read it into the variable beforehand. - *string* -**MODS** -Defines mods to install and enable. -- *CSV of workshop IDs* - *Example:* `378160973,492173795,407705132` - **MODS_OVERRIDES** Sets the overrides-configuration for all mods. Basically it's just the content for the `modsoverrides.lua` file. As this value can be pretty large it's recommended to put the diff --git a/docs/examples/mods/docker-compose.yml b/docs/examples/mods/docker-compose.yml index 1b8a73c..eb3c8d9 100644 --- a/docs/examples/mods/docker-compose.yml +++ b/docs/examples/mods/docker-compose.yml @@ -1,7 +1,10 @@ version: "2" services: world: - image: dstacademy/dontstarvetogether + build: + context: https://github.com/dst-academy/docker-dontstarvetogether.git#:build + args: + MODS: 378160973,492173795,407705132 container_name: world hostname: world tty: true diff --git a/docs/examples/mods/world.env b/docs/examples/mods/world.env index 72e7634..7d99dc7 100644 --- a/docs/examples/mods/world.env +++ b/docs/examples/mods/world.env @@ -5,5 +5,4 @@ TOKEN=your-server-token NAME=World # MODS -MODS=378160973,492173795,407705132 MODS_OVERRIDES diff --git a/test/boot-mods/run.sh b/test/boot-mods/run.sh index 2cade54..522b4cf 100755 --- a/test/boot-mods/run.sh +++ b/test/boot-mods/run.sh @@ -59,7 +59,7 @@ docker cp $container_id:/var/lib/dsta/cluster/shard/modoverrides.lua $aux || exi diff $modoverrides2 $aux || exit 1 docker rm -fv $container_id > /dev/null -container_id=`docker run -d -e MODS="foo,bar" -e MODS_OVERRIDES="xyz" $1 dst-server start --update=none || exit 1` +container_id=`docker run -d -e MODS="foo,bar" -e MODS_OVERRIDES="xyz" $1 dst-server start --update=none || exit 1` sleep 2 docker cp $container_id:/opt/dst/mods/dedicated_server_mods_setup.lua $aux || exit 1 tail -n 3 $aux > $aux2 diff --git a/test/run.sh b/test/run.sh index 1a002c3..d4ddfa0 100755 --- a/test/run.sh +++ b/test/run.sh @@ -14,7 +14,7 @@ docker build -t $image_name ../build || build_error tests=`mktemp` if [ $# -eq 0 ]; then - find -mindepth 2 -maxdepth 2 -type f -name run.sh > $tests + find . -mindepth 2 -maxdepth 2 -type f -name run.sh > $tests else for test_name in "$@" do From cb9001be8d86e0c12311de22edb58ce4d242d41c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brais=20Gab=C3=ADn?= Date: Sun, 17 Dec 2017 21:47:00 +0100 Subject: [PATCH 24/28] Remove steamcmd test --- test/steamcmd-path/run.sh | 9 --------- 1 file changed, 9 deletions(-) delete mode 100755 test/steamcmd-path/run.sh diff --git a/test/steamcmd-path/run.sh b/test/steamcmd-path/run.sh deleted file mode 100755 index eb8fa01..0000000 --- a/test/steamcmd-path/run.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -clean() { - rm -f $file1 -} -trap clean EXIT - -file1=`mktemp` -docker run --rm $1 steamcmd +quit > $file1 || exit 1 From 8782e1b4681f9e61a7eff1112d0a2395cfc7c6c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Brais=20Gab=C3=ADn?= Date: Mon, 25 Dec 2017 22:06:51 +0100 Subject: [PATCH 25/28] Refactor test-suite using bats --- .travis.yml | 5 +- test/README.md | 19 - test/attach-console/run.sh | 29 - test/boot-aux/run.sh | 66 -- test/boot-lists/run.sh | 95 --- test/boot-mods/run.sh | 79 -- test/boot-token/run.sh | 55 -- test/boot-world/run.sh | 87 --- test/close-cleanly/run.sh | 48 -- test/console/run.sh | 20 - test/dsta-console/commands1.txt | 2 - test/dsta-console/commands2.txt | 2 - test/dsta-console/commands3.txt | 2 - test/dsta-console/commands4.txt | 2 - test/dsta-console/run.sh | 40 - test/dsta-help/run.sh | 131 ---- test/dsta-log/run.sh | 52 -- test/dsta-start/run.sh | 88 --- test/dsta-update/run.sh | 44 -- test/dsta-version/run.sh | 41 - test/entrypoint-other/run.sh | 15 - test/mods-install/run.sh | 17 - test/run.sh | 45 -- tests/README.md | 7 + tests/attach-console.bats | 23 + tests/boot-aux.bats | 178 +++++ tests/boot-lists.bats | 159 ++++ tests/boot-mods.bats | 53 ++ tests/boot-token.bats | 106 +++ tests/boot-world.bats | 83 ++ tests/build-mods.bats | 21 + tests/close-cleanly.bats | 45 ++ tests/console.bats | 16 + tests/dependencies/bats-assert/assert.bash | 720 ++++++++++++++++++ tests/dependencies/bats-support/error.bash | 41 + tests/dependencies/bats-support/lang.bash | 73 ++ tests/dependencies/bats-support/output.bash | 279 +++++++ tests/dependencies/load.bash | 6 + tests/dsta-console.bats | 71 ++ tests/dsta-help.bats | 181 +++++ tests/dsta-log.bats | 60 ++ tests/dsta-start.bats | 82 ++ tests/dsta-update.bats | 79 ++ tests/dsta-version.bats | 36 + tests/entrypoint.bats | 19 + tests/fixtures/boot-lists/bar.txt | 1 + tests/fixtures/boot-lists/foo.txt | 1 + tests/fixtures/boot-lists/list.txt | 3 + .../dedicated_server_mods_setup.lua-tail | 2 + .../foo-bar-with-overrides/modoverrides.lua | 1 + .../dedicated_server_mods_setup.lua-tail | 2 + .../boot-mods/foo-bar/modoverrides.lua | 4 + .../foo/dedicated_server_mods_setup.lua-tail | 1 + tests/fixtures/boot-mods/foo/modoverrides.lua | 3 + tests/fixtures/boot-token/token1 | 1 + tests/fixtures/boot-token/token2 | 1 + tests/fixtures/boot-world/foo | 1 + tests/fixtures/boot-world/foo2 | 1 + .../one-mod/dedicated_server_mods_setup.lua | 12 + .../two-mods/dedicated_server_mods_setup.lua | 13 + .../fixtures}/close-cleanly/commands.sh | 0 {test => tests/fixtures}/console/commands.sh | 2 +- tests/fixtures/dsta-console/commands.txt | 2 + tests/fixtures/dsta-help/console | 5 + tests/fixtures/dsta-help/dst-server | 10 + tests/fixtures/dsta-help/log | 1 + tests/fixtures/dsta-help/start | 22 + tests/fixtures/dsta-help/update | 1 + tests/fixtures/dsta-help/version | 10 + tests/fixtures/dsta-log/empty-file | 0 tests/fixtures/dsta-log/server_log.txt | 1 + tests/fixtures/dsta-log/server_log_chat.txt | 1 + tests/test_helper.bash | 32 + 73 files changed, 2474 insertions(+), 982 deletions(-) delete mode 100644 test/README.md delete mode 100755 test/attach-console/run.sh delete mode 100755 test/boot-aux/run.sh delete mode 100755 test/boot-lists/run.sh delete mode 100755 test/boot-mods/run.sh delete mode 100755 test/boot-token/run.sh delete mode 100755 test/boot-world/run.sh delete mode 100755 test/close-cleanly/run.sh delete mode 100755 test/console/run.sh delete mode 100644 test/dsta-console/commands1.txt delete mode 100644 test/dsta-console/commands2.txt delete mode 100644 test/dsta-console/commands3.txt delete mode 100644 test/dsta-console/commands4.txt delete mode 100755 test/dsta-console/run.sh delete mode 100755 test/dsta-help/run.sh delete mode 100755 test/dsta-log/run.sh delete mode 100755 test/dsta-start/run.sh delete mode 100755 test/dsta-update/run.sh delete mode 100755 test/dsta-version/run.sh delete mode 100755 test/entrypoint-other/run.sh delete mode 100755 test/mods-install/run.sh delete mode 100755 test/run.sh create mode 100644 tests/README.md create mode 100644 tests/attach-console.bats create mode 100644 tests/boot-aux.bats create mode 100644 tests/boot-lists.bats create mode 100644 tests/boot-mods.bats create mode 100644 tests/boot-token.bats create mode 100644 tests/boot-world.bats create mode 100644 tests/build-mods.bats create mode 100644 tests/close-cleanly.bats create mode 100644 tests/console.bats create mode 100755 tests/dependencies/bats-assert/assert.bash create mode 100755 tests/dependencies/bats-support/error.bash create mode 100755 tests/dependencies/bats-support/lang.bash create mode 100755 tests/dependencies/bats-support/output.bash create mode 100644 tests/dependencies/load.bash create mode 100644 tests/dsta-console.bats create mode 100644 tests/dsta-help.bats create mode 100644 tests/dsta-log.bats create mode 100644 tests/dsta-start.bats create mode 100644 tests/dsta-update.bats create mode 100644 tests/dsta-version.bats create mode 100644 tests/entrypoint.bats create mode 100644 tests/fixtures/boot-lists/bar.txt create mode 100644 tests/fixtures/boot-lists/foo.txt create mode 100644 tests/fixtures/boot-lists/list.txt create mode 100644 tests/fixtures/boot-mods/foo-bar-with-overrides/dedicated_server_mods_setup.lua-tail create mode 100644 tests/fixtures/boot-mods/foo-bar-with-overrides/modoverrides.lua create mode 100644 tests/fixtures/boot-mods/foo-bar/dedicated_server_mods_setup.lua-tail create mode 100644 tests/fixtures/boot-mods/foo-bar/modoverrides.lua create mode 100644 tests/fixtures/boot-mods/foo/dedicated_server_mods_setup.lua-tail create mode 100644 tests/fixtures/boot-mods/foo/modoverrides.lua create mode 100644 tests/fixtures/boot-token/token1 create mode 100644 tests/fixtures/boot-token/token2 create mode 100644 tests/fixtures/boot-world/foo create mode 100644 tests/fixtures/boot-world/foo2 create mode 100644 tests/fixtures/build-mods/one-mod/dedicated_server_mods_setup.lua create mode 100644 tests/fixtures/build-mods/two-mods/dedicated_server_mods_setup.lua rename {test => tests/fixtures}/close-cleanly/commands.sh (100%) rename {test => tests/fixtures}/console/commands.sh (57%) create mode 100644 tests/fixtures/dsta-console/commands.txt create mode 100644 tests/fixtures/dsta-help/console create mode 100644 tests/fixtures/dsta-help/dst-server create mode 100644 tests/fixtures/dsta-help/log create mode 100644 tests/fixtures/dsta-help/start create mode 100644 tests/fixtures/dsta-help/update create mode 100644 tests/fixtures/dsta-help/version create mode 100644 tests/fixtures/dsta-log/empty-file create mode 100644 tests/fixtures/dsta-log/server_log.txt create mode 100644 tests/fixtures/dsta-log/server_log_chat.txt create mode 100644 tests/test_helper.bash diff --git a/.travis.yml b/.travis.yml index bc9ff1a..5d89c4a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,12 +10,13 @@ env: before_install: - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" + - sudo add-apt-repository ppa:duggan/bats --yes - sudo apt-get update - - sudo apt-get -y install docker-ce + - sudo apt-get -y install docker-ce bats script: - docker build -t $DOCKER_IMAGE_NAME ./build - - ./test/run.sh + - bats tests notifications: slack: diff --git a/test/README.md b/test/README.md deleted file mode 100644 index c8f5834..0000000 --- a/test/README.md +++ /dev/null @@ -1,19 +0,0 @@ -# Test Suite - -## How to run the tests -```sh -./run.sh -``` - -### How to run a specific test or tests -```sh -./run.sh ... -``` - -## How to write a tests -You must create a directory inside this and add a `run.sh` script to check whatever you want. Things -to have in mind: -* You are going to be called with the name of the image in `$1`. -* You can create all the containers and volumes that you want, but you must be sure to delete all of -them before you leave the script. -* If the test pass you must exit with a `0` otherwise with something different of `0` diff --git a/test/attach-console/run.sh b/test/attach-console/run.sh deleted file mode 100755 index afd38e2..0000000 --- a/test/attach-console/run.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bash - -clean() { - rm -f $file1 - if [ -n "$container_id" ] && [ -n "`docker ps -qf id=$container_id`" ]; then - docker rm -fv $container_id >/dev/null - fi -} -trap clean EXIT - -file1=`mktemp` - -timeout --kill-after 1 20 docker run -i --rm $1 dst-server start --update=none >/dev/null <<-EOF - c_shutdown(true) -EOF - -if [[ $? -ne 0 ]]; then - exit 1 -fi - -container_id=`docker run -id $1 dst-server start --update=none || exit 1` -docker attach $container_id <<-EOF - c_shutdown(true) -EOF -timeout --kill-after 1 20 docker wait $container_id >/dev/null || exit 1 -docker cp $container_id:/var/lib/dsta/cluster/shard/server_log.txt $file1 -docker rm -fv $container_id >/dev/null - -grep -Fq "RemoteCommandInput: \"c_shutdown(true)\"" $file1 || exit 1 diff --git a/test/boot-aux/run.sh b/test/boot-aux/run.sh deleted file mode 100755 index e9fb8f6..0000000 --- a/test/boot-aux/run.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env bash - -source ../build/static/boot/functions.sh - -export FOO="" -validate_bool FOO || exit 1 -export FOO="true" -validate_bool FOO || exit 1 -export FOO="false" -validate_bool FOO || exit 1 -export FOO="bar" -validate_bool FOO 2> /dev/null && exit 1 - -export FOO="" -validate_int FOO 1 10 || exit 1 -export FOO="1" -validate_int FOO 1 10 || exit 1 -export FOO="5" -validate_int FOO 1 10 || exit 1 -export FOO="10" -validate_int FOO 1 10 || exit 1 -export FOO="0" -validate_int FOO 1 10 2> /dev/null && exit 1 -export FOO="11" -validate_int FOO 1 10 2> /dev/null && exit 1 -export FOO="1100" -validate_int FOO 1 10 2> /dev/null && exit 1 - -export FOO="" -validate_port FOO || exit 1 -export FOO="1" -validate_port FOO || exit 1 -export FOO="10999" -validate_port FOO || exit 1 -export FOO="65535" -validate_port FOO || exit 1 -export FOO="0" -validate_port FOO 2> /dev/null && exit 1 -export FOO="65536" -validate_port FOO 2> /dev/null && exit 1 -export FOO="655350" -validate_port FOO 2> /dev/null && exit 1 - -export FOO="" -validate_option FOO a b c || exit 1 -export FOO="a" -validate_option FOO a b c || exit 1 -export FOO="b" -validate_option FOO a b c || exit 1 -export FOO="c" -validate_option FOO a b c || exit 1 -export FOO="d" -validate_option FOO a b c 2> /dev/null && exit 1 -export FOO="1" -validate_option FOO a b c 2> /dev/null && exit 1 -export FOO="1" -validate_option FOO 1 2 3 || exit 1 -export FOO="2" -validate_option FOO 1 2 3 || exit 1 -export FOO="3" -validate_option FOO 1 2 3 || exit 1 -export FOO="4" -validate_option FOO 1 2 3 2> /dev/null && exit 1 -export FOO="a" -validate_option FOO 1 2 3 2> /dev/null && exit 1 -exit 0 diff --git a/test/boot-lists/run.sh b/test/boot-lists/run.sh deleted file mode 100755 index efd2d3c..0000000 --- a/test/boot-lists/run.sh +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/env bash - -clean() { - rm -f $aux $adminlist $whitelist $blocklist $foo $foo2 - if [ -n "`docker ps -qf id=$container_id`" ]; then - docker rm -fv $container_id >/dev/null - fi - docker volume rm $volume >/dev/null 2>/dev/null || exit 0 -} -trap clean EXIT - -volume="boot-lists" -aux=`mktemp` -adminlist=`mktemp` -whitelist=`mktemp` -blocklist=`mktemp` -foo=`mktemp` -foo2=`mktemp` - -printf "foo\nbar\nxy_:z\n" >$adminlist -printf "foo\n" >$whitelist -printf "foo\nbar\n" >$blocklist -printf "foo\n" >$foo -printf "foo2\n" >$foo2 - -container_id=`docker run -d -e ADMINLIST="foo,bar,xy_:z" -e WHITELIST="foo" -e BLOCKLIST="foo,bar" $1 dst-server start --update=none || exit 1` -sleep 20 -docker cp $container_id:/var/lib/dsta/cluster/adminlist.txt $aux || exit 1 -diff $adminlist $aux || exit 1 -docker cp $container_id:/var/lib/dsta/cluster/whitelist.txt $aux || exit 1 -diff $whitelist $aux || exit 1 -docker cp $container_id:/var/lib/dsta/cluster/blocklist.txt $aux || exit 1 -diff $blocklist $aux || exit 1 -docker cp $container_id:/var/lib/dsta/cluster/shard/server_log.txt $aux || exit 1 -cat $aux | grep "adminlist.txt" | grep -qF "(Success)" || exit 1 -cat $aux | grep "whitelist.txt" | grep -qF "(Success)" || exit 1 -cat $aux | grep "blocklist.txt" | grep -qF "(Success)" || exit 1 -docker rm -fv $container_id >/dev/null - -container_id=`docker run -d -e BLOCKLIST="foo,bar" $1 dst-server start --update=none || exit 1` -sleep 2 -docker cp $container_id:/var/lib/dsta/cluster/adminlist.txt $aux 2>/dev/null && exit 1 -docker cp $container_id:/var/lib/dsta/cluster/whitelist.txt $aux 2>/dev/null && exit 1 -docker cp $container_id:/var/lib/dsta/cluster/blocklist.txt $aux || exit 1 -diff $blocklist $aux || exit 1 -docker rm -fv $container_id >/dev/null - -test_lists_with_keep(){ - docker_image=$1 - variable=$2 - keep_flag=$3 - file_name=$3 - - container_id=`docker run -d -v $volume:/var/lib/dsta/cluster -e $variable="foo" $docker_image dst-server start --update=none || exit 1` - sleep 2 - docker cp $container_id:/var/lib/dsta/cluster/$file_name.txt $aux || exit 1 - diff $foo $aux || exit 1 - docker rm -fv $container_id >/dev/null - docker volume rm $volume > /dev/null - - container_id=`docker run -d -v $volume:/var/lib/dsta/cluster -e $variable="foo2" $docker_image dst-server start --update=none --keep-configuration=$keep_flag || exit 1` - sleep 2 - docker cp $container_id:/var/lib/dsta/cluster/$file_name.txt $aux || exit 1 - diff $foo2 $aux || exit 1 - docker rm -fv $container_id >/dev/null - - container_id=`docker run -d -v $volume:/var/lib/dsta/cluster $docker_image dst-server start --update=none --keep-configuration=$keep_flag || exit 1` - sleep 2 - docker cp $container_id:/var/lib/dsta/cluster/$file_name.txt $aux || exit 1 - diff $foo2 $aux || exit 1 - docker rm -fv $container_id >/dev/null - - container_id=`docker run -d -v $volume:/var/lib/dsta/cluster -e $variable="foo" $docker_image dst-server start --update=none || exit 1` - sleep 2 - docker cp $container_id:/var/lib/dsta/cluster/$file_name.txt $aux || exit 1 - diff $foo $aux || exit 1 - docker rm -fv $container_id >/dev/null - - container_id=`docker run -d -v $volume:/var/lib/dsta/cluster -e $variable="foo2" $docker_image dst-server start --update=none --keep-configuration=$keep_flag || exit 1` - sleep 2 - docker cp $container_id:/var/lib/dsta/cluster/$file_name.txt $aux || exit 1 - diff $foo $aux || exit 1 - docker rm -fv $container_id >/dev/null - - container_id=`docker run -d -v $volume:/var/lib/dsta/cluster $docker_image dst-server start --update=none || exit 1` - sleep 2 - docker cp $container_id:/var/lib/dsta/cluster/$file_name.txt $aux 2>/dev/null && exit 1 - diff $foo $aux || exit 1 - docker rm -fv $container_id >/dev/null - docker volume rm $volume > /dev/null -} - -test_lists_with_keep $1 ADMINLIST adminlist -test_lists_with_keep $1 WHITELIST whitelist -test_lists_with_keep $1 BLOCKLIST blocklist diff --git a/test/boot-mods/run.sh b/test/boot-mods/run.sh deleted file mode 100755 index 522b4cf..0000000 --- a/test/boot-mods/run.sh +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env bash - -clean() { - rm -f $aux $aux2 $mods_setup1 $mods_setup2 $mods_setup3 $modoverrides1 $modoverrides2 $modoverrides3 - if [ -n "`docker ps -qf id=$container_id`" ]; then - docker rm -fv $container_id > /dev/null - fi -} -trap clean EXIT - -aux=`mktemp` -aux2=`mktemp` -mods_setup1=`mktemp` -mods_setup2=`mktemp` -mods_setup3=`mktemp` -modoverrides1=`mktemp` -modoverrides2=`mktemp` -modoverrides3=`mktemp` - -cat <<- EOF > $mods_setup1 -ServerModSetup("foo") -EOF -cat <<- EOF > $mods_setup2 -ServerModSetup("foo") -ServerModSetup("bar") -EOF -cat <<- EOF > $mods_setup3 -ServerModSetup("foo") -ServerModSetup("bar") -EOF -cat <<- EOF > $modoverrides1 -return { - ["workshop-foo"] = { enabled = true }, -} -EOF -cat <<- EOF > $modoverrides2 -return { - ["workshop-foo"] = { enabled = true }, - ["workshop-bar"] = { enabled = true }, -} -EOF -echo "xyz" > $modoverrides3 - -container_id=`docker run -d -e MODS="foo" $1 dst-server start --update=none || exit 1` -sleep 2 -docker cp $container_id:/opt/dst/mods/dedicated_server_mods_setup.lua $aux || exit 1 -tail -n 2 $aux > $aux2 -diff $mods_setup1 $aux2 || exit 1 -docker cp $container_id:/var/lib/dsta/cluster/shard/modoverrides.lua $aux || exit 1 -diff $modoverrides1 $aux || exit 1 -docker rm -fv $container_id > /dev/null - -container_id=`docker run -d -e MODS="foo,bar" $1 dst-server start --update=none || exit 1` -sleep 2 -docker cp $container_id:/opt/dst/mods/dedicated_server_mods_setup.lua $aux || exit 1 -tail -n 3 $aux > $aux2 -diff $mods_setup2 $aux2 || exit 1 -docker cp $container_id:/var/lib/dsta/cluster/shard/modoverrides.lua $aux || exit 1 -diff $modoverrides2 $aux || exit 1 -docker rm -fv $container_id > /dev/null - -container_id=`docker run -d -e MODS="foo,bar" -e MODS_OVERRIDES="xyz" $1 dst-server start --update=none || exit 1` -sleep 2 -docker cp $container_id:/opt/dst/mods/dedicated_server_mods_setup.lua $aux || exit 1 -tail -n 3 $aux > $aux2 -diff $mods_setup3 $aux2 || exit 1 -docker cp $container_id:/var/lib/dsta/cluster/shard/modoverrides.lua $aux || exit 1 -diff $modoverrides3 $aux || exit 1 -docker rm -fv $container_id > /dev/null - -container_id=`docker run -d $1 -e MODS_OVERRIDES="xyz" dst-server start --update=none || exit 1` -sleep 2 -docker cp $container_id:/var/lib/dsta/cluster/shard/modoverrides.lua $aux 2> /dev/null && exit 1 -docker rm -fv $container_id > /dev/null - -container_id=`docker run -d $1 dst-server start --update=none || exit 1` -sleep 2 -docker cp $container_id:/var/lib/dsta/cluster/shard/modoverrides.lua $aux 2> /dev/null && exit 1 -docker rm -fv $container_id > /dev/null diff --git a/test/boot-token/run.sh b/test/boot-token/run.sh deleted file mode 100755 index fe34ef5..0000000 --- a/test/boot-token/run.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env bash - -clean() { - rm -f $aux $token1 $token2 - if [ -n "`docker ps -qf id=$container_id`" ]; then - docker rm -fv $container_id >/dev/null - fi - docker volume rm $volume >/dev/null 2>/dev/null || exit 0 -} -trap clean EXIT - -volume="boot-token" -aux=`mktemp` -token1=`mktemp` -token2=`mktemp` - -printf "token-1" > $token1 -printf "token-2" > $token2 - -container_id=`docker run -d -v $volume:/var/lib/dsta/cluster -e TOKEN="token-1" $1 dst-server start --update=none || exit 1` -sleep 2 -docker cp $container_id:/var/lib/dsta/cluster/cluster_token.txt $aux || exit 1 -diff $token1 $aux || exit 1 -docker rm -fv $container_id > /dev/null -docker volume rm $volume > /dev/null - -container_id=`docker run -d -v $volume:/var/lib/dsta/cluster -e TOKEN="token-2" $1 dst-server start --update=none --keep-configuration=token || exit 1` -sleep 2 -docker cp $container_id:/var/lib/dsta/cluster/cluster_token.txt $aux || exit 1 -diff $token2 $aux || exit 1 -docker rm -fv $container_id > /dev/null - -container_id=`docker run -d -v $volume:/var/lib/dsta/cluster $1 dst-server start --update=none --keep-configuration=token,whitelist || exit 1` -sleep 2 -docker cp $container_id:/var/lib/dsta/cluster/cluster_token.txt $aux || exit 1 -diff $token2 $aux || exit 1 -docker rm -fv $container_id > /dev/null # No remove volume - -container_id=`docker run -d -v $volume:/var/lib/dsta/cluster -e TOKEN="token-1" $1 dst-server start --update=none --keep-configuration=whitelist || exit 1` -sleep 2 -docker cp $container_id:/var/lib/dsta/cluster/cluster_token.txt $aux || exit 1 -diff $token1 $aux || exit 1 -docker rm -fv $container_id > /dev/null # No remove volume - -container_id=`docker run -d -v $volume:/var/lib/dsta/cluster -e TOKEN="token-3" $1 dst-server start --update=none --keep-configuration=token,whitelist || exit 1` -sleep 2 -docker cp $container_id:/var/lib/dsta/cluster/cluster_token.txt $aux || exit 1 -diff $token1 $aux || exit 1 -docker rm -fv $container_id > /dev/null - -container_id=`docker run -d -v $volume:/var/lib/dsta/cluster $1 dst-server start --update=none || exit 1` -sleep 2 -docker cp $container_id:/var/lib/dsta/cluster/cluster_token.txt 2>/dev/null $aux && exit 1 -docker rm -fv $container_id > /dev/null -docker volume rm $volume > /dev/null diff --git a/test/boot-world/run.sh b/test/boot-world/run.sh deleted file mode 100755 index 85fa194..0000000 --- a/test/boot-world/run.sh +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/env bash - -clean() { - rm -f $aux $file1 $file2 $foo $foo2 - if [ -n "`docker ps -qf id=$container_id`" ]; then - docker rm -fv $container_id > /dev/null - fi - docker volume rm $volume >/dev/null 2>/dev/null || exit 0 -} -trap clean EXIT - -volume="boot-world" -aux=`mktemp` -file1=`mktemp` -file2=`mktemp` -foo=`mktemp` -foo2=`mktemp` - -echo "foo" > $file1 -cat <<- EOF > $file2 -return { - id = "bar", - location = "forest", - name="", - desc="", - overrides={}, -} -EOF -printf "foo\n" >$foo -printf "foo2\n" >$foo2 - -container_id=`docker run -d -e LEVELDATA_OVERRIDES="foo" $1 dst-server start --update=none || exit 1` -sleep 2 -docker cp $container_id:/var/lib/dsta/cluster/shard/leveldataoverride.lua $aux || exit 1 -diff $file1 $aux || exit 1 -docker rm -fv $container_id > /dev/null - -container_id=`docker run -d $1 dst-server start --update=none || exit 1` -sleep 2 -docker cp $container_id:/var/lib/dsta/cluster/shard/leveldataoverride.lua $aux 2> /dev/null && exit 1 -docker rm -fv $container_id > /dev/null - -test_world_with_keep(){ - docker_image=$1 - variable=$2 - keep_flag=$3 - - container_id=`docker run -d -v $volume:/var/lib/dsta/cluster -e $variable="foo" $docker_image dst-server start --update=none || exit 1` - sleep 2 - docker cp $container_id:/var/lib/dsta/cluster/shard/leveldataoverride.lua $aux || exit 1 - diff $foo $aux || exit 1 - docker rm -fv $container_id >/dev/null - docker volume rm $volume > /dev/null - - container_id=`docker run -d -v $volume:/var/lib/dsta/cluster -e $variable="foo2" $docker_image dst-server start --update=none --keep-configuration=$keep_flag || exit 1` - sleep 2 - docker cp $container_id:/var/lib/dsta/cluster/shard/leveldataoverride.lua $aux || exit 1 - diff $foo2 $aux || exit 1 - docker rm -fv $container_id >/dev/null - - container_id=`docker run -d -v $volume:/var/lib/dsta/cluster $docker_image dst-server start --update=none --keep-configuration=$keep_flag || exit 1` - sleep 2 - docker cp $container_id:/var/lib/dsta/cluster/shard/leveldataoverride.lua $aux || exit 1 - diff $foo2 $aux || exit 1 - docker rm -fv $container_id >/dev/null - - container_id=`docker run -d -v $volume:/var/lib/dsta/cluster -e $variable="foo" $docker_image dst-server start --update=none || exit 1` - sleep 2 - docker cp $container_id:/var/lib/dsta/cluster/shard/leveldataoverride.lua $aux || exit 1 - diff $foo $aux || exit 1 - docker rm -fv $container_id >/dev/null - - container_id=`docker run -d -v $volume:/var/lib/dsta/cluster -e $variable="foo2" $docker_image dst-server start --update=none --keep-configuration=$keep_flag || exit 1` - sleep 2 - docker cp $container_id:/var/lib/dsta/cluster/shard/leveldataoverride.lua $aux || exit 1 - diff $foo $aux || exit 1 - docker rm -fv $container_id >/dev/null - - container_id=`docker run -d -v $volume:/var/lib/dsta/cluster $docker_image dst-server start --update=none || exit 1` - sleep 2 - docker cp $container_id:/var/lib/dsta/cluster/shard/leveldataoverride.lua $aux 2>/dev/null && exit 1 - diff $foo $aux || exit 1 - docker rm -fv $container_id >/dev/null - docker volume rm $volume > /dev/null -} - -test_world_with_keep $1 LEVELDATA_OVERRIDES world diff --git a/test/close-cleanly/run.sh b/test/close-cleanly/run.sh deleted file mode 100755 index 98406c0..0000000 --- a/test/close-cleanly/run.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env bash - -clean() { - rm -f $file1 - if [ -n "`docker ps -qf id=$container_id`" ]; then - docker rm -fv $container_id > /dev/null - fi -} -trap clean EXIT - -file1=`mktemp` - -container_id=`docker run -d $1 dst-server start --update=none || exit 1` -sleep 20 -docker stop $container_id >/dev/null || exit 1 -docker cp $container_id:/var/lib/dsta/cluster/shard/server_log.txt $file1 -docker rm -fv $container_id > /dev/null -grep -q "Shutting down$" $file1 || exit 1 - -# Dirty console -container_id=`docker run -d $1 dst-server start --update=none || exit 1` -sleep 20 -docker cp close-cleanly/commands.sh $container_id:/ -docker exec $container_id /commands.sh || exit 1 -docker stop $container_id >/dev/null || exit 1 -docker cp $container_id:/var/lib/dsta/cluster/shard/server_log.txt $file1 -docker rm -fv $container_id > /dev/null -grep -q "Shutting down$" $file1 || exit 1 - -# TERM -container_id=`docker run -d $1 dst-server start --update=none || exit 1` -sleep 20 -docker exec $container_id bash -c "kill 1" -timeout --kill-after 1 12 docker wait $container_id > $file1 -grep -q "^0$" $file1 || exit 1 -docker cp $container_id:/var/lib/dsta/cluster/shard/server_log.txt $file1 -docker rm -fv $container_id > /dev/null -grep -q "Shutting down$" $file1 || exit 1 - -# INT -container_id=`docker run -d $1 dst-server start --update=none || exit 1` -sleep 20 -docker exec $container_id bash -c "kill -SIGINT 1" -timeout --kill-after 1 12 docker wait $container_id > $file1 -grep -q "^0$" $file1 || exit 1 -docker cp $container_id:/var/lib/dsta/cluster/shard/server_log.txt $file1 -docker rm -fv $container_id > /dev/null -grep -q "Shutting down$" $file1 || exit 1 diff --git a/test/console/run.sh b/test/console/run.sh deleted file mode 100755 index 6703e78..0000000 --- a/test/console/run.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env bash - -clean() { - rm -f $file1 - if [ -n "`docker ps -qf id=$container_id`" ]; then - docker rm -fv $container_id > /dev/null - fi -} -trap clean EXIT - -file1=`mktemp` - -container_id=`docker run -d $1 dst-server start --update=none || exit 1` -docker cp console/commands.sh $container_id:/ -docker exec $container_id /commands.sh || exit 1 -sleep 20 -docker cp $container_id:/var/lib/dsta/cluster/shard/server_log.txt $file1 -grep -Fq "RemoteCommandInput: \"foo\"" $file1 || exit 1 -grep -Fq "RemoteCommandInput: \"bar\"" $file1 || exit 1 -docker rm -fv $container_id > /dev/null diff --git a/test/dsta-console/commands1.txt b/test/dsta-console/commands1.txt deleted file mode 100644 index 32ef2ce..0000000 --- a/test/dsta-console/commands1.txt +++ /dev/null @@ -1,2 +0,0 @@ -foo 1 -bar1 diff --git a/test/dsta-console/commands2.txt b/test/dsta-console/commands2.txt deleted file mode 100644 index 8bb29a9..0000000 --- a/test/dsta-console/commands2.txt +++ /dev/null @@ -1,2 +0,0 @@ -foo 2 -bar2 diff --git a/test/dsta-console/commands3.txt b/test/dsta-console/commands3.txt deleted file mode 100644 index 721888b..0000000 --- a/test/dsta-console/commands3.txt +++ /dev/null @@ -1,2 +0,0 @@ -foo 3 -bar3 diff --git a/test/dsta-console/commands4.txt b/test/dsta-console/commands4.txt deleted file mode 100644 index c471b5d..0000000 --- a/test/dsta-console/commands4.txt +++ /dev/null @@ -1,2 +0,0 @@ -foo 4 -bar4 diff --git a/test/dsta-console/run.sh b/test/dsta-console/run.sh deleted file mode 100755 index 0cc7ed4..0000000 --- a/test/dsta-console/run.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env bash - -clean() { - rm -f $file1 - if [ -n "`docker ps -qf id=$container_id`" ]; then - docker rm -fv $container_id > /dev/null - fi -} -trap clean EXIT - -file1=`mktemp` - -container_id=`docker run -d $1 dst-server start --update=none || exit 1` -docker exec -i $container_id dst-server console < dsta-console/commands1.txt || exit 1 -docker exec -i $container_id dst-server console - < dsta-console/commands2.txt || exit 1 -docker exec -i $container_id dst-server console "asdf" || exit 1 -docker exec -i $container_id dst-server console "abcde" - "aaaaa" < dsta-console/commands3.txt || exit 1 -docker exec -i $container_id dst-server console "xyz as" "1234" < dsta-console/commands4.txt || exit 1 -sleep 20 -docker cp $container_id:/var/lib/dsta/cluster/shard/server_log.txt $file1 -docker rm -fv $container_id > /dev/null - -grep -Fq "RemoteCommandInput: \"foo 1\"" $file1 || exit 1 -grep -Fq "RemoteCommandInput: \"bar1\"" $file1 || exit 1 - -grep -Fq "RemoteCommandInput: \"foo 2\"" $file1 || exit 1 -grep -Fq "RemoteCommandInput: \"bar2\"" $file1 || exit 1 - -grep -Fq "RemoteCommandInput: \"asdf\"" $file1 || exit 1 - -grep -Fq "RemoteCommandInput: \"abcde\"" $file1 || exit 1 -grep -Fq "RemoteCommandInput: \"foo 3\"" $file1 || exit 1 -grep -Fq "RemoteCommandInput: \"bar3\"" $file1 || exit 1 -grep -Fq "RemoteCommandInput: \"aaaaa\"" $file1 || exit 1 - -grep -Fq "RemoteCommandInput: \"xyz as\"" $file1 || exit 1 -grep -Fq "RemoteCommandInput: \"1234\"" $file1 || exit 1 -grep -Fq "RemoteCommandInput: \"foo 4\"" $file1 && exit 1 -grep -Fq "RemoteCommandInput: \"bar4\"" $file1 && exit 1 -exit 0 diff --git a/test/dsta-help/run.sh b/test/dsta-help/run.sh deleted file mode 100755 index 1ff84a2..0000000 --- a/test/dsta-help/run.sh +++ /dev/null @@ -1,131 +0,0 @@ -#!/usr/bin/env bash - -clean() { - rm -f $file1 $file2 -} -trap clean EXIT - -file1=`mktemp` -file2=`mktemp` - -# dst-server -cat > $file1 <<- EOF -usage: dst-server [--help] [] - -The commands are: - start Start the server - console Execute commands on the server console - update Update game and/or mods - log Show a log - version Show the current server version - -See 'dst-server help ' to read about a specific command. -EOF - -docker run --rm -e NAME=bar $1 dst-server > $file2 && exit 1 -diff $file1 $file2 || exit 1 - -docker run --rm -e NAME=bar $1 dst-server help > $file2 || exit 1 -diff $file1 $file2 || exit 1 - -docker run --rm -e NAME=bar $1 dst-server --help > $file2 || exit 1 -diff $file1 $file2 || exit 1 - -docker run --rm -e NAME=bar $1 dst-server --foo 2> $file2 && exit 1 -diff $file1 $file2 || exit 1 - -docker run --rm -e NAME=bar $1 dst-server foo 2> $file2 && exit 1 -diff $file1 $file2 || exit 1 - -# dst-server start -cat > $file1 <<- EOF -usage: dst-server start [--update=all|none|game|mods] - [--keep-configuration=]...>] - - --update=none - Update nothing, just start the server. This is the default behaviour. - --update=all - Update the game and the mods before launch the server. - --update=game - Update just the game (no the mods) and launch the server. - --update=mods - Update the mods and launch the server. - --keep-configuration - Select which configuration you don't want to overwrite. - You must provide one or more of these values separated by commas: - - token - - cluster - - server - - world - - adminlist - - blocklist - - whitelist - - mods -EOF - -docker run --rm -e NAME=bar $1 dst-server help start > $file2 || exit 1 -diff $file1 $file2 || exit 1 - -docker run --rm -e NAME=bar $1 dst-server --help start > $file2 || exit 1 -diff $file1 $file2 || exit 1 - -docker run --rm -e NAME=bar $1 dst-server start --help > $file2 || exit 1 -diff $file1 $file2 || exit 1 - -docker run --rm -e NAME=bar $1 dst-server start --help foo > $file2 || exit 1 -diff $file1 $file2 || exit 1 - -# dst-server update -cat > $file1 <<- EOF -usage: dst-server update [--all|--game|--mods] -EOF - -docker run --rm -e NAME=bar $1 dst-server help update > $file2 || exit 1 -diff $file1 $file2 || exit 1 - -docker run --rm -e NAME=bar $1 dst-server --help update > $file2 || exit 1 -diff $file1 $file2 || exit 1 - -docker run --rm -e NAME=bar $1 dst-server update --help > $file2 || exit 1 -diff $file1 $file2 || exit 1 - -docker run --rm -e NAME=bar $1 dst-server update --help foo > $file2 || exit 1 -diff $file1 $file2 || exit 1 - -# dst-server log -cat > $file1 <<- EOF -usage: dst-server log [--server|--chat] -EOF - -docker run --rm -e NAME=bar $1 dst-server help log > $file2 || exit 1 -diff $file1 $file2 || exit 1 - -docker run --rm -e NAME=bar $1 dst-server --help log > $file2 || exit 1 -diff $file1 $file2 || exit 1 - -docker run --rm -e NAME=bar $1 dst-server log --help > $file2 || exit 1 -diff $file1 $file2 || exit 1 - -docker run --rm -e NAME=bar $1 dst-server log --help foo > $file2 || exit 1 -diff $file1 $file2 || exit 1 - -# dst-server log -cat > $file1 <<- EOF -usage: dst-server console [command ...] - -The console utility executes commands in the Don't Starve Together server console. -The commands are executed in command-line order. -If command is a single dash ('-') or absent, console reads from the standard input. -EOF - -docker run --rm -e NAME=bar $1 dst-server help console > $file2 || exit 1 -diff $file1 $file2 || exit 1 - -docker run --rm -e NAME=bar $1 dst-server --help console > $file2 || exit 1 -diff $file1 $file2 || exit 1 - -docker run --rm -e NAME=bar $1 dst-server console --help > $file2 || exit 1 -diff $file1 $file2 || exit 1 - -docker run --rm -e NAME=bar $1 dst-server console --help foo > $file2 || exit 1 -diff $file1 $file2 || exit 1 diff --git a/test/dsta-log/run.sh b/test/dsta-log/run.sh deleted file mode 100755 index 0350d8c..0000000 --- a/test/dsta-log/run.sh +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env bash - -clean() { - rm -f $log_txt $log_chat_txt $aux $aux1 - if [ -n "`docker ps -qf id=$container_id`" ]; then - docker rm -fv $container_id > /dev/null - fi -} -trap clean EXIT - -log_txt=`mktemp` -uuidgen > $log_txt -log_chat_txt=`mktemp` -uuidgen > $log_chat_txt -aux=`mktemp` -aux1=`mktemp` - -container_id=`docker run -d $1 sleep infinity || exit 1` -docker exec $container_id mkdir /var/lib/dsta/cluster/shard -docker exec $container_id chown steam:steam /var/lib/dsta/cluster/shard -docker cp $log_txt $container_id:/var/lib/dsta/cluster/shard/server_log.txt -docker cp $log_chat_txt $container_id:/var/lib/dsta/cluster/shard/server_log_chat.txt -docker exec $container_id dst-server log > $aux -diff $log_txt $aux || exit 1 -docker exec $container_id dst-server log --server > $aux -diff $log_txt $aux || exit 1 -docker exec $container_id dst-server log --chat > $aux -diff $log_chat_txt $aux || exit 1 - -cat > $log_txt <<- EOF -usage: dst-server log [--server|--chat] -EOF -docker exec $container_id dst-server log --server --chat 2> $aux && exit 1 -diff $log_txt $aux || exit 1 -docker exec $container_id dst-server log --type 2> $aux && exit 1 -diff $log_txt $aux || exit 1 -docker exec $container_id dst-server log asd 2> $aux && exit 1 -diff $log_txt $aux || exit 1 -docker exec $container_id dst-server log --type=chat 2> $aux && exit 1 -diff $log_txt $aux || exit 1 -docker rm -fv $container_id > /dev/null - -echo -n "" > $log_txt -docker run --rm -e NAME=foo $1 dst-server log > $aux 2> $aux1 -diff $log_txt $aux || exit 1 -diff $log_txt $aux1 || exit 1 -docker run --rm -e NAME=foo $1 dst-server log --server > $aux 2> $aux1 -diff $log_txt $aux || exit 1 -diff $log_txt $aux1 || exit 1 -docker run --rm -e NAME=foo $1 dst-server log --chat > $aux 2> $aux1 -diff $log_txt $aux || exit 1 -diff $log_txt $aux1 || exit 1 diff --git a/test/dsta-start/run.sh b/test/dsta-start/run.sh deleted file mode 100755 index 02caafc..0000000 --- a/test/dsta-start/run.sh +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/env bash - -clean() { - rm -f $file1 $file2 - if [ -n "`docker ps -qf name=$container_id`" ]; then - docker rm -fv $container_id > /dev/null - fi -} -trap clean EXIT - -container_id=`uuidgen` -file1=`mktemp` -file2=`mktemp` - -docker run --name "$container_id" $1 dst-server start > $file2 & -sleep 40 -if [ -z "`docker ps -qf name=$container_id`" ]; then - exit 1 -fi -grep -Fq "Success! App '343050' already up to date." $file2 && exit 1 -grep -Fq "DownloadMods" $file2 && exit 1 -docker rm -fv $container_id > /dev/null - -docker run --name "$container_id" $1 dst-server start --update=all > $file2 & -sleep 40 -if [ -z "`docker ps -qf name=$container_id`" ]; then - exit 1 -fi -grep -Fq "Success! App '343050' already up to date." $file2 || exit 1 -grep -Fq "DownloadMods" $file2 || exit 1 -docker rm -fv $container_id > /dev/null - -docker run --name "$container_id" $1 dst-server start --update=none > $file2 & -sleep 20 -if [ -z "`docker ps -qf name=$container_id`" ]; then - exit 1 -fi -grep -Fq "Success! App '343050' already up to date." $file2 && exit 1 -grep -Fq "DownloadMods" $file2 && exit 1 -docker rm -fv $container_id > /dev/null - -docker run --name "$container_id" $1 dst-server start --update=game > $file2 & -sleep 40 -if [ -z "`docker ps -qf name=$container_id`" ]; then - exit 1 -fi -grep -Fq "Success! App '343050' already up to date." $file2 || exit 1 -grep -Fq "DownloadMods" $file2 && exit 1 -docker rm -fv $container_id > /dev/null - -docker run --name "$container_id" $1 dst-server start --update=mods > $file2 & -sleep 20 -if [ -z "`docker ps -qf name=$container_id`" ]; then - exit 1 -fi -grep -Fq "Success! App '343050' already up to date." $file2 && exit 1 -grep -Fq "DownloadMods" $file2 || exit 1 -docker rm -fv $container_id > /dev/null - -# Errors -cat > $file1 <<- EOF -usage: dst-server start [--update=all|none|game|mods] - [--keep-configuration=]...>] - - --update=none - Update nothing, just start the server. This is the default behaviour. - --update=all - Update the game and the mods before launch the server. - --update=game - Update just the game (no the mods) and launch the server. - --update=mods - Update the mods and launch the server. - --keep-configuration - Select which configuration you don't want to overwrite. - You must provide one or more of these values separated by commas: - - token - - cluster - - server - - world - - adminlist - - blocklist - - whitelist - - mods -EOF -docker run --rm $1 dst-server start foo >/dev/null 2> $file2 && exit 1 -diff $file1 $file2 || exit 1 -docker run --rm $1 dst-server start --update=foo >/dev/null 2> $file2 && exit 1 -diff $file1 $file2 || exit 1 diff --git a/test/dsta-update/run.sh b/test/dsta-update/run.sh deleted file mode 100755 index 7266bb8..0000000 --- a/test/dsta-update/run.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env bash - -clean() { - rm -f $file1 $file2 -} -trap clean EXIT - -file1=`mktemp` -file2=`mktemp` - -docker run --rm $1 dst-server update > $file2 || exit 1 -grep -Fq "Success! App '343050' already up to date." $file2 || exit 1 -grep -Fq "DownloadMods" $file2 || exit 1 - -docker run --rm $1 dst-server update --all > $file2 || exit 1 -grep -Fq "Success! App '343050' already up to date." $file2 || exit 1 -grep -Fq "DownloadMods" $file2 || exit 1 - -docker run --rm $1 dst-server update --game > $file2 || exit 1 -grep -Fq "Success! App '343050' already up to date." $file2 || exit 1 -grep -Fq "DownloadMods" $file2 && exit 1 - -docker run --rm $1 dst-server update --mods > $file2 || exit 1 -grep -Fq "Success! App '343050' already up to date." $file2 && exit 1 -grep -Fq "DownloadMods" $file2 || exit 1 - -# Errors -cat > $file1 <<- EOF -usage: dst-server update [--all|--game|--mods] -EOF -docker run --rm $1 dst-server update --game --mods >/dev/null 2> $file2 && exit 1 -diff $file1 $file2 || exit 1 -docker run --rm $1 dst-server update --all --game >/dev/null 2> $file2 && exit 1 -diff $file1 $file2 || exit 1 -docker run --rm $1 dst-server update --all --mods >/dev/null 2> $file2 && exit 1 -diff $file1 $file2 || exit 1 -docker run --rm $1 dst-server update --game --game >/dev/null 2> $file2 && exit 1 -diff $file1 $file2 || exit 1 -docker run --rm $1 dst-server update foo >/dev/null 2> $file2 && exit 1 -diff $file1 $file2 || exit 1 -docker run --rm $1 dst-server update --bar >/dev/null 2> $file2 && exit 1 -diff $file1 $file2 || exit 1 -docker run --rm $1 dst-server update --bar=foo >/dev/null 2> $file2 && exit 1 -diff $file1 $file2 || exit 1 diff --git a/test/dsta-version/run.sh b/test/dsta-version/run.sh deleted file mode 100755 index 25c3d85..0000000 --- a/test/dsta-version/run.sh +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash - -clean() { - rm -f $aux $aux1 -} -trap clean EXIT - -aux=`mktemp` -aux1=`mktemp` - -docker run --rm $1 dst-server version >/dev/null || exit 1 - -version=`docker run --rm $1 dst-server version --local || exit 1` -[[ $version =~ ^[0-9]+$ ]] || ( echo "\$version == $version" && exit 1 ) - -version=`docker run --rm $1 dst-server version --upstream || exit 1` -[[ $version =~ ^[0-9]+$ ]] || ( echo "\$version == $version" && exit 1 ) - -message=`docker run --rm $1 dst-server version --check` -if [ $? -eq 0 ]; then - [[ "$message" == "Version is up to date." ]] || ( echo "\$? == $? && \$message == $message" && exit 1 ) -else - [ "$message" == "Version is outdated." ] || ( echo "\$? == $? && \$message == $message" && exit 1 ) -fi - -cat > $aux <<- EOF -usage: dst-server version [--local|--upstream|--check] - -Print the local and upstream version of the DST server. - - --local - Return the local version. - --upstream - Return the currently released upstream version. - --check - Check if the currently running version is up to date. -EOF -docker run --rm $1 dst-server version --help >$aux1 || exit 1 -diff $aux $aux1 || exit 1 -docker run --rm $1 dst-server version --foo >/dev/null 2>$aux1 && exit 1 -diff $aux $aux1 || exit 1 diff --git a/test/entrypoint-other/run.sh b/test/entrypoint-other/run.sh deleted file mode 100755 index cb819d9..0000000 --- a/test/entrypoint-other/run.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash - -clean() { - rm -f $file1 $file2 -} -trap clean EXIT - -file1=`mktemp` -file2=`mktemp` -docker run --rm $1 echo OK > $file1 || exit 1 -echo OK > $file2 -diff $file1 $file2 || exit 1 - -../build/docker-entrypoint.sh false && exit 1 -../build/docker-entrypoint.sh true || exit 1 diff --git a/test/mods-install/run.sh b/test/mods-install/run.sh deleted file mode 100755 index 0fb89b1..0000000 --- a/test/mods-install/run.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash - -clean() { - rm -f $log_txt - if [ -n "$container_id" ]; then - docker rm -fv $container_id > /dev/null - fi -} -trap clean EXIT - -log_txt=`mktemp` -container_id=`docker run -e MODS=492173795 -d $1 dst-server start --update=mods || exit 1` -sleep 20 # We need to wait for the server to start -docker cp $container_id:/var/lib/dsta/cluster/shard/server_log.txt $log_txt || exit 1 -if grep -Fq "Failed to create mod folder [../mods/" $log_txt; then - exit 1 -fi diff --git a/test/run.sh b/test/run.sh deleted file mode 100755 index d4ddfa0..0000000 --- a/test/run.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env bash - -echoerr() { echo "$@" 1>&2; } -build_error() { - echoerr Error building the image - exit 1 -} - -cd "$( dirname "$0" )" - -# Build the image -image_name=dstacademy/dontstarvetogether -docker build -t $image_name ../build || build_error - -tests=`mktemp` -if [ $# -eq 0 ]; then - find . -mindepth 2 -maxdepth 2 -type f -name run.sh > $tests -else - for test_name in "$@" - do - echo "./$test_name/run.sh" >> $tests - done -fi -test_count=`wc -l < $tests` -i=1 -error_count=0 - -# Run the tests -while read -u 3 t -do - test_name=`echo $t | cut -d'/' -f2` - echo "Running $test_name [$i/$test_count]" - if ! $t $image_name; then - echoerr "[FAIL] $test_name" - ((error_count++)) - fi - ((i++)) -done 3< $tests - -rm $tests # TODO trap signal - -if [ $error_count -ne 0 ]; then - echoerr "Failed $error_count/$test_count tests." - exit 1 -fi diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..2c1c135 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,7 @@ +# Test Suite + +## Usage +1. [Intall `bats`][install-bats] +2. Run `bats tests` + + [install-bats]: https://github.com/bats-core/bats-core/wiki/Install-Bats-Using-a-Package diff --git a/tests/attach-console.bats b/tests/attach-console.bats new file mode 100644 index 0000000..97f4e56 --- /dev/null +++ b/tests/attach-console.bats @@ -0,0 +1,23 @@ +#!/usr/bin/env bats + +load test_helper + +@test "Send console commands" { + timeout --kill-after 1 20 docker run -i --name $CONTAINER $IMAGE <<-EOF + c_shutdown(true) + EOF + docker cp $CONTAINER:/var/lib/dsta/cluster/shard/server_log.txt $TMP/server_log.txt + + grep -Fq "RemoteCommandInput: \"c_shutdown(true)\"" $TMP/server_log.txt +} + +@test "Send console commands with docker attach" { + docker run -id --name $CONTAINER $IMAGE + docker attach $CONTAINER <<-EOF + c_shutdown(true) + EOF + timeout --kill-after 1 20 docker wait $CONTAINER + docker cp $CONTAINER:/var/lib/dsta/cluster/shard/server_log.txt $TMP/server_log.txt + + grep -Fq "RemoteCommandInput: \"c_shutdown(true)\"" $TMP/server_log.txt +} diff --git a/tests/boot-aux.bats b/tests/boot-aux.bats new file mode 100644 index 0000000..63c0689 --- /dev/null +++ b/tests/boot-aux.bats @@ -0,0 +1,178 @@ +#!/usr/bin/env bats + +load test_helper +source $BUILD/static/boot/functions.sh + +@test "Test validate_bool 1" { + export FOO="" + run validate_bool FOO + assert_success +} + +@test "Test validate_bool 2" { + export FOO="true" + run validate_bool FOO + assert_success +} + +@test "Test validate_bool 3" { + export FOO="false" + run validate_bool FOO + assert_success +} + +@test "Test validate_bool 4" { + export FOO="bar" + run validate_bool FOO + assert_failure +} + +@test "Test validate_int 1" { + export FOO="" + run validate_int FOO 1 10 + assert_success +} + +@test "Test validate_int 2" { + export FOO="1" + run validate_int FOO 1 10 + assert_success +} + +@test "Test validate_int 3" { + export FOO="5" + run validate_int FOO 1 10 + assert_success +} + +@test "Test validate_int 4" { + export FOO="10" + run validate_int FOO 1 10 + assert_success +} + +@test "Test validate_int 5" { + export FOO="0" + run validate_int FOO 1 10 + assert_failure +} + +@test "Test validate_int 6" { + export FOO="11" + run validate_int FOO 1 10 + assert_failure +} + +@test "Test validate_int 7" { + export FOO="1100" + run validate_int FOO 1 10 + assert_failure +} + +@test "Test validate_port 1" { + export FOO="" + run validate_port FOO + assert_success +} + +@test "Test validate_port 2" { + export FOO="1" + run validate_port FOO + assert_success +} + +@test "Test validate_port 3" { + export FOO="10999" + run validate_port FOO + assert_success +} + +@test "Test validate_port 4" { + export FOO="65535" + run validate_port FOO + assert_success +} + +@test "Test validate_port 5" { + export FOO="0" + run validate_port FOO + assert_failure +} + +@test "Test validate_port 6" { + export FOO="65536" + run validate_port FOO + assert_failure +} + +@test "Test validate_port 7" { + export FOO="655350" + run validate_port FOO + assert_failure +} + +@test "Test validate_option 1" { + export FOO="" + run validate_option FOO a b c + assert_success +} + +@test "Test validate_option 2" { + export FOO="a" + run validate_option FOO a b c + assert_success +} + +@test "Test validate_option 3" { + export FOO="b" + run validate_option FOO a b c + assert_success +} + +@test "Test validate_option 4" { + export FOO="c" + run validate_option FOO a b c + assert_success +} + +@test "Test validate_option 5" { + export FOO="d" + run validate_option FOO a b c + assert_failure +} + +@test "Test validate_option 6" { + export FOO="1" + run validate_option FOO a b c + assert_failure +} + +@test "Test validate_option 7" { + export FOO="1" + run validate_option FOO 1 2 3 + assert_success +} + +@test "Test validate_option 8" { + export FOO="2" + run validate_option FOO 1 2 3 + assert_success +} + +@test "Test validate_option 9" { + export FOO="3" + run validate_option FOO 1 2 3 + assert_success +} + +@test "Test validate_option 10" { + export FOO="4" + run validate_option FOO 1 2 3 + assert_failure +} + +@test "Test validate_option 11" { + export FOO="a" + run validate_option FOO 1 2 3 + assert_failure +} diff --git a/tests/boot-lists.bats b/tests/boot-lists.bats new file mode 100644 index 0000000..ba9e09e --- /dev/null +++ b/tests/boot-lists.bats @@ -0,0 +1,159 @@ +#!/usr/bin/env bats + +load test_helper + +export VOLUME="test-keep-lists" + +##### +# Adminlist +##### +@test "load ADMINLIST in correct format" { + load_list_in_correct_format ADMINLIST adminlist +} + +@test "set ADMINLIST creates file" { + set_variable_creates_file ADMINLIST adminlist +} + +@test "no set ADMINLIST does't create file" { + no_set_varibale_doesnt_create_file ADMINLIST adminlist +} + +@test "overwrite ADMINLIST" { + overwrite_list ADMINLIST adminlist +} + +@test "keep ADMINLIST" { + keep_list ADMINLIST adminlist +} + +@test "no keep and no provide ADMINLIST" { + no_keep_and_not_provide ADMINLIST adminlist +} + +##### +# Whitelist +##### +@test "load WHITELIST in correct format" { + load_list_in_correct_format WHITELIST whitelist +} + +@test "set WHITELIST creates file" { + set_variable_creates_file WHITELIST whitelist +} + +@test "no set WHITELIST does't create file" { + no_set_varibale_doesnt_create_file WHITELIST whitelist +} + +@test "overwrite WHITELIST" { + overwrite_list WHITELIST whitelist +} + +@test "keep WHITELIST" { + keep_list WHITELIST whitelist +} + +@test "no keep and no provide WHITELIST" { + no_keep_and_not_provide WHITELIST whitelist +} + +##### +# Blocklist +##### +@test "load BLOCKLIST in correct format" { + load_list_in_correct_format BLOCKLIST blocklist +} + +@test "set BLOCKLIST creates file" { + set_variable_creates_file BLOCKLIST blocklist +} + +@test "no set BLOCKLIST does't create file" { + no_set_varibale_doesnt_create_file BLOCKLIST blocklist +} + +@test "overwrite BLOCKLIST" { + overwrite_list BLOCKLIST blocklist +} + +@test "keep BLOCKLIST" { + keep_list BLOCKLIST blocklist +} + +@test "no keep and no provide BLOCKLIST" { + no_keep_and_not_provide BLOCKLIST blocklist +} + +load_list_in_correct_format() { + fixtures boot-lists + + docker run -d -e $1="foo,bar,xy_:z" --name $CONTAINER $IMAGE + wait_until_initializing + docker cp $CONTAINER:/var/lib/dsta/cluster/$2.txt "$TMP/$2.txt" + diff "$TMP/$2.txt" "$FIXTURE_ROOT/list.txt" + wait_until_loaded + docker cp $CONTAINER:/var/lib/dsta/cluster/shard/server_log.txt "$TMP/server_log.txt" + grep -E "$2\.txt.*\(Success\)" "$TMP/server_log.txt" +} + +set_variable_creates_file() { + fixtures boot-lists + + docker run -d -e $1="foo" --name $CONTAINER $IMAGE + wait_until_initializing + docker cp $CONTAINER:/var/lib/dsta/cluster/$2.txt "$TMP/$2.txt" + diff "$TMP/$2.txt" "$FIXTURE_ROOT/foo.txt" +} + +no_set_varibale_doesnt_create_file() { + docker run -d --name $CONTAINER $IMAGE + wait_until_initializing + run docker cp $CONTAINER:/var/lib/dsta/cluster/$2.txt "$TMP/$2.txt" + assert_failure +} + +overwrite_list() { + fixtures boot-lists + + docker run -d -v $VOLUME:/var/lib/dsta/cluster -e $1="foo" --name $CONTAINER $IMAGE + wait_until_initializing + docker cp $CONTAINER:/var/lib/dsta/cluster/$2.txt "$TMP/$2.txt" + diff "$TMP/$2.txt" "$FIXTURE_ROOT/foo.txt" + docker rm -f $CONTAINER + + docker run -d -v $VOLUME:/var/lib/dsta/cluster -e $1="bar" --name $CONTAINER $IMAGE + wait_until_initializing + docker cp $CONTAINER:/var/lib/dsta/cluster/$2.txt "$TMP/$2.txt" + diff "$TMP/$2.txt" "$FIXTURE_ROOT/bar.txt" +} + +keep_list() { + fixtures boot-lists + + docker run -d -v $VOLUME:/var/lib/dsta/cluster -e $1="foo" --name $CONTAINER $IMAGE + wait_until_initializing + docker cp $CONTAINER:/var/lib/dsta/cluster/$2.txt "$TMP/$2.txt" + diff "$TMP/$2.txt" "$FIXTURE_ROOT/foo.txt" + docker rm -f $CONTAINER + + docker run -d -v $VOLUME:/var/lib/dsta/cluster -e $1="bar" --name $CONTAINER $IMAGE --keep-configuration=$2 + wait_until_initializing + docker cp $CONTAINER:/var/lib/dsta/cluster/$2.txt "$TMP/$2.txt" + diff "$TMP/$2.txt" "$FIXTURE_ROOT/foo.txt" +} + +no_keep_and_not_provide() { + fixtures boot-lists + + docker run -d -v $VOLUME:/var/lib/dsta/cluster -e $1="foo" --name $CONTAINER $IMAGE + wait_until_initializing + docker cp $CONTAINER:/var/lib/dsta/cluster/$2.txt "$TMP/$2.txt" + diff "$TMP/$2.txt" "$FIXTURE_ROOT/foo.txt" + docker rm -f $CONTAINER + + docker run -d -v $VOLUME:/var/lib/dsta/cluster --name $CONTAINER $IMAGE + wait_until_initializing + run docker cp $CONTAINER:/var/lib/dsta/cluster/$2.txt "$TMP/$2.txt" + assert_failure +} diff --git a/tests/boot-mods.bats b/tests/boot-mods.bats new file mode 100644 index 0000000..76e04eb --- /dev/null +++ b/tests/boot-mods.bats @@ -0,0 +1,53 @@ +#!/usr/bin/env bats + +load test_helper + +@test "Configure one mod" { + fixtures boot-mods/foo + + docker run -d -e MODS="foo" --name $CONTAINER $IMAGE + wait_until_initializing + docker cp $CONTAINER:/opt/dst/mods/dedicated_server_mods_setup.lua "$TMP/dedicated_server_mods_setup.lua" + tail -n 2 "$TMP/dedicated_server_mods_setup.lua" >"$TMP/dedicated_server_mods_setup.lua-tail" + diff "$TMP/dedicated_server_mods_setup.lua-tail" "$FIXTURE_ROOT/dedicated_server_mods_setup.lua-tail" + docker cp $CONTAINER:/var/lib/dsta/cluster/shard/modoverrides.lua "$TMP/modoverrides.lua" + diff "$TMP/modoverrides.lua" "$FIXTURE_ROOT/modoverrides.lua" +} + +@test "Configure two mods" { + fixtures boot-mods/foo-bar + + docker run -d -e MODS="foo,bar" --name $CONTAINER $IMAGE + wait_until_initializing + docker cp $CONTAINER:/opt/dst/mods/dedicated_server_mods_setup.lua "$TMP/dedicated_server_mods_setup.lua" + tail -n 3 "$TMP/dedicated_server_mods_setup.lua" >"$TMP/dedicated_server_mods_setup.lua-tail" + diff "$TMP/dedicated_server_mods_setup.lua-tail" "$FIXTURE_ROOT/dedicated_server_mods_setup.lua-tail" + docker cp $CONTAINER:/var/lib/dsta/cluster/shard/modoverrides.lua "$TMP/modoverrides.lua" + diff "$TMP/modoverrides.lua" "$FIXTURE_ROOT/modoverrides.lua" +} + +@test "Configure two mods with mods overrides" { + fixtures boot-mods/foo-bar-with-overrides + + docker run -d -e MODS="foo,bar" -e MODS_OVERRIDES="xyz" --name $CONTAINER $IMAGE + wait_until_initializing + docker cp $CONTAINER:/opt/dst/mods/dedicated_server_mods_setup.lua "$TMP/dedicated_server_mods_setup.lua" + tail -n 3 "$TMP/dedicated_server_mods_setup.lua" >"$TMP/dedicated_server_mods_setup.lua-tail" + diff "$TMP/dedicated_server_mods_setup.lua-tail" "$FIXTURE_ROOT/dedicated_server_mods_setup.lua-tail" + docker cp $CONTAINER:/var/lib/dsta/cluster/shard/modoverrides.lua "$TMP/modoverrides.lua" + diff "$TMP/modoverrides.lua" "$FIXTURE_ROOT/modoverrides.lua" +} + +@test "modoverrides.lua is not created by default" { + docker run -d --name $CONTAINER $IMAGE + wait_until_initializing + run docker cp $CONTAINER:/var/lib/dsta/cluster/shard/modoverrides.lua "$TMP/modoverrides.lua" + assert_failure +} + +@test "Just set mods overrides doesn't create modoverrides.lua" { + docker run -d -e MODS_OVERRIDES="xyz" --name $CONTAINER $IMAGE + wait_until_initializing + run docker cp $CONTAINER:/var/lib/dsta/cluster/shard/modoverrides.lua "$TMP/modoverrides.lua" + assert_failure +} diff --git a/tests/boot-token.bats b/tests/boot-token.bats new file mode 100644 index 0000000..91a44de --- /dev/null +++ b/tests/boot-token.bats @@ -0,0 +1,106 @@ +#!/usr/bin/env bats + +load test_helper + +@test "set token creates cluster_token.txt" { + fixtures boot-token + + docker run -d -e TOKEN="token-1" --name $CONTAINER $IMAGE + wait_until_initializing + docker cp $CONTAINER:/var/lib/dsta/cluster/cluster_token.txt "$TMP/cluster_token.txt" + diff "$TMP/cluster_token.txt" "$FIXTURE_ROOT/token1" +} + +@test "not keep and not provide token" { + fixtures boot-token + + docker run -d --name $CONTAINER $IMAGE + wait_until_initializing + run docker cp $CONTAINER:/var/lib/dsta/cluster/cluster_token.txt "$TMP/cluster_token.txt" + assert_failure +} + +@test "overwrite token" { + fixtures boot-token + + VOLUME="test-keep-token" + + docker run -d -v $VOLUME:/var/lib/dsta/cluster -e TOKEN="token-1" --name $CONTAINER $IMAGE + wait_until_initializing + docker cp $CONTAINER:/var/lib/dsta/cluster/cluster_token.txt "$TMP/cluster_token.txt" + diff "$TMP/cluster_token.txt" "$FIXTURE_ROOT/token1" + docker rm -f $CONTAINER + + docker run -d -v $VOLUME:/var/lib/dsta/cluster -e TOKEN="token-2" --name $CONTAINER $IMAGE + wait_until_initializing + docker cp $CONTAINER:/var/lib/dsta/cluster/cluster_token.txt "$TMP/cluster_token.txt" + diff "$TMP/cluster_token.txt" "$FIXTURE_ROOT/token2" +} + +@test "keep token" { + fixtures boot-token + + VOLUME="test-keep-token" + + docker run -d -v $VOLUME:/var/lib/dsta/cluster -e TOKEN="token-1" --name $CONTAINER $IMAGE + wait_until_initializing + docker cp $CONTAINER:/var/lib/dsta/cluster/cluster_token.txt "$TMP/cluster_token.txt" + diff "$TMP/cluster_token.txt" "$FIXTURE_ROOT/token1" + docker rm -f $CONTAINER + + docker run -d -v $VOLUME:/var/lib/dsta/cluster -e TOKEN="token-2" --name $CONTAINER $IMAGE --keep-configuration=token + wait_until_initializing + docker cp $CONTAINER:/var/lib/dsta/cluster/cluster_token.txt "$TMP/cluster_token.txt" + diff "$TMP/cluster_token.txt" "$FIXTURE_ROOT/token1" +} + +@test "multiple keep values" { + fixtures boot-token + + VOLUME="test-keep-token" + + docker run -d -v $VOLUME:/var/lib/dsta/cluster -e TOKEN="token-1" --name $CONTAINER $IMAGE + wait_until_initializing + docker cp $CONTAINER:/var/lib/dsta/cluster/cluster_token.txt "$TMP/cluster_token.txt" + diff "$TMP/cluster_token.txt" "$FIXTURE_ROOT/token1" + docker rm -f $CONTAINER + + docker run -d -v $VOLUME:/var/lib/dsta/cluster -e TOKEN="token-2" --name $CONTAINER $IMAGE --keep-configuration=token,whitelist + wait_until_initializing + docker cp $CONTAINER:/var/lib/dsta/cluster/cluster_token.txt "$TMP/cluster_token.txt" + diff "$TMP/cluster_token.txt" "$FIXTURE_ROOT/token1" +} + +@test "keep but not the token" { + fixtures boot-token + + VOLUME="test-keep-token" + + docker run -d -v $VOLUME:/var/lib/dsta/cluster -e TOKEN="token-1" --name $CONTAINER $IMAGE + wait_until_initializing + docker cp $CONTAINER:/var/lib/dsta/cluster/cluster_token.txt "$TMP/cluster_token.txt" + diff "$TMP/cluster_token.txt" "$FIXTURE_ROOT/token1" + docker rm -f $CONTAINER + + docker run -d -v $VOLUME:/var/lib/dsta/cluster -e TOKEN="token-2" --name $CONTAINER $IMAGE --keep-configuration=whitelist + wait_until_initializing + docker cp $CONTAINER:/var/lib/dsta/cluster/cluster_token.txt "$TMP/cluster_token.txt" + diff "$TMP/cluster_token.txt" "$FIXTURE_ROOT/token2" +} + +@test "not keep and not provide token" { + fixtures boot-token + + VOLUME="test-keep-token" + + docker run -d -v $VOLUME:/var/lib/dsta/cluster -e TOKEN="token-1" --name $CONTAINER $IMAGE + wait_until_initializing + docker cp $CONTAINER:/var/lib/dsta/cluster/cluster_token.txt "$TMP/cluster_token.txt" + diff "$TMP/cluster_token.txt" "$FIXTURE_ROOT/token1" + docker rm -f $CONTAINER + + docker run -d -v $VOLUME:/var/lib/dsta/cluster --name $CONTAINER $IMAGE + wait_until_initializing + run docker cp $CONTAINER:/var/lib/dsta/cluster/cluster_token.txt "$TMP/cluster_token.txt" + assert_failure +} diff --git a/tests/boot-world.bats b/tests/boot-world.bats new file mode 100644 index 0000000..0bbadb5 --- /dev/null +++ b/tests/boot-world.bats @@ -0,0 +1,83 @@ +#!/usr/bin/env bats + +load test_helper + +@test "set LEVELDATA_OVERRIDES creates leveldataoverride.lua" { + fixtures boot-world + + docker run -d -e LEVELDATA_OVERRIDES="foo" --name $CONTAINER $IMAGE + wait_until_initializing + docker cp $CONTAINER:/var/lib/dsta/cluster/shard/leveldataoverride.lua "$TMP/leveldataoverride.lua" + diff "$TMP/leveldataoverride.lua" "$FIXTURE_ROOT/foo" +} + +@test "no keep and not provide LEVELDATA_OVERRIDES doesn't create leveldataoverride.lua" { + docker run -d --name $CONTAINER $IMAGE + wait_until_initializing + run docker cp $CONTAINER:/var/lib/dsta/cluster/shard/leveldataoverride.lua "$TMP/leveldataoverride.lua" + assert_failure +} + +@test "overwrite LEVELDATA_OVERRIDES" { + fixtures boot-world + VOLUME="test-keep-token" + + docker run -d -v $VOLUME:/var/lib/dsta/cluster -e LEVELDATA_OVERRIDES="foo" --name $CONTAINER $IMAGE + wait_until_initializing + docker cp $CONTAINER:/var/lib/dsta/cluster/shard/leveldataoverride.lua "$TMP/leveldataoverride.lua" + diff "$TMP/leveldataoverride.lua" "$FIXTURE_ROOT/foo" + docker rm -f $CONTAINER + + docker run -d -v $VOLUME:/var/lib/dsta/cluster -e LEVELDATA_OVERRIDES="foo2" --name $CONTAINER $IMAGE + wait_until_initializing + docker cp $CONTAINER:/var/lib/dsta/cluster/shard/leveldataoverride.lua "$TMP/leveldataoverride.lua" + diff "$TMP/leveldataoverride.lua" "$FIXTURE_ROOT/foo2" +} + +@test "keep world and set LEVELDATA_OVERRIDES" { + fixtures boot-world + VOLUME="test-keep-token" + + docker run -d -v $VOLUME:/var/lib/dsta/cluster -e LEVELDATA_OVERRIDES="foo" --name $CONTAINER $IMAGE + wait_until_initializing + docker cp $CONTAINER:/var/lib/dsta/cluster/shard/leveldataoverride.lua "$TMP/leveldataoverride.lua" + diff "$TMP/leveldataoverride.lua" "$FIXTURE_ROOT/foo" + docker rm -f $CONTAINER + + docker run -d -v $VOLUME:/var/lib/dsta/cluster -e LEVELDATA_OVERRIDES="foo2" --name $CONTAINER $IMAGE --keep=world + wait_until_initializing + docker cp $CONTAINER:/var/lib/dsta/cluster/shard/leveldataoverride.lua "$TMP/leveldataoverride.lua" + diff "$TMP/leveldataoverride.lua" "$FIXTURE_ROOT/foo" +} + +@test "keep world but not set LEVELDATA_OVERRIDES" { + fixtures boot-world + VOLUME="test-keep-token" + + docker run -d -v $VOLUME:/var/lib/dsta/cluster -e LEVELDATA_OVERRIDES="foo" --name $CONTAINER $IMAGE + wait_until_initializing + docker cp $CONTAINER:/var/lib/dsta/cluster/shard/leveldataoverride.lua "$TMP/leveldataoverride.lua" + diff "$TMP/leveldataoverride.lua" "$FIXTURE_ROOT/foo" + docker rm -f $CONTAINER + + docker run -d -v $VOLUME:/var/lib/dsta/cluster --name $CONTAINER $IMAGE --keep=world + wait_until_initializing + docker cp $CONTAINER:/var/lib/dsta/cluster/shard/leveldataoverride.lua "$TMP/leveldataoverride.lua" + diff "$TMP/leveldataoverride.lua" "$FIXTURE_ROOT/foo" +} + +@test "not keep world and not set LEVELDATA_OVERRIDES" { + fixtures boot-world + VOLUME="test-keep-token" + + docker run -d -v $VOLUME:/var/lib/dsta/cluster -e LEVELDATA_OVERRIDES="foo" --name $CONTAINER $IMAGE + wait_until_initializing + docker cp $CONTAINER:/var/lib/dsta/cluster/shard/leveldataoverride.lua "$TMP/leveldataoverride.lua" + diff "$TMP/leveldataoverride.lua" "$FIXTURE_ROOT/foo" + docker rm -f $CONTAINER + + docker run -d -v $VOLUME:/var/lib/dsta/cluster --name $CONTAINER $IMAGE + wait_until_initializing + run docker cp $CONTAINER:/var/lib/dsta/cluster/shard/leveldataoverride.lua "$TMP/leveldataoverride.lua" + assert_failure +} diff --git a/tests/build-mods.bats b/tests/build-mods.bats new file mode 100644 index 0000000..1b2c36f --- /dev/null +++ b/tests/build-mods.bats @@ -0,0 +1,21 @@ +#!/usr/bin/env bats + +load test_helper + +@test "correct dedicated_server_mods_setup.lua installing one mod" { + fixtures build-mods/one-mod + + docker build --build-arg MODS="378160973" -t $IMAGE $BUILD + docker create --name $CONTAINER $IMAGE + docker cp $CONTAINER:/opt/dst/mods/dedicated_server_mods_setup.lua "$TMP/dedicated_server_mods_setup.lua" + diff --strip-trailing-cr "$TMP/dedicated_server_mods_setup.lua" "$FIXTURE_ROOT/dedicated_server_mods_setup.lua" +} + +@test "correct dedicated_server_mods_setup.lua installing two mods" { + fixtures build-mods/two-mods + + docker build --build-arg MODS="378160973,380423963" -t $IMAGE $BUILD + docker create --name $CONTAINER $IMAGE + docker cp $CONTAINER:/opt/dst/mods/dedicated_server_mods_setup.lua "$TMP/dedicated_server_mods_setup.lua" + diff --strip-trailing-cr "$TMP/dedicated_server_mods_setup.lua" "$FIXTURE_ROOT/dedicated_server_mods_setup.lua" +} diff --git a/tests/close-cleanly.bats b/tests/close-cleanly.bats new file mode 100644 index 0000000..5c806e9 --- /dev/null +++ b/tests/close-cleanly.bats @@ -0,0 +1,45 @@ +#!/usr/bin/env bats + +load test_helper + +@test "close cleanly after docker stop" { + docker run -d --name $CONTAINER $IMAGE + wait_until_loaded + docker stop $CONTAINER + docker cp $CONTAINER:/var/lib/dsta/cluster/shard/server_log.txt "$TMP/server_log.txt" + grep -q "Shutting down$" "$TMP/server_log.txt" +} + +@test "close cleanly after docker stop with dirty console" { + fixtures close-cleanly + + docker run -d --name $CONTAINER $IMAGE + wait_until_loaded + docker cp "$FIXTURE_ROOT/commands.sh" $CONTAINER:/ + docker exec $CONTAINER /commands.sh + docker stop $CONTAINER + docker cp $CONTAINER:/var/lib/dsta/cluster/shard/server_log.txt "$TMP/server_log.txt" + grep -q "Shutting down$" "$TMP/server_log.txt" +} + +@test "close cleanly after kill 1" { + fixtures close-cleanly + + docker run -d --name $CONTAINER $IMAGE + wait_until_loaded + docker exec $CONTAINER bash -c "kill 1" + timeout --kill-after 1 12 docker wait $CONTAINER + docker cp $CONTAINER:/var/lib/dsta/cluster/shard/server_log.txt "$TMP/server_log.txt" + grep -q "Shutting down$" "$TMP/server_log.txt" +} + +@test "close cleanly after kill -SIGINT 1" { + fixtures close-cleanly + + docker run -d --name $CONTAINER $IMAGE + wait_until_loaded + docker exec $CONTAINER bash -c "kill -SIGINT 1" + timeout --kill-after 1 12 docker wait $CONTAINER + docker cp $CONTAINER:/var/lib/dsta/cluster/shard/server_log.txt "$TMP/server_log.txt" + grep -q "Shutting down$" "$TMP/server_log.txt" +} diff --git a/tests/console.bats b/tests/console.bats new file mode 100644 index 0000000..4942e9d --- /dev/null +++ b/tests/console.bats @@ -0,0 +1,16 @@ +#!/usr/bin/env bats + +load test_helper + +@test "write in /usr/local/share/dsta/console is like write in the console" { + fixtures console + + docker run -d --name $CONTAINER $IMAGE + docker cp "$FIXTURE_ROOT/commands.sh" $CONTAINER:/ + docker exec $CONTAINER /commands.sh + wait_until_loaded + sleep 1 + docker cp $CONTAINER:/var/lib/dsta/cluster/shard/server_log.txt "$TMP/server_log.txt" + grep -F "RemoteCommandInput: \"foo bar\"" "$TMP/server_log.txt" + grep -F "RemoteCommandInput: \"bar\"" "$TMP/server_log.txt" +} diff --git a/tests/dependencies/bats-assert/assert.bash b/tests/dependencies/bats-assert/assert.bash new file mode 100755 index 0000000..1194753 --- /dev/null +++ b/tests/dependencies/bats-assert/assert.bash @@ -0,0 +1,720 @@ +# +# bats-assert - Common assertions for Bats +# +# Written in 2016 by Zoltan Tombol +# +# To the extent possible under law, the author(s) have dedicated all +# copyright and related and neighboring rights to this software to the +# public domain worldwide. This software is distributed without any +# warranty. +# +# You should have received a copy of the CC0 Public Domain Dedication +# along with this software. If not, see +# . +# + +# +# assert.bash +# ----------- +# +# Assertions are functions that perform a test and output relevant +# information on failure to help debugging. They return 1 on failure +# and 0 otherwise. +# +# All output is formatted for readability using the functions of +# `output.bash' and sent to the standard error. +# + +# Fail and display the expression if it evaluates to false. +# +# NOTE: The expression must be a simple command. Compound commands, such +# as `[[', can be used only when executed with `bash -c'. +# +# Globals: +# none +# Arguments: +# $1 - expression +# Returns: +# 0 - expression evaluates to TRUE +# 1 - otherwise +# Outputs: +# STDERR - details, on failure +assert() { + if ! "$@"; then + batslib_print_kv_single 10 'expression' "$*" \ + | batslib_decorate 'assertion failed' \ + | fail + fi +} + +# Fail and display the expression if it evaluates to true. +# +# NOTE: The expression must be a simple command. Compound commands, such +# as `[[', can be used only when executed with `bash -c'. +# +# Globals: +# none +# Arguments: +# $1 - expression +# Returns: +# 0 - expression evaluates to FALSE +# 1 - otherwise +# Outputs: +# STDERR - details, on failure +refute() { + if "$@"; then + batslib_print_kv_single 10 'expression' "$*" \ + | batslib_decorate 'assertion succeeded, but it was expected to fail' \ + | fail + fi +} + +# Fail and display details if the expected and actual values do not +# equal. Details include both values. +# +# Globals: +# none +# Arguments: +# $1 - actual value +# $2 - expected value +# Returns: +# 0 - values equal +# 1 - otherwise +# Outputs: +# STDERR - details, on failure +assert_equal() { + if [[ $1 != "$2" ]]; then + batslib_print_kv_single_or_multi 8 \ + 'expected' "$2" \ + 'actual' "$1" \ + | batslib_decorate 'values do not equal' \ + | fail + fi +} + +# Fail and display details if `$status' is not 0. Details include +# `$status' and `$output'. +# +# Globals: +# status +# output +# Arguments: +# none +# Returns: +# 0 - `$status' is 0 +# 1 - otherwise +# Outputs: +# STDERR - details, on failure +assert_success() { + if (( status != 0 )); then + { local -ir width=6 + batslib_print_kv_single "$width" 'status' "$status" + batslib_print_kv_single_or_multi "$width" 'output' "$output" + } | batslib_decorate 'command failed' \ + | fail + fi +} + +# Fail and display details if `$status' is 0. Details include `$output'. +# +# Optionally, when the expected status is specified, fail when it does +# not equal `$status'. In this case, details include the expected and +# actual status, and `$output'. +# +# Globals: +# status +# output +# Arguments: +# $1 - [opt] expected status +# Returns: +# 0 - `$status' is not 0, or +# `$status' equals the expected status +# 1 - otherwise +# Outputs: +# STDERR - details, on failure +assert_failure() { + (( $# > 0 )) && local -r expected="$1" + if (( status == 0 )); then + batslib_print_kv_single_or_multi 6 'output' "$output" \ + | batslib_decorate 'command succeeded, but it was expected to fail' \ + | fail + elif (( $# > 0 )) && (( status != expected )); then + { local -ir width=8 + batslib_print_kv_single "$width" \ + 'expected' "$expected" \ + 'actual' "$status" + batslib_print_kv_single_or_multi "$width" \ + 'output' "$output" + } | batslib_decorate 'command failed as expected, but status differs' \ + | fail + fi +} + +# Fail and display details if `$output' does not match the expected +# output. The expected output can be specified either by the first +# parameter or on the standard input. +# +# By default, literal matching is performed. The assertion fails if the +# expected output does not equal `$output'. Details include both values. +# +# Option `--partial' enables partial matching. The assertion fails if +# the expected substring cannot be found in `$output'. +# +# Option `--regexp' enables regular expression matching. The assertion +# fails if the extended regular expression does not match `$output'. An +# invalid regular expression causes an error to be displayed. +# +# It is an error to use partial and regular expression matching +# simultaneously. +# +# Globals: +# output +# Options: +# -p, --partial - partial matching +# -e, --regexp - extended regular expression matching +# Arguments: +# $1 - [=STDIN] expected output +# Returns: +# 0 - expected matches the actual output +# 1 - otherwise +# Inputs: +# STDIN - [=$1] expected output +# Outputs: +# STDERR - details, on failure +# error message, on error +assert_output() { + local -i is_mode_partial=0 + local -i is_mode_regexp=0 + + # Handle options. + while (( $# > 0 )); do + case "$1" in + -p|--partial) is_mode_partial=1; shift ;; + -e|--regexp) is_mode_regexp=1; shift ;; + --) shift; break ;; + *) break ;; + esac + done + + if (( is_mode_partial )) && (( is_mode_regexp )); then + echo "\`--partial' and \`--regexp' are mutually exclusive" \ + | batslib_decorate 'ERROR: assert_output' \ + | fail + return $? + fi + + # Arguments. + local expected + (( $# == 0 )) && expected="$(cat -)" || expected="$1" + + # Matching. + if (( is_mode_regexp )); then + if [[ '' =~ $expected ]] || (( $? == 2 )); then + echo "Invalid extended regular expression: \`$expected'" \ + | batslib_decorate 'ERROR: assert_output' \ + | fail + return $? + fi + if ! [[ $output =~ $expected ]]; then + batslib_print_kv_single_or_multi 6 \ + 'regexp' "$expected" \ + 'output' "$output" \ + | batslib_decorate 'regular expression does not match output' \ + | fail + fi + elif (( is_mode_partial )); then + if [[ $output != *"$expected"* ]]; then + batslib_print_kv_single_or_multi 9 \ + 'substring' "$expected" \ + 'output' "$output" \ + | batslib_decorate 'output does not contain substring' \ + | fail + fi + else + if [[ $output != "$expected" ]]; then + batslib_print_kv_single_or_multi 8 \ + 'expected' "$expected" \ + 'actual' "$output" \ + | batslib_decorate 'output differs' \ + | fail + fi + fi +} + +# Fail and display details if `$output' matches the unexpected output. +# The unexpected output can be specified either by the first parameter +# or on the standard input. +# +# By default, literal matching is performed. The assertion fails if the +# unexpected output equals `$output'. Details include `$output'. +# +# Option `--partial' enables partial matching. The assertion fails if +# the unexpected substring is found in `$output'. The unexpected +# substring is added to details. +# +# Option `--regexp' enables regular expression matching. The assertion +# fails if the extended regular expression does matches `$output'. The +# regular expression is added to details. An invalid regular expression +# causes an error to be displayed. +# +# It is an error to use partial and regular expression matching +# simultaneously. +# +# Globals: +# output +# Options: +# -p, --partial - partial matching +# -e, --regexp - extended regular expression matching +# Arguments: +# $1 - [=STDIN] unexpected output +# Returns: +# 0 - unexpected matches the actual output +# 1 - otherwise +# Inputs: +# STDIN - [=$1] unexpected output +# Outputs: +# STDERR - details, on failure +# error message, on error +refute_output() { + local -i is_mode_partial=0 + local -i is_mode_regexp=0 + + # Handle options. + while (( $# > 0 )); do + case "$1" in + -p|--partial) is_mode_partial=1; shift ;; + -e|--regexp) is_mode_regexp=1; shift ;; + --) shift; break ;; + *) break ;; + esac + done + + if (( is_mode_partial )) && (( is_mode_regexp )); then + echo "\`--partial' and \`--regexp' are mutually exclusive" \ + | batslib_decorate 'ERROR: refute_output' \ + | fail + return $? + fi + + # Arguments. + local unexpected + (( $# == 0 )) && unexpected="$(cat -)" || unexpected="$1" + + if (( is_mode_regexp == 1 )) && [[ '' =~ $unexpected ]] || (( $? == 2 )); then + echo "Invalid extended regular expression: \`$unexpected'" \ + | batslib_decorate 'ERROR: refute_output' \ + | fail + return $? + fi + + # Matching. + if (( is_mode_regexp )); then + if [[ $output =~ $unexpected ]] || (( $? == 0 )); then + batslib_print_kv_single_or_multi 6 \ + 'regexp' "$unexpected" \ + 'output' "$output" \ + | batslib_decorate 'regular expression should not match output' \ + | fail + fi + elif (( is_mode_partial )); then + if [[ $output == *"$unexpected"* ]]; then + batslib_print_kv_single_or_multi 9 \ + 'substring' "$unexpected" \ + 'output' "$output" \ + | batslib_decorate 'output should not contain substring' \ + | fail + fi + else + if [[ $output == "$unexpected" ]]; then + batslib_print_kv_single_or_multi 6 \ + 'output' "$output" \ + | batslib_decorate 'output equals, but it was expected to differ' \ + | fail + fi + fi +} + +# Fail and display details if the expected line is not found in the +# output (default) or in a specific line of it. +# +# By default, the entire output is searched for the expected line. The +# expected line is matched against every element of `${lines[@]}'. If no +# match is found, the assertion fails. Details include the expected line +# and `${lines[@]}'. +# +# When `--index ' is specified, only the -th line is matched. +# If the expected line does not match `${lines[]}', the assertion +# fails. Details include and the compared lines. +# +# By default, literal matching is performed. A literal match fails if +# the expected string does not equal the matched string. +# +# Option `--partial' enables partial matching. A partial match fails if +# the expected substring is not found in the target string. +# +# Option `--regexp' enables regular expression matching. A regular +# expression match fails if the extended regular expression does not +# match the target string. An invalid regular expression causes an error +# to be displayed. +# +# It is an error to use partial and regular expression matching +# simultaneously. +# +# Mandatory arguments to long options are mandatory for short options +# too. +# +# Globals: +# output +# lines +# Options: +# -n, --index - match the -th line +# -p, --partial - partial matching +# -e, --regexp - extended regular expression matching +# Arguments: +# $1 - expected line +# Returns: +# 0 - match found +# 1 - otherwise +# Outputs: +# STDERR - details, on failure +# error message, on error +# FIXME(ztombol): Display `${lines[@]}' instead of `$output'! +assert_line() { + local -i is_match_line=0 + local -i is_mode_partial=0 + local -i is_mode_regexp=0 + + # Handle options. + while (( $# > 0 )); do + case "$1" in + -n|--index) + if (( $# < 2 )) || ! [[ $2 =~ ^([0-9]|[1-9][0-9]+)$ ]]; then + echo "\`--index' requires an integer argument: \`$2'" \ + | batslib_decorate 'ERROR: assert_line' \ + | fail + return $? + fi + is_match_line=1 + local -ri idx="$2" + shift 2 + ;; + -p|--partial) is_mode_partial=1; shift ;; + -e|--regexp) is_mode_regexp=1; shift ;; + --) shift; break ;; + *) break ;; + esac + done + + if (( is_mode_partial )) && (( is_mode_regexp )); then + echo "\`--partial' and \`--regexp' are mutually exclusive" \ + | batslib_decorate 'ERROR: assert_line' \ + | fail + return $? + fi + + # Arguments. + local -r expected="$1" + + if (( is_mode_regexp == 1 )) && [[ '' =~ $expected ]] || (( $? == 2 )); then + echo "Invalid extended regular expression: \`$expected'" \ + | batslib_decorate 'ERROR: assert_line' \ + | fail + return $? + fi + + # Matching. + if (( is_match_line )); then + # Specific line. + if (( is_mode_regexp )); then + if ! [[ ${lines[$idx]} =~ $expected ]]; then + batslib_print_kv_single 6 \ + 'index' "$idx" \ + 'regexp' "$expected" \ + 'line' "${lines[$idx]}" \ + | batslib_decorate 'regular expression does not match line' \ + | fail + fi + elif (( is_mode_partial )); then + if [[ ${lines[$idx]} != *"$expected"* ]]; then + batslib_print_kv_single 9 \ + 'index' "$idx" \ + 'substring' "$expected" \ + 'line' "${lines[$idx]}" \ + | batslib_decorate 'line does not contain substring' \ + | fail + fi + else + if [[ ${lines[$idx]} != "$expected" ]]; then + batslib_print_kv_single 8 \ + 'index' "$idx" \ + 'expected' "$expected" \ + 'actual' "${lines[$idx]}" \ + | batslib_decorate 'line differs' \ + | fail + fi + fi + else + # Contained in output. + if (( is_mode_regexp )); then + local -i idx + for (( idx = 0; idx < ${#lines[@]}; ++idx )); do + [[ ${lines[$idx]} =~ $expected ]] && return 0 + done + { local -ar single=( + 'regexp' "$expected" + ) + local -ar may_be_multi=( + 'output' "$output" + ) + local -ir width="$( batslib_get_max_single_line_key_width \ + "${single[@]}" "${may_be_multi[@]}" )" + batslib_print_kv_single "$width" "${single[@]}" + batslib_print_kv_single_or_multi "$width" "${may_be_multi[@]}" + } | batslib_decorate 'no output line matches regular expression' \ + | fail + elif (( is_mode_partial )); then + local -i idx + for (( idx = 0; idx < ${#lines[@]}; ++idx )); do + [[ ${lines[$idx]} == *"$expected"* ]] && return 0 + done + { local -ar single=( + 'substring' "$expected" + ) + local -ar may_be_multi=( + 'output' "$output" + ) + local -ir width="$( batslib_get_max_single_line_key_width \ + "${single[@]}" "${may_be_multi[@]}" )" + batslib_print_kv_single "$width" "${single[@]}" + batslib_print_kv_single_or_multi "$width" "${may_be_multi[@]}" + } | batslib_decorate 'no output line contains substring' \ + | fail + else + local -i idx + for (( idx = 0; idx < ${#lines[@]}; ++idx )); do + [[ ${lines[$idx]} == "$expected" ]] && return 0 + done + { local -ar single=( + 'line' "$expected" + ) + local -ar may_be_multi=( + 'output' "$output" + ) + local -ir width="$( batslib_get_max_single_line_key_width \ + "${single[@]}" "${may_be_multi[@]}" )" + batslib_print_kv_single "$width" "${single[@]}" + batslib_print_kv_single_or_multi "$width" "${may_be_multi[@]}" + } | batslib_decorate 'output does not contain line' \ + | fail + fi + fi +} + +# Fail and display details if the unexpected line is found in the output +# (default) or in a specific line of it. +# +# By default, the entire output is searched for the unexpected line. The +# unexpected line is matched against every element of `${lines[@]}'. If +# a match is found, the assertion fails. Details include the unexpected +# line, the index of the first match and `${lines[@]}' with the matching +# line highlighted if `${lines[@]}' is longer than one line. +# +# When `--index ' is specified, only the -th line is matched. +# If the unexpected line matches `${lines[]}', the assertion fails. +# Details include and the unexpected line. +# +# By default, literal matching is performed. A literal match fails if +# the unexpected string does not equal the matched string. +# +# Option `--partial' enables partial matching. A partial match fails if +# the unexpected substring is found in the target string. When used with +# `--index ', the unexpected substring is also displayed on +# failure. +# +# Option `--regexp' enables regular expression matching. A regular +# expression match fails if the extended regular expression matches the +# target string. When used with `--index ', the regular expression +# is also displayed on failure. An invalid regular expression causes an +# error to be displayed. +# +# It is an error to use partial and regular expression matching +# simultaneously. +# +# Mandatory arguments to long options are mandatory for short options +# too. +# +# Globals: +# output +# lines +# Options: +# -n, --index - match the -th line +# -p, --partial - partial matching +# -e, --regexp - extended regular expression matching +# Arguments: +# $1 - unexpected line +# Returns: +# 0 - match not found +# 1 - otherwise +# Outputs: +# STDERR - details, on failure +# error message, on error +# FIXME(ztombol): Display `${lines[@]}' instead of `$output'! +refute_line() { + local -i is_match_line=0 + local -i is_mode_partial=0 + local -i is_mode_regexp=0 + + # Handle options. + while (( $# > 0 )); do + case "$1" in + -n|--index) + if (( $# < 2 )) || ! [[ $2 =~ ^([0-9]|[1-9][0-9]+)$ ]]; then + echo "\`--index' requires an integer argument: \`$2'" \ + | batslib_decorate 'ERROR: refute_line' \ + | fail + return $? + fi + is_match_line=1 + local -ri idx="$2" + shift 2 + ;; + -p|--partial) is_mode_partial=1; shift ;; + -e|--regexp) is_mode_regexp=1; shift ;; + --) shift; break ;; + *) break ;; + esac + done + + if (( is_mode_partial )) && (( is_mode_regexp )); then + echo "\`--partial' and \`--regexp' are mutually exclusive" \ + | batslib_decorate 'ERROR: refute_line' \ + | fail + return $? + fi + + # Arguments. + local -r unexpected="$1" + + if (( is_mode_regexp == 1 )) && [[ '' =~ $unexpected ]] || (( $? == 2 )); then + echo "Invalid extended regular expression: \`$unexpected'" \ + | batslib_decorate 'ERROR: refute_line' \ + | fail + return $? + fi + + # Matching. + if (( is_match_line )); then + # Specific line. + if (( is_mode_regexp )); then + if [[ ${lines[$idx]} =~ $unexpected ]] || (( $? == 0 )); then + batslib_print_kv_single 6 \ + 'index' "$idx" \ + 'regexp' "$unexpected" \ + 'line' "${lines[$idx]}" \ + | batslib_decorate 'regular expression should not match line' \ + | fail + fi + elif (( is_mode_partial )); then + if [[ ${lines[$idx]} == *"$unexpected"* ]]; then + batslib_print_kv_single 9 \ + 'index' "$idx" \ + 'substring' "$unexpected" \ + 'line' "${lines[$idx]}" \ + | batslib_decorate 'line should not contain substring' \ + | fail + fi + else + if [[ ${lines[$idx]} == "$unexpected" ]]; then + batslib_print_kv_single 5 \ + 'index' "$idx" \ + 'line' "${lines[$idx]}" \ + | batslib_decorate 'line should differ' \ + | fail + fi + fi + else + # Line contained in output. + if (( is_mode_regexp )); then + local -i idx + for (( idx = 0; idx < ${#lines[@]}; ++idx )); do + if [[ ${lines[$idx]} =~ $unexpected ]]; then + { local -ar single=( + 'regexp' "$unexpected" + 'index' "$idx" + ) + local -a may_be_multi=( + 'output' "$output" + ) + local -ir width="$( batslib_get_max_single_line_key_width \ + "${single[@]}" "${may_be_multi[@]}" )" + batslib_print_kv_single "$width" "${single[@]}" + if batslib_is_single_line "${may_be_multi[1]}"; then + batslib_print_kv_single "$width" "${may_be_multi[@]}" + else + may_be_multi[1]="$( printf '%s' "${may_be_multi[1]}" \ + | batslib_prefix \ + | batslib_mark '>' "$idx" )" + batslib_print_kv_multi "${may_be_multi[@]}" + fi + } | batslib_decorate 'no line should match the regular expression' \ + | fail + return $? + fi + done + elif (( is_mode_partial )); then + local -i idx + for (( idx = 0; idx < ${#lines[@]}; ++idx )); do + if [[ ${lines[$idx]} == *"$unexpected"* ]]; then + { local -ar single=( + 'substring' "$unexpected" + 'index' "$idx" + ) + local -a may_be_multi=( + 'output' "$output" + ) + local -ir width="$( batslib_get_max_single_line_key_width \ + "${single[@]}" "${may_be_multi[@]}" )" + batslib_print_kv_single "$width" "${single[@]}" + if batslib_is_single_line "${may_be_multi[1]}"; then + batslib_print_kv_single "$width" "${may_be_multi[@]}" + else + may_be_multi[1]="$( printf '%s' "${may_be_multi[1]}" \ + | batslib_prefix \ + | batslib_mark '>' "$idx" )" + batslib_print_kv_multi "${may_be_multi[@]}" + fi + } | batslib_decorate 'no line should contain substring' \ + | fail + return $? + fi + done + else + local -i idx + for (( idx = 0; idx < ${#lines[@]}; ++idx )); do + if [[ ${lines[$idx]} == "$unexpected" ]]; then + { local -ar single=( + 'line' "$unexpected" + 'index' "$idx" + ) + local -a may_be_multi=( + 'output' "$output" + ) + local -ir width="$( batslib_get_max_single_line_key_width \ + "${single[@]}" "${may_be_multi[@]}" )" + batslib_print_kv_single "$width" "${single[@]}" + if batslib_is_single_line "${may_be_multi[1]}"; then + batslib_print_kv_single "$width" "${may_be_multi[@]}" + else + may_be_multi[1]="$( printf '%s' "${may_be_multi[1]}" \ + | batslib_prefix \ + | batslib_mark '>' "$idx" )" + batslib_print_kv_multi "${may_be_multi[@]}" + fi + } | batslib_decorate 'line should not be in output' \ + | fail + return $? + fi + done + fi + fi +} diff --git a/tests/dependencies/bats-support/error.bash b/tests/dependencies/bats-support/error.bash new file mode 100755 index 0000000..e5d9791 --- /dev/null +++ b/tests/dependencies/bats-support/error.bash @@ -0,0 +1,41 @@ +# +# bats-support - Supporting library for Bats test helpers +# +# Written in 2016 by Zoltan Tombol +# +# To the extent possible under law, the author(s) have dedicated all +# copyright and related and neighboring rights to this software to the +# public domain worldwide. This software is distributed without any +# warranty. +# +# You should have received a copy of the CC0 Public Domain Dedication +# along with this software. If not, see +# . +# + +# +# error.bash +# ---------- +# +# Functions implementing error reporting. Used by public helper +# functions or test suits directly. +# + +# Fail and display a message. When no parameters are specified, the +# message is read from the standard input. Other functions use this to +# report failure. +# +# Globals: +# none +# Arguments: +# $@ - [=STDIN] message +# Returns: +# 1 - always +# Inputs: +# STDIN - [=$@] message +# Outputs: +# STDERR - message +fail() { + (( $# == 0 )) && batslib_err || batslib_err "$@" + return 1 +} diff --git a/tests/dependencies/bats-support/lang.bash b/tests/dependencies/bats-support/lang.bash new file mode 100755 index 0000000..c57e299 --- /dev/null +++ b/tests/dependencies/bats-support/lang.bash @@ -0,0 +1,73 @@ +# +# bats-util - Various auxiliary functions for Bats +# +# Written in 2016 by Zoltan Tombol +# +# To the extent possible under law, the author(s) have dedicated all +# copyright and related and neighboring rights to this software to the +# public domain worldwide. This software is distributed without any +# warranty. +# +# You should have received a copy of the CC0 Public Domain Dedication +# along with this software. If not, see +# . +# + +# +# lang.bash +# --------- +# +# Bash language and execution related functions. Used by public helper +# functions. +# + +# Check whether the calling function was called from a given function. +# +# By default, direct invocation is checked. The function succeeds if the +# calling function was called directly from the given function. In other +# words, if the given function is the next element on the call stack. +# +# When `--indirect' is specified, indirect invocation is checked. The +# function succeeds if the calling function was called from the given +# function with any number of intermediate calls. In other words, if the +# given function can be found somewhere on the call stack. +# +# Direct invocation is a form of indirect invocation with zero +# intermediate calls. +# +# Globals: +# FUNCNAME +# Options: +# -i, --indirect - check indirect invocation +# Arguments: +# $1 - calling function's name +# Returns: +# 0 - current function was called from the given function +# 1 - otherwise +batslib_is_caller() { + local -i is_mode_direct=1 + + # Handle options. + while (( $# > 0 )); do + case "$1" in + -i|--indirect) is_mode_direct=0; shift ;; + --) shift; break ;; + *) break ;; + esac + done + + # Arguments. + local -r func="$1" + + # Check call stack. + if (( is_mode_direct )); then + [[ $func == "${FUNCNAME[2]}" ]] && return 0 + else + local -i depth + for (( depth=2; depth<${#FUNCNAME[@]}; ++depth )); do + [[ $func == "${FUNCNAME[$depth]}" ]] && return 0 + done + fi + + return 1 +} diff --git a/tests/dependencies/bats-support/output.bash b/tests/dependencies/bats-support/output.bash new file mode 100755 index 0000000..c6cf6a6 --- /dev/null +++ b/tests/dependencies/bats-support/output.bash @@ -0,0 +1,279 @@ +# +# bats-support - Supporting library for Bats test helpers +# +# Written in 2016 by Zoltan Tombol +# +# To the extent possible under law, the author(s) have dedicated all +# copyright and related and neighboring rights to this software to the +# public domain worldwide. This software is distributed without any +# warranty. +# +# You should have received a copy of the CC0 Public Domain Dedication +# along with this software. If not, see +# . +# + +# +# output.bash +# ----------- +# +# Private functions implementing output formatting. Used by public +# helper functions. +# + +# Print a message to the standard error. When no parameters are +# specified, the message is read from the standard input. +# +# Globals: +# none +# Arguments: +# $@ - [=STDIN] message +# Returns: +# none +# Inputs: +# STDIN - [=$@] message +# Outputs: +# STDERR - message +batslib_err() { + { if (( $# > 0 )); then + echo "$@" + else + cat - + fi + } >&2 +} + +# Count the number of lines in the given string. +# +# TODO(ztombol): Fix tests and remove this note after #93 is resolved! +# NOTE: Due to a bug in Bats, `batslib_count_lines "$output"' does not +# give the same result as `${#lines[@]}' when the output contains +# empty lines. +# See PR #93 (https://github.com/sstephenson/bats/pull/93). +# +# Globals: +# none +# Arguments: +# $1 - string +# Returns: +# none +# Outputs: +# STDOUT - number of lines +batslib_count_lines() { + local -i n_lines=0 + local line + while IFS='' read -r line || [[ -n $line ]]; do + (( ++n_lines )) + done < <(printf '%s' "$1") + echo "$n_lines" +} + +# Determine whether all strings are single-line. +# +# Globals: +# none +# Arguments: +# $@ - strings +# Returns: +# 0 - all strings are single-line +# 1 - otherwise +batslib_is_single_line() { + for string in "$@"; do + (( $(batslib_count_lines "$string") > 1 )) && return 1 + done + return 0 +} + +# Determine the length of the longest key that has a single-line value. +# +# This function is useful in determining the correct width of the key +# column in two-column format when some keys may have multi-line values +# and thus should be excluded. +# +# Globals: +# none +# Arguments: +# $odd - key +# $even - value of the previous key +# Returns: +# none +# Outputs: +# STDOUT - length of longest key +batslib_get_max_single_line_key_width() { + local -i max_len=-1 + while (( $# != 0 )); do + local -i key_len="${#1}" + batslib_is_single_line "$2" && (( key_len > max_len )) && max_len="$key_len" + shift 2 + done + echo "$max_len" +} + +# Print key-value pairs in two-column format. +# +# Keys are displayed in the first column, and their corresponding values +# in the second. To evenly line up values, the key column is fixed-width +# and its width is specified with the first parameter (possibly computed +# using `batslib_get_max_single_line_key_width'). +# +# Globals: +# none +# Arguments: +# $1 - width of key column +# $even - key +# $odd - value of the previous key +# Returns: +# none +# Outputs: +# STDOUT - formatted key-value pairs +batslib_print_kv_single() { + local -ir col_width="$1"; shift + while (( $# != 0 )); do + printf '%-*s : %s\n' "$col_width" "$1" "$2" + shift 2 + done +} + +# Print key-value pairs in multi-line format. +# +# The key is displayed first with the number of lines of its +# corresponding value in parenthesis. Next, starting on the next line, +# the value is displayed. For better readability, it is recommended to +# indent values using `batslib_prefix'. +# +# Globals: +# none +# Arguments: +# $odd - key +# $even - value of the previous key +# Returns: +# none +# Outputs: +# STDOUT - formatted key-value pairs +batslib_print_kv_multi() { + while (( $# != 0 )); do + printf '%s (%d lines):\n' "$1" "$( batslib_count_lines "$2" )" + printf '%s\n' "$2" + shift 2 + done +} + +# Print all key-value pairs in either two-column or multi-line format +# depending on whether all values are single-line. +# +# If all values are single-line, print all pairs in two-column format +# with the specified key column width (identical to using +# `batslib_print_kv_single'). +# +# Otherwise, print all pairs in multi-line format after indenting values +# with two spaces for readability (identical to using `batslib_prefix' +# and `batslib_print_kv_multi') +# +# Globals: +# none +# Arguments: +# $1 - width of key column (for two-column format) +# $even - key +# $odd - value of the previous key +# Returns: +# none +# Outputs: +# STDOUT - formatted key-value pairs +batslib_print_kv_single_or_multi() { + local -ir width="$1"; shift + local -a pairs=( "$@" ) + + local -a values=() + local -i i + for (( i=1; i < ${#pairs[@]}; i+=2 )); do + values+=( "${pairs[$i]}" ) + done + + if batslib_is_single_line "${values[@]}"; then + batslib_print_kv_single "$width" "${pairs[@]}" + else + local -i i + for (( i=1; i < ${#pairs[@]}; i+=2 )); do + pairs[$i]="$( batslib_prefix < <(printf '%s' "${pairs[$i]}") )" + done + batslib_print_kv_multi "${pairs[@]}" + fi +} + +# Prefix each line read from the standard input with the given string. +# +# Globals: +# none +# Arguments: +# $1 - [= ] prefix string +# Returns: +# none +# Inputs: +# STDIN - lines +# Outputs: +# STDOUT - prefixed lines +batslib_prefix() { + local -r prefix="${1:- }" + local line + while IFS='' read -r line || [[ -n $line ]]; do + printf '%s%s\n' "$prefix" "$line" + done +} + +# Mark select lines of the text read from the standard input by +# overwriting their beginning with the given string. +# +# Usually the input is indented by a few spaces using `batslib_prefix' +# first. +# +# Globals: +# none +# Arguments: +# $1 - marking string +# $@ - indices (zero-based) of lines to mark +# Returns: +# none +# Inputs: +# STDIN - lines +# Outputs: +# STDOUT - lines after marking +batslib_mark() { + local -r symbol="$1"; shift + # Sort line numbers. + set -- $( sort -nu <<< "$( printf '%d\n' "$@" )" ) + + local line + local -i idx=0 + while IFS='' read -r line || [[ -n $line ]]; do + if (( ${1:--1} == idx )); then + printf '%s\n' "${symbol}${line:${#symbol}}" + shift + else + printf '%s\n' "$line" + fi + (( ++idx )) + done +} + +# Enclose the input text in header and footer lines. +# +# The header contains the given string as title. The output is preceded +# and followed by an additional newline to make it stand out more. +# +# Globals: +# none +# Arguments: +# $1 - title +# Returns: +# none +# Inputs: +# STDIN - text +# Outputs: +# STDOUT - decorated text +batslib_decorate() { + echo + echo "-- $1 --" + cat - + echo '--' + echo +} diff --git a/tests/dependencies/load.bash b/tests/dependencies/load.bash new file mode 100644 index 0000000..ddff87a --- /dev/null +++ b/tests/dependencies/load.bash @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +load dependencies/bats-support/output +load dependencies/bats-support/error +load dependencies/bats-support/lang +load dependencies/bats-assert/assert diff --git a/tests/dsta-console.bats b/tests/dsta-console.bats new file mode 100644 index 0000000..3aea748 --- /dev/null +++ b/tests/dsta-console.bats @@ -0,0 +1,71 @@ +#!/usr/bin/env bats + +load test_helper + +@test "dst-server console redirect" { + fixtures dsta-console + + docker run -d --name $CONTAINER $IMAGE + docker exec -i $CONTAINER dst-server console <"$FIXTURE_ROOT/commands.txt" + wait_until_loaded + sleep 1 + docker cp $CONTAINER:/var/lib/dsta/cluster/shard/server_log.txt "$TMP/server_log.txt" + + grep -F "RemoteCommandInput: \"foo bar\"" "$TMP/server_log.txt" + grep -F "RemoteCommandInput: \"bar\"" "$TMP/server_log.txt" +} + +@test "dst-server console - redirect" { + fixtures dsta-console + + docker run -d --name $CONTAINER $IMAGE + docker exec -i $CONTAINER dst-server console - <"$FIXTURE_ROOT/commands.txt" + wait_until_loaded + sleep 1 + docker cp $CONTAINER:/var/lib/dsta/cluster/shard/server_log.txt "$TMP/server_log.txt" + + grep -F "RemoteCommandInput: \"foo bar\"" "$TMP/server_log.txt" + grep -F "RemoteCommandInput: \"bar\"" "$TMP/server_log.txt" +} + +@test "dst-server console command" { + docker run -d --name $CONTAINER $IMAGE + docker exec -i $CONTAINER dst-server console "asdf" + wait_until_loaded + sleep 1 + docker cp $CONTAINER:/var/lib/dsta/cluster/shard/server_log.txt "$TMP/server_log.txt" + + grep -F "RemoteCommandInput: \"asdf\"" "$TMP/server_log.txt" +} + +@test "dst-server console command with redirect" { + fixtures dsta-console + + docker run -d --name $CONTAINER $IMAGE + docker exec -i $CONTAINER dst-server console "asdf" - "aaaaa" <"$FIXTURE_ROOT/commands.txt" + wait_until_loaded + sleep 1 + docker cp $CONTAINER:/var/lib/dsta/cluster/shard/server_log.txt "$TMP/server_log.txt" + + grep -F "RemoteCommandInput: \"asdf\"" "$TMP/server_log.txt" + grep -F "RemoteCommandInput: \"foo bar\"" "$TMP/server_log.txt" + grep -F "RemoteCommandInput: \"bar\"" "$TMP/server_log.txt" + grep -F "RemoteCommandInput: \"aaaaa\"" "$TMP/server_log.txt" +} + +@test "dst-server console command with redirect but not -" { + fixtures dsta-console + + docker run -d --name $CONTAINER $IMAGE + docker exec -i $CONTAINER dst-server console "asdf" "aaaaa" <"$FIXTURE_ROOT/commands.txt" + wait_until_loaded + sleep 1 + docker cp $CONTAINER:/var/lib/dsta/cluster/shard/server_log.txt "$TMP/server_log.txt" + + grep -F "RemoteCommandInput: \"asdf\"" "$TMP/server_log.txt" + grep -F "RemoteCommandInput: \"aaaaa\"" "$TMP/server_log.txt" + run grep -F "RemoteCommandInput: \"foo bar\"" "$TMP/server_log.txt" + assert_failure + run grep -F "RemoteCommandInput: \"bar\"" "$TMP/server_log.txt" + assert_failure +} diff --git a/tests/dsta-help.bats b/tests/dsta-help.bats new file mode 100644 index 0000000..703febe --- /dev/null +++ b/tests/dsta-help.bats @@ -0,0 +1,181 @@ +#!/usr/bin/env bats + +load test_helper + +##### +# dst-server +##### +@test "dst-server" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server + assert_failure + cat "$FIXTURE_ROOT/dst-server" | assert_output +} + +@test "dst-server help" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server help + assert_success + cat "$FIXTURE_ROOT/dst-server" | assert_output +} + +@test "dst-server --help" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server --help + assert_success + cat "$FIXTURE_ROOT/dst-server" | assert_output +} + +@test "dst-server with unknown argument" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server foo + assert_failure + cat "$FIXTURE_ROOT/dst-server" | assert_output +} + +@test "dst-server with unknown flag" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server --foo + assert_failure + cat "$FIXTURE_ROOT/dst-server" | assert_output +} + +##### +# dst-server start +##### +@test "dst-server help start" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server help start + assert_success + cat "$FIXTURE_ROOT/start" | assert_output +} + +@test "dst-server --help start" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server --help start + assert_success + cat "$FIXTURE_ROOT/start" | assert_output +} + +@test "dst-server start --help" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server start --help + assert_success + cat "$FIXTURE_ROOT/start" | assert_output +} + +##### +# dst-server update +##### +@test "dst-server help update" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server help update + assert_success + cat "$FIXTURE_ROOT/update" | assert_output +} + +@test "dst-server --help update" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server --help update + assert_success + cat "$FIXTURE_ROOT/update" | assert_output +} + +@test "dst-server update --help" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server update --help + assert_success + cat "$FIXTURE_ROOT/update" | assert_output +} + +##### +# dst-server log +##### +@test "dst-server help log" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server help log + assert_success + cat "$FIXTURE_ROOT/log" | assert_output +} + +@test "dst-server --help log" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server --help log + assert_success + cat "$FIXTURE_ROOT/log" | assert_output +} + +@test "dst-server log --help" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server log --help + assert_success + cat "$FIXTURE_ROOT/log" | assert_output +} + +##### +# dst-server console +##### +@test "dst-server help console" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server help console + assert_success + cat "$FIXTURE_ROOT/console" | assert_output +} + +@test "dst-server --help console" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server --help console + assert_success + cat "$FIXTURE_ROOT/console" | assert_output +} + +@test "dst-server console --help" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server console --help + assert_success + cat "$FIXTURE_ROOT/console" | assert_output +} + +##### +# dst-server version +##### +@test "dst-server help version" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server help version + assert_success + cat "$FIXTURE_ROOT/version" | assert_output +} + +@test "dst-server --help version" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server --help version + assert_success + cat "$FIXTURE_ROOT/version" | assert_output +} + +@test "dst-server version --help" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server version --help + assert_success + cat "$FIXTURE_ROOT/version" | assert_output +} diff --git a/tests/dsta-log.bats b/tests/dsta-log.bats new file mode 100644 index 0000000..483a9a1 --- /dev/null +++ b/tests/dsta-log.bats @@ -0,0 +1,60 @@ +#!/usr/bin/env bats + +load test_helper + +@test "Get the logs" { + fixtures dsta-log + + docker run -d --name $CONTAINER $IMAGE sleep infinity + docker exec $CONTAINER mkdir /var/lib/dsta/cluster/shard + docker exec $CONTAINER chown steam:steam /var/lib/dsta/cluster/shard + docker cp "$FIXTURE_ROOT/server_log.txt" $CONTAINER:/var/lib/dsta/cluster/shard/server_log.txt + docker cp "$FIXTURE_ROOT/server_log_chat.txt" $CONTAINER:/var/lib/dsta/cluster/shard/server_log_chat.txt + + docker exec $CONTAINER dst-server log >"$TMP/server_log.txt" + diff "$TMP/server_log.txt" "$FIXTURE_ROOT/server_log.txt" + docker exec $CONTAINER dst-server log --server >"$TMP/server_log.txt" + diff "$TMP/server_log.txt" "$FIXTURE_ROOT/server_log.txt" + docker exec $CONTAINER dst-server log --chat >"$TMP/server_log_chat.txt" + diff "$TMP/server_log_chat.txt" "$FIXTURE_ROOT/server_log_chat.txt" +} + +@test "Empty logs when the files doesn't exist" { + fixtures dsta-log + + docker run --rm -e NAME=foo $IMAGE dst-server log >"$TMP/std_output.txt" 2>"$TMP/err_output.txt" + diff "$TMP/std_output.txt" "$FIXTURE_ROOT/empty-file" + diff "$TMP/err_output.txt" "$FIXTURE_ROOT/empty-file" + + docker run --rm -e NAME=foo $IMAGE dst-server log --server >"$TMP/std_output.txt" 2>"$TMP/err_output.txt" + diff "$TMP/std_output.txt" "$FIXTURE_ROOT/empty-file" + diff "$TMP/err_output.txt" "$FIXTURE_ROOT/empty-file" + + docker run --rm -e NAME=foo $IMAGE dst-server log --chat >"$TMP/std_output.txt" 2>"$TMP/err_output.txt" + diff "$TMP/std_output.txt" "$FIXTURE_ROOT/empty-file" + diff "$TMP/err_output.txt" "$FIXTURE_ROOT/empty-file" +} + +@test "dst-server log fails with double flag" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server log --server --chat + assert_failure + cat "$FIXTURE_ROOT/log" | assert_output +} + +@test "dst-server log fails with unknown flag" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server log --type + assert_failure + cat "$FIXTURE_ROOT/log" | assert_output +} + +@test "dst-server log fails with parameter" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server log asd + assert_failure + cat "$FIXTURE_ROOT/log" | assert_output +} diff --git a/tests/dsta-start.bats b/tests/dsta-start.bats new file mode 100644 index 0000000..8b7e9a0 --- /dev/null +++ b/tests/dsta-start.bats @@ -0,0 +1,82 @@ +#!/usr/bin/env bats + +load test_helper + +@test "dst-server start" { + docker run -d --name $CONTAINER $IMAGE dst-server start + wait_until_loaded + if [ -z "`docker ps -qf name=$container_id`" ]; then + false + fi + run docker logs $CONTAINER + refute_line --partial "Success! App '343050' already up to date." + refute_line --partial "DownloadMods" +} + +@test "dst-server start --update=none" { + docker run -d --name $CONTAINER $IMAGE dst-server start --update=none + wait_until_loaded + if [ -z "`docker ps -qf name=$container_id`" ]; then + false + fi + run docker logs $CONTAINER + refute_line --partial "Success! App '343050' already up to date." + refute_line --partial "DownloadMods" +} + +@test "dst-server start --update=all" { + docker run -d --name $CONTAINER $IMAGE dst-server start --update=all + wait_until_loaded + if [ -z "`docker ps -qf name=$container_id`" ]; then + false + fi + run docker logs $CONTAINER + assert_line --partial "Success! App '343050' already up to date." + assert_line --partial "DownloadMods" +} + +@test "dst-server start --update=game" { + docker run -d --name $CONTAINER $IMAGE dst-server start --update=game + wait_until_loaded + if [ -z "`docker ps -qf name=$container_id`" ]; then + false + fi + run docker logs $CONTAINER + assert_line --partial "Success! App '343050' already up to date." + refute_line --partial "DownloadMods" +} + +@test "dst-server start --update=mods" { + docker run -d --name $CONTAINER $IMAGE dst-server start --update=mods + wait_until_loaded + if [ -z "`docker ps -qf name=$container_id`" ]; then + false + fi + run docker logs $CONTAINER + refute_line --partial "Success! App '343050' already up to date." + assert_line --partial "DownloadMods" +} + +@test "dst-server start fails with unknow value in flag" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server start --update=foo + assert_failure + cat "$FIXTURE_ROOT/start" | assert_output +} + +@test "dst-server start fails with unknown flag" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server start --game + assert_failure + cat "$FIXTURE_ROOT/start" | assert_output +} + +@test "dst-server start fails with parameter" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server start asd + assert_failure + cat "$FIXTURE_ROOT/start" | assert_output +} diff --git a/tests/dsta-update.bats b/tests/dsta-update.bats new file mode 100644 index 0000000..9d94fdb --- /dev/null +++ b/tests/dsta-update.bats @@ -0,0 +1,79 @@ +#!/usr/bin/env bats + +load test_helper + +@test "dst-server update" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server update + assert_success + assert_line "Success! App '343050' already up to date." + assert_line --partial "DownloadMods" +} + +@test "dst-server update --all" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server update --all + assert_success + assert_line "Success! App '343050' already up to date." + assert_line --partial "DownloadMods" +} + +@test "dst-server update --game" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server update --game + assert_success + assert_line "Success! App '343050' already up to date." + refute_line --partial "DownloadMods" +} + +@test "dst-server update --mods" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server update --mods + assert_success + refute_line "Success! App '343050' already up to date." + assert_line --partial "DownloadMods" +} + +@test "dst-server update -- too much flags 1" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server update --game --mods + assert_failure + cat $FIXTURE_ROOT/update | assert_output +} + +@test "dst-server update -- too much flags 2" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server update --all --game + assert_failure + cat $FIXTURE_ROOT/update | assert_output +} + +@test "dst-server update -- repeat flags" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server update --game --game + assert_failure + cat $FIXTURE_ROOT/update | assert_output +} + +@test "dst-server update -- Unknown argument" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server update foo + assert_failure + cat $FIXTURE_ROOT/update | assert_output +} + +@test "dst-server update -- Unknown flag" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server update --foo + assert_failure + cat $FIXTURE_ROOT/update | assert_output +} diff --git a/tests/dsta-version.bats b/tests/dsta-version.bats new file mode 100644 index 0000000..29afa2f --- /dev/null +++ b/tests/dsta-version.bats @@ -0,0 +1,36 @@ +#!/usr/bin/env bats + +load test_helper + +@test "dst-server version" { + docker run --rm $IMAGE dst-server version +} + +@test "dst-server version --local" { + run docker run --rm $IMAGE dst-server version --local + assert_success + assert_output --regexp '^[0-9]+$' +} + +@test "dst-server version --upstream" { + run docker run --rm $IMAGE dst-server version --upstream + assert_success + assert_output --regexp '^[0-9]+$' +} + +@test "dst-server version --check" { + run docker run --rm $IMAGE dst-server version --check + if [ $status -eq 0 ]; then + assert_output "Version is up to date." + else + assert_output "Version is outdated." + fi +} + +@test "dst-server version unknown flag" { + fixtures dsta-help + + run docker run --rm $IMAGE dst-server version --foo + assert_failure + cat "$FIXTURE_ROOT/version" | assert_output +} diff --git a/tests/entrypoint.bats b/tests/entrypoint.bats new file mode 100644 index 0000000..ca3be2a --- /dev/null +++ b/tests/entrypoint.bats @@ -0,0 +1,19 @@ +#!/usr/bin/env bats + +load test_helper + +@test "The image know how to run any kind of command" { + docker run --rm $IMAGE echo OK >"$TMP/std_output" + echo OK >"$TMP/std_output_expected" + diff "$TMP/std_output" "$TMP/std_output_expected" +} + +@test "docker-entrypoint.sh successed if the command successed" { + run $BUILD/docker-entrypoint.sh true + assert_success +} + +@test "docker-entrypoint.sh fails if the command fails" { + run $BUILD/docker-entrypoint.sh false + assert_failure +} diff --git a/tests/fixtures/boot-lists/bar.txt b/tests/fixtures/boot-lists/bar.txt new file mode 100644 index 0000000..5716ca5 --- /dev/null +++ b/tests/fixtures/boot-lists/bar.txt @@ -0,0 +1 @@ +bar diff --git a/tests/fixtures/boot-lists/foo.txt b/tests/fixtures/boot-lists/foo.txt new file mode 100644 index 0000000..257cc56 --- /dev/null +++ b/tests/fixtures/boot-lists/foo.txt @@ -0,0 +1 @@ +foo diff --git a/tests/fixtures/boot-lists/list.txt b/tests/fixtures/boot-lists/list.txt new file mode 100644 index 0000000..ac8d272 --- /dev/null +++ b/tests/fixtures/boot-lists/list.txt @@ -0,0 +1,3 @@ +foo +bar +xy_:z diff --git a/tests/fixtures/boot-mods/foo-bar-with-overrides/dedicated_server_mods_setup.lua-tail b/tests/fixtures/boot-mods/foo-bar-with-overrides/dedicated_server_mods_setup.lua-tail new file mode 100644 index 0000000..0875c27 --- /dev/null +++ b/tests/fixtures/boot-mods/foo-bar-with-overrides/dedicated_server_mods_setup.lua-tail @@ -0,0 +1,2 @@ +ServerModSetup("foo") +ServerModSetup("bar") diff --git a/tests/fixtures/boot-mods/foo-bar-with-overrides/modoverrides.lua b/tests/fixtures/boot-mods/foo-bar-with-overrides/modoverrides.lua new file mode 100644 index 0000000..cd470e6 --- /dev/null +++ b/tests/fixtures/boot-mods/foo-bar-with-overrides/modoverrides.lua @@ -0,0 +1 @@ +xyz diff --git a/tests/fixtures/boot-mods/foo-bar/dedicated_server_mods_setup.lua-tail b/tests/fixtures/boot-mods/foo-bar/dedicated_server_mods_setup.lua-tail new file mode 100644 index 0000000..0875c27 --- /dev/null +++ b/tests/fixtures/boot-mods/foo-bar/dedicated_server_mods_setup.lua-tail @@ -0,0 +1,2 @@ +ServerModSetup("foo") +ServerModSetup("bar") diff --git a/tests/fixtures/boot-mods/foo-bar/modoverrides.lua b/tests/fixtures/boot-mods/foo-bar/modoverrides.lua new file mode 100644 index 0000000..a0f817e --- /dev/null +++ b/tests/fixtures/boot-mods/foo-bar/modoverrides.lua @@ -0,0 +1,4 @@ +return { + ["workshop-foo"] = { enabled = true }, + ["workshop-bar"] = { enabled = true }, +} diff --git a/tests/fixtures/boot-mods/foo/dedicated_server_mods_setup.lua-tail b/tests/fixtures/boot-mods/foo/dedicated_server_mods_setup.lua-tail new file mode 100644 index 0000000..e0feb11 --- /dev/null +++ b/tests/fixtures/boot-mods/foo/dedicated_server_mods_setup.lua-tail @@ -0,0 +1 @@ +ServerModSetup("foo") diff --git a/tests/fixtures/boot-mods/foo/modoverrides.lua b/tests/fixtures/boot-mods/foo/modoverrides.lua new file mode 100644 index 0000000..26fa471 --- /dev/null +++ b/tests/fixtures/boot-mods/foo/modoverrides.lua @@ -0,0 +1,3 @@ +return { + ["workshop-foo"] = { enabled = true }, +} diff --git a/tests/fixtures/boot-token/token1 b/tests/fixtures/boot-token/token1 new file mode 100644 index 0000000..1d565f8 --- /dev/null +++ b/tests/fixtures/boot-token/token1 @@ -0,0 +1 @@ +token-1 \ No newline at end of file diff --git a/tests/fixtures/boot-token/token2 b/tests/fixtures/boot-token/token2 new file mode 100644 index 0000000..0772c1d --- /dev/null +++ b/tests/fixtures/boot-token/token2 @@ -0,0 +1 @@ +token-2 \ No newline at end of file diff --git a/tests/fixtures/boot-world/foo b/tests/fixtures/boot-world/foo new file mode 100644 index 0000000..257cc56 --- /dev/null +++ b/tests/fixtures/boot-world/foo @@ -0,0 +1 @@ +foo diff --git a/tests/fixtures/boot-world/foo2 b/tests/fixtures/boot-world/foo2 new file mode 100644 index 0000000..54b060e --- /dev/null +++ b/tests/fixtures/boot-world/foo2 @@ -0,0 +1 @@ +foo2 diff --git a/tests/fixtures/build-mods/one-mod/dedicated_server_mods_setup.lua b/tests/fixtures/build-mods/one-mod/dedicated_server_mods_setup.lua new file mode 100644 index 0000000..3154855 --- /dev/null +++ b/tests/fixtures/build-mods/one-mod/dedicated_server_mods_setup.lua @@ -0,0 +1,12 @@ +--There are two functions that will install mods, ServerModSetup and ServerModCollectionSetup. Put the calls to the functions in this file and they will be executed on boot. + +--ServerModSetup takes a string of a specific mod's Workshop id. It will download and install the mod to your mod directory on boot. + --The Workshop id can be found at the end of the url to the mod's Workshop page. + --Example: http://steamcommunity.com/sharedfiles/filedetails/?id=350811795 + --ServerModSetup("350811795") + +--ServerModCollectionSetup takes a string of a specific mod's Workshop id. It will download all the mods in the collection and install them to the mod directory on boot. + --The Workshop id can be found at the end of the url to the collection's Workshop page. + --Example: http://steamcommunity.com/sharedfiles/filedetails/?id=379114180 + --ServerModCollectionSetup("379114180") +ServerModSetup("378160973") diff --git a/tests/fixtures/build-mods/two-mods/dedicated_server_mods_setup.lua b/tests/fixtures/build-mods/two-mods/dedicated_server_mods_setup.lua new file mode 100644 index 0000000..044387b --- /dev/null +++ b/tests/fixtures/build-mods/two-mods/dedicated_server_mods_setup.lua @@ -0,0 +1,13 @@ +--There are two functions that will install mods, ServerModSetup and ServerModCollectionSetup. Put the calls to the functions in this file and they will be executed on boot. + +--ServerModSetup takes a string of a specific mod's Workshop id. It will download and install the mod to your mod directory on boot. + --The Workshop id can be found at the end of the url to the mod's Workshop page. + --Example: http://steamcommunity.com/sharedfiles/filedetails/?id=350811795 + --ServerModSetup("350811795") + +--ServerModCollectionSetup takes a string of a specific mod's Workshop id. It will download all the mods in the collection and install them to the mod directory on boot. + --The Workshop id can be found at the end of the url to the collection's Workshop page. + --Example: http://steamcommunity.com/sharedfiles/filedetails/?id=379114180 + --ServerModCollectionSetup("379114180") +ServerModSetup("378160973") +ServerModSetup("380423963") diff --git a/test/close-cleanly/commands.sh b/tests/fixtures/close-cleanly/commands.sh similarity index 100% rename from test/close-cleanly/commands.sh rename to tests/fixtures/close-cleanly/commands.sh diff --git a/test/console/commands.sh b/tests/fixtures/console/commands.sh similarity index 57% rename from test/console/commands.sh rename to tests/fixtures/console/commands.sh index 26dc881..f1c6ea3 100755 --- a/test/console/commands.sh +++ b/tests/fixtures/console/commands.sh @@ -1,4 +1,4 @@ #!/usr/bin/env bash -echo foo > /usr/local/share/dsta/console +echo foo bar > /usr/local/share/dsta/console echo bar > /usr/local/share/dsta/console diff --git a/tests/fixtures/dsta-console/commands.txt b/tests/fixtures/dsta-console/commands.txt new file mode 100644 index 0000000..f0468ac --- /dev/null +++ b/tests/fixtures/dsta-console/commands.txt @@ -0,0 +1,2 @@ +foo bar +bar diff --git a/tests/fixtures/dsta-help/console b/tests/fixtures/dsta-help/console new file mode 100644 index 0000000..0a7c475 --- /dev/null +++ b/tests/fixtures/dsta-help/console @@ -0,0 +1,5 @@ +usage: dst-server console [command ...] + +The console utility executes commands in the Don't Starve Together server console. +The commands are executed in command-line order. +If command is a single dash ('-') or absent, console reads from the standard input. diff --git a/tests/fixtures/dsta-help/dst-server b/tests/fixtures/dsta-help/dst-server new file mode 100644 index 0000000..35d1283 --- /dev/null +++ b/tests/fixtures/dsta-help/dst-server @@ -0,0 +1,10 @@ +usage: dst-server [--help] [] + +The commands are: + start Start the server + console Execute commands on the server console + update Update game and/or mods + log Show a log + version Show the current server version + +See 'dst-server help ' to read about a specific command. diff --git a/tests/fixtures/dsta-help/log b/tests/fixtures/dsta-help/log new file mode 100644 index 0000000..88d0e0f --- /dev/null +++ b/tests/fixtures/dsta-help/log @@ -0,0 +1 @@ +usage: dst-server log [--server|--chat] diff --git a/tests/fixtures/dsta-help/start b/tests/fixtures/dsta-help/start new file mode 100644 index 0000000..5b143a7 --- /dev/null +++ b/tests/fixtures/dsta-help/start @@ -0,0 +1,22 @@ +usage: dst-server start [--update=all|none|game|mods] + [--keep-configuration=]...>] + + --update=none + Update nothing, just start the server. This is the default behaviour. + --update=all + Update the game and the mods before launch the server. + --update=game + Update just the game (no the mods) and launch the server. + --update=mods + Update the mods and launch the server. + --keep-configuration + Select which configuration you don't want to overwrite. + You must provide one or more of these values separated by commas: + - token + - cluster + - server + - world + - adminlist + - blocklist + - whitelist + - mods diff --git a/tests/fixtures/dsta-help/update b/tests/fixtures/dsta-help/update new file mode 100644 index 0000000..13f7546 --- /dev/null +++ b/tests/fixtures/dsta-help/update @@ -0,0 +1 @@ +usage: dst-server update [--all|--game|--mods] diff --git a/tests/fixtures/dsta-help/version b/tests/fixtures/dsta-help/version new file mode 100644 index 0000000..893ba6f --- /dev/null +++ b/tests/fixtures/dsta-help/version @@ -0,0 +1,10 @@ +usage: dst-server version [--local|--upstream|--check] + +Print the local and upstream version of the DST server. + + --local + Return the local version. + --upstream + Return the currently released upstream version. + --check + Check if the currently running version is up to date. diff --git a/tests/fixtures/dsta-log/empty-file b/tests/fixtures/dsta-log/empty-file new file mode 100644 index 0000000..e69de29 diff --git a/tests/fixtures/dsta-log/server_log.txt b/tests/fixtures/dsta-log/server_log.txt new file mode 100644 index 0000000..beec616 --- /dev/null +++ b/tests/fixtures/dsta-log/server_log.txt @@ -0,0 +1 @@ +C3857C96-3757-4A96-8857-75E02CBCE829 diff --git a/tests/fixtures/dsta-log/server_log_chat.txt b/tests/fixtures/dsta-log/server_log_chat.txt new file mode 100644 index 0000000..eb98de5 --- /dev/null +++ b/tests/fixtures/dsta-log/server_log_chat.txt @@ -0,0 +1 @@ +0E2A1A92-D047-4CAD-AC53-0F42FADAD9F3 diff --git a/tests/test_helper.bash b/tests/test_helper.bash new file mode 100644 index 0000000..c618384 --- /dev/null +++ b/tests/test_helper.bash @@ -0,0 +1,32 @@ +#!/usr/bin/env bash + +load dependencies/load + +export BUILD="$BATS_TEST_DIRNAME/../build" +export IMAGE="dstacademy/dontstarvetogether" +export CONTAINER="dstacademy-test" +export TMP="$BATS_TEST_DIRNAME/tmp" + +fixtures() { + FIXTURE_ROOT="$BATS_TEST_DIRNAME/fixtures/$1" + RELATIVE_FIXTURE_ROOT="$(bats_trim_filename "$FIXTURE_ROOT")" +} + +setup() { + mkdir "$TMP" + + docker build -t $IMAGE $BUILD +} + +teardown() { + docker rm -fv "$CONTAINER" >/dev/null + rm -rf "$TMP" +} + +wait_until_initializing() { + docker logs --follow $CONTAINER | sed '/Starting Up$/ q' >/dev/null +} + +wait_until_loaded() { + docker logs --follow $CONTAINER | sed '/LOADING LUA SUCCESS$/ q' >/dev/null +} From c03427edc8d69da006145b6c7bd182945faab2ae Mon Sep 17 00:00:00 2001 From: Thomas Deinhamer Date: Sun, 31 Dec 2017 13:20:17 +0100 Subject: [PATCH 26/28] Update CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 529ea58..1dfbfa1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [next] ### Added +- Introduce a `MODS` build-variable to support pre-built images with pre-installed mods. - Add support for the `leveldataoverride.lua` file via the `LEVELDATA_OVERRIDES` env-variable. - Configure the Docker `HEALTHCHECK` command running `dst-server version --check`. - Add a `keep-configuration` boot option to define how existing configuration files should be handled. @@ -11,6 +12,7 @@ - Update the base-image to `dstacademy/steamcmd:0.3`. - Overwrite configuration files by default when starting a container. - Do not expose/configure a default port in the `Dockerfile` anymore. +- Refactor tests to use `bats`. ### Removed - Remove the `WORLD_OVERRIDES` env-variable and `worldgenoverride.lua` file. From 6b61e06623040c1ed4ff82d19e5891c15a2e7602 Mon Sep 17 00:00:00 2001 From: Thomas Deinhamer Date: Sun, 31 Dec 2017 13:59:02 +0100 Subject: [PATCH 27/28] Add documentation for the dst-server shell commands --- README.md | 2 ++ docs/commands.md | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 docs/commands.md diff --git a/README.md b/README.md index 697a943..64d3f1d 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ for the online multi-player survival game [*Don't Starve Together*][website]. ## Documentation - [Setup][docs-setup] - [Configuration][docs-configuration] +- [Commands][docs-commands] - [Usage][docs-usage] - [Examples][docs-examples] @@ -53,6 +54,7 @@ Check out our [contribution guide][contribution-guide]. [docs-setup]: /docs/setup.md [docs-configuration]: /docs/configuration.md +[docs-commands]: /docs/commands.md [docs-usage]: /docs/usage.md [docs-examples]: /docs/examples/ [website]: http://www.dontstarvetogether.com/ diff --git a/docs/commands.md b/docs/commands.md new file mode 100644 index 0000000..79be1d6 --- /dev/null +++ b/docs/commands.md @@ -0,0 +1,53 @@ +# Commands + +Commands are used to start the server with specific options, +control it and get information about it, while it's running. + +## `start` +Start the DST server. + +**Options** +* `--update=[none|all|game|mods]` Enable or disable running updates on boot. +* `--keep-configuration=[token|cluster|server|world|mods|adminlist|whitelist|blocklist]` Configure overwriting of files. + +**Examples** +* `dst-server start` Start the server, do not run updates and overwrite existing configuration files. +* `dst-server start --update=all` Start the server and update the game and mods on every boot/reboot. +* `dst-server start --update=game` Start the server and update the game on every boot/reboot only. +* `dst-server start --update=mods` Start the server and update installed mods on every boot/reboot. +* `dst-server start --update=none` Start the server and don't update the game or mods. +* `dst-server start --keep-configuration` Start the server and do not overwrite any existing files. +* `dst-server start --keep-configuration=token` Start the server and overwrite existing files except the token-file. +* `dst-server start --keep-configuration=token,world` Start the server without overwriting token and world files. + +## `version` +Print the game's version. + +**Options** +* `--local` Print the current running version of the game. +* `--upstream` Print the current released version of the game. +* `--check` Check if the upstream version is newer than the local running one. + +**Examples** +* `dst-server version` Print the current running version and the available upstream version. +* `dst-server version --local` Print the current running version of the game. +* `dst-server version --upstream` Print the current available, released version of the game. +* `dst-server version --check` Check if the upstream version is newer than the running version. + +## `log` +Read contents of various game-server log files. + +**Options** +* `--server` Print the server log. +* `--chat` Print the chat log + +**Examples** +* `dst-server log --server` Print the server log. +* `dst-server log --chat` Print the chat log. + +## `console` +Execute a command on the in-game server-console. + +**Examples** +* `dst-server console c_reset()` Run `c_reset()` on the console which resets the world. +* `dst-server console c_announce('Hello!')` Run `c_announce('Hello!')` on the console which broadcasts a message. From 76204cced7e603c645a9e9d6f158576afa843546 Mon Sep 17 00:00:00 2001 From: Thomas Deinhamer Date: Sun, 31 Dec 2017 14:06:17 +0100 Subject: [PATCH 28/28] Update CHANGELOG --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1dfbfa1..8de4d93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## [next] +## [0.8.0] + ### Added - Introduce a `MODS` build-variable to support pre-built images with pre-installed mods. - Add support for the `leveldataoverride.lua` file via the `LEVELDATA_OVERRIDES` env-variable. @@ -142,7 +144,8 @@ ### Added - Initial release. -[next]: https://github.com/dst-academy/docker-dontstarvetogether/compare/v0.7.1...HEAD +[next]: https://github.com/dst-academy/docker-dontstarvetogether/compare/v0.8.0...HEAD +[0.8.0]: https://github.com/dst-academy/docker-dontstarvetogether/compare/v0.7.1...v0.8.0 [0.7.1]: https://github.com/dst-academy/docker-dontstarvetogether/compare/v0.7.0...v0.7.1 [0.7.0]: https://github.com/dst-academy/docker-dontstarvetogether/compare/v0.6.0...v0.7.0 [0.6.0]: https://github.com/dst-academy/docker-dontstarvetogether/compare/v0.5.0...v0.6.0