diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 0000000..ff4479a --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,53 @@ +name: Build & Test + +on: + pull_request: + branches: + - main + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout main + uses: actions/checkout@v4 + + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + + - name: Install Just + uses: extractions/setup-just@v2 + + - name: Install dependencies + run: | + + sudo apt-get install build-essential libncursesw5-dev bison flex liblua5.1-0-dev \ + libsqlite3-dev libz-dev pkg-config python3-yaml binutils-gold python-is-python3 \ + bzip2 ncurses-term locales-all sqlite3 libpcre3 liblua5.1-0 locales autoconf \ + lsof flex libbot-basicbot-perl lua5.1 man libpng-dev python3-tornado + + - name: Build DCSS Webtiles (multiple versions) + run: just setup-dcss-server + + - name: Run DCSS Webtiles + run: | + python3 crawl/server/server.py & + sleep 5 + + - name: Create users + run: just dcss-create-users + + - name: Test Rust dcss-api + run: just test-api + + - name: Test Rust dcss-scenario-builder + run: just test-scenario + + - name: Setup python dcss-api + run: just setup-python + + - name: Test python dcss-api + run: just test-python diff --git a/Justfile b/Justfile index 85eb7fc..1ec069b 100644 --- a/Justfile +++ b/Justfile @@ -28,8 +28,8 @@ setup-dcss-server: cp -r ./crawl/dcss-0.32/crawl-ref/source/webserver/. ./crawl/server sed -i -e 's/subprocess.signal/signal_module/g' ./crawl/server/webtiles/process_handler.py sed -i -e 's/import subprocess/import signal as signal_module/g' ./crawl/server/webtiles/process_handler.py - cp ./tests/config/config.py ./crawl/server/config.py - cp ./tests/config/init-player.sh ./crawl/server/init-player.sh + cp ./crawl-config/config.py ./crawl/server/config.py + cp ./crawl-config/init-player.sh ./crawl/server/init-player.sh echo save_dir = ./crawl/server/saves-0.29 > ./crawl/server/init-0.29.txt echo save_dir = ./crawl/server/saves-0.30 > ./crawl/server/init-0.30.txt echo save_dir = ./crawl/server/saves-0.31 > ./crawl/server/init-0.31.txt @@ -37,11 +37,11 @@ setup-dcss-server: rm -rf ./crawl/main -dcss-create-users: - cd ./dcss-api && cargo -r run --example 0_setup - dcss-run: - python crawl/server/server.py + python3 crawl/server/server.py + +dcss-create-users: + cd ./dcss-api && cargo run -r --example 0_setup dcss-clear: rm -rf ./saves @@ -62,20 +62,29 @@ dcss-disable-logging: sed -i -e 's/print("SENT FROM DCSS: ", msg, data)/# type: (str, Any) -> bool/g' ./crawl/server/webtiles/ws_handler.py test-api: - cd ./dcss-api && cargo test + cd ./dcss-api && GAME_ID=dcss-0.29 cargo test + cd ./dcss-api && GAME_ID=dcss-0.30 cargo test + cd ./dcss-api && GAME_ID=dcss-0.31 cargo test + cd ./dcss-api && GAME_ID=dcss-0.32 cargo test test-scenario: - cd ./dcss-scenario-builder && cargo test + cd ./dcss-scenario-builder && GAME_ID=dcss-0.29 cargo test + cd ./dcss-scenario-builder && GAME_ID=dcss-0.30 cargo test + cd ./dcss-scenario-builder && GAME_ID=dcss-0.31 cargo test + cd ./dcss-scenario-builder && GAME_ID=dcss-0.32 cargo test setup-python: rm -rf ./dcss-api-python/pyo3 mkdir ./dcss-api-python/pyo3 python -m venv ./dcss-api-python/pyo3 - source ./dcss-api-python/pyo3/bin/activate && cd ./dcss-api-python/ && pip install maturin patchelf pytest - source ./dcss-api-python/pyo3/bin/activate && cd ./dcss-api-python/ && maturin develop -r + . ./dcss-api-python/pyo3/bin/activate && cd ./dcss-api-python/ && pip install maturin patchelf pytest + . ./dcss-api-python/pyo3/bin/activate && cd ./dcss-api-python/ && maturin develop -r test-python: - source ./dcss-api-python/pyo3/bin/activate && pytest ./dcss-api-python/tests + . ./dcss-api-python/pyo3/bin/activate && GAME_ID=dcss-0.29 pytest ./dcss-api-python/tests + . ./dcss-api-python/pyo3/bin/activate && GAME_ID=dcss-0.30 pytest ./dcss-api-python/tests + . ./dcss-api-python/pyo3/bin/activate && GAME_ID=dcss-0.31 pytest ./dcss-api-python/tests + . ./dcss-api-python/pyo3/bin/activate && GAME_ID=dcss-0.32 pytest ./dcss-api-python/tests cargo-update: cd ./dcss-api && cargo update diff --git a/crawl-config/config.py b/crawl-config/config.py index 49603a2..6ef4f4f 100644 --- a/crawl-config/config.py +++ b/crawl-config/config.py @@ -1,190 +1,28 @@ -# ### Server Operators ### -# If you want to customise any settings in this file, you'll need to work around -# the fact that is version controlled. Some options: -# 1. Use a local commit and always do a rebase pull on top of it. (This may -# affect versioning, though.) -# 2. Create config.yml and write your overrides in there. -# 3. Use a more complicated scripting system; for example, dgamelaunch-config -# supports templating this file and automatically handles merging the -# server config with the repository files. -# -# ### Developers ### -# Warning! Servers will not update or merge with the version controlled copy of -# this file, so any parameters here should be presented as recommendations or -# documentation of the default, not a default value, and option name changes -# here will require manual intervention on the part of server admins. New -# values should always come with a default that does not lead to crashes, so -# that something sensible happens on DGL upgrade. -# -# To add new default values, see the `webtiles.config` module. Note that -# webtiles.config.get(x) returns `None` if `x` is not present in the config -# data, so this can be taken as a default default value. -# -# Bad assumptions about config defaults particularly impacts templated html -# files, which are loaded and called dynamically, so *do* get updated -# immediately on a rebuild (unlike python code in this module or -# webtiles.config). If something like client.html raises an exception, this -# will trigger 500 errors across the whole server. - import logging import os - +import collections import yaml -# Where to look for `games.d/`, `config.yml`, and other things. server_path = os.path.dirname(os.path.abspath(__file__)) -# Set to False to enable `local webtiles` mode: the regular webtiles lobby -# is disabled, and opening webtiles loads the game main menu. (default: True) -# dgl_mode = False - -# to enable ttyrec writing at the server level: -# enable_ttyrecs = False - -# set `bind_nonsecure` to False to use only SSL. Set to `"redirect"` to bind -# the nonsecure ports as indicated, but redirect them to an SSL port. bind_nonsecure = True bind_address = "" bind_port = 8080 -# Or listen on multiple address/port pairs (overriding the above) with: -# bind_pairs = ( -# ("127.0.0.1", 8080), -# ("localhost", 8082), -# ("", 8180), # All addresses -# ) - -# set `ssl_options` to Tornado ssl options in order to use ssl on the specified -# port. For a real deployment, in addition to certfile/keyfile as below, you -# will probably need to provide "ca_certs" with your full CA cert chain. -# The server needs read access to keyfile when accepting new connections, so -# it should be readable by the user running the server (not just root). -# -# For local testing, you can generate a self-signed cert with a command like: -# ``` -# openssl req -x509 -out localhost.crt -keyout localhost.key \ -# -newkey rsa:2048 -nodes -sha256 \ -# -subj '/CN=localhost' -extensions EXT -config <( \ -# printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth") -# ``` -# (this sort of cert will generate security warnings in modern browsers, so it -# is appropriate only for development use) - ssl_options = None # No SSL -# ssl_options = { -# "certfile": "./webserver/localhost.crt", -# "keyfile": "./webserver/localhost.key" -# } ssl_address = "" ssl_port = 8443 -# Or listen on multiple address/port pairs (overriding the above) with: -# ssl_bind_pairs = ( -# ("127.0.0.1", 8081), -# ("localhost", 8083), -# ) - -# to log to a file directly, uncomment and add something like: -# "filename": "webtiles.log", -# logging_config = { -# "level": logging.INFO, -# "format": "%(asctime)s %(levelname)s: %(message)s" -# } - -# sometimes useful for debugging: -# logging.getLogger('asyncio').setLevel(logging.DEBUG) - password_db = "./crawl/server/passwd.db3" -# Uncomment and change if you want this db somewhere separate from the -# password_db location. -#settings_db = "./webserver/user_settings.db3" static_path = "./crawl/server/static" template_path = "./crawl/server/templates/" -# Path for server-side unix sockets (to be used to communicate with crawl) -# server_socket_path = None # None: Uses global temp dir - -# Server name, so far only used in the ttyrec metadata server_id = "" -# Disable caching of game data files game_data_no_cache = True -# Watch socket dirs for games not started by the server -# watch_socket_dirs = False - -################ -# Game configs -################ -# -# The webtiles server needs some game modes configured in order to run. The -# default in-repo configuration enables regular mode, seeded, tutorial, and -# sprint for the `crawl` binary as built in the repository. (Build with -# `WEBTILES=y`.) -# -# You can define game configs in two ways: -# 1. As *.yml files in `games.d/`. (default; see games.d/base.yml) -# 2. With a dictionary `games` in this file -# -# Both of these formats are essentially the same. See the commented examples -# below, as well as the comments and examples in games.d/base.yml for more -# information on the format and how it is used. Examples from production -# servers are also available in branches of the repository: -# https://github.com/crawl/dgamelaunch-config -# (These are further templated using the scripts in that package.) - -# to override yml loading, simply set `games` in this file; see the example -# below. To force using both sources, set `use_game_yaml` to True. Games -# defined in this file will precede games defined in games.d. Templates -# defined in this file are always loaded. -# use_game_yaml = True - -# Templating game configurations: -# You can define a set of parameters to use as a template across multiple -# game configs. To use a template by name, use the `template` parameter. -# Recursive templating is supported. If a template named `default` is defined, -# it will be used as the template for any game definitions that specify no -# template at all (see example below). If `default` is defined, it can be -# explicitly overridden by using the template name `base` (which cannot be -# redefined). - -# Templating string values: -# if the `version` key is set, most game parameters will support templating -# with %v, %V, and %r. -# %v: the version value as-is -# %V: the capitalized version value (e.g. "trunk" -> "Trunk") -# %r: the 'raw' version, which strips off an initial "0.". So for example, -# "0.29" would give just "29". If this substring does not occur, %r -# is equivalent to %v. (Implementation note: characters before a "0." -# will be dropped as well. Not relevant for normal crawl versions of -# course.) -# -# Most fields (though not all, in particular, not any game-general ones and -# not socket_path) also support templating with %n, which gives the player's -# username. -# -# The bare minimum necessary fields are what it takes to get the crawl binary -# running. Games are called with the following argv; some of these fields can -# be inferred when not set. -# [ -# $crawl_binary, -# *$pre_options, -# "-name", "%n", -# "-rc", "$rcfile_path/%n.rc", -# "-macro", "$macro_path/%n.macro", -# "-morgue", "$morgue_path," -# *$options, -# "-dir", "$dir_path" -# "-webtiles-socket", "$socket_path/%n:$timestamp.sock", -# "-await-connection" -# ] -# -# The example below illustrates basic uses of both of these. - -# Non-templated example: it's possible just to set every field directly. -import collections games = collections.OrderedDict([ ("dcss-0.29", dict( version = "0.29", @@ -254,162 +92,16 @@ dgl_status_file = "./crawl/server/status" -# Extra paths to tail for milestone updates. This is a legacy setting, you -# should use `milestone_path` or `dir_path` for each game in the games dict. -# (This setting can be a string or list of strings.) -# milestone_file = ["./milestones"] - -# status_file_update_rate = 30 -# lobby_update_rate = 2 - -# recording_term_size = (80, 24) - -# max_connections = 100 - -# Script to initialize a user, e.g. make sure the paths -# and the rc file exist. This is not done by the server -# at the moment. This value init_player_program = "./crawl/server/init-player.sh" -# how often to check for an active connection while playing; this has an effect -# on how often a connection is checked for basic life, as well as the following -# two idle timer settings. -# connection_timeout = 10 * 60 - -# the maximum allowed idle time while playing. This timer is checked in -# intervals determined by `connection_timout`, so values will essentially be -# rounded up to that setting -# max_idle_time = 5 * 60 * 60 - -# the maximum allowed idle time in the lobby. Negative values will disable the -# lobby idle timer. This timer is rounded up to the value of the -# `connection_timeout` setting, similar to `max_idle_time`. -# max_lobby_idle_time = 3 * 60 * 60 - -# use_gzip = True - -# Seconds until stale HTTP connections are closed -# This corresponds to the tornado parameter `idle_connection_timeout`, which -# will automatically close idle http connections that do not respond after a -# period of time. Setting this to `None` gives the tornado default (1 hour). -# This setting usually does not affect websockets connections, which use the -# above webtiles-internal timeouts. -# http_connection_timeout = None - -# Set this to true if you are behind a reverse proxy -# Your proxy must set header X-Real-IP -# -# Enabling this option when webtiles is NOT protected behind a reverse proxy -# introduces a security risk. An attacker could inject a false address into the -# X-Real-IP header. Do not enable this option if the webtiles server is -# directly exposed to users. -# http_xheaders = None - -# kill_timeout = 10 # Seconds until crawl is killed after HUP is sent - -# max_passwd_length = 20 - -# Username management options. -# -# This options are used on a running webserver only for new account creation! -# It is possible to run a ban query against an existing userdb with them as -# well, see wtutil.py options --check-config-bans and --run-config-bans. For -# banning offensive names, skip to `banned` below. Crawl nicknames are case -# preserving but not case sensitive. To be an acceptable username, a string -# must pass all three of these checks (if defined). -# -# 1. Use `nick_regex` to modify the basic format for valid nicknames. -# a nick is allowed if it matches this regex. It is not recommended to modify -# this unless you really know what you're doing, and this default should not -# ever be modified to something less restrictive for official servers. -# nick_regex = r"^[a-zA-Z0-9]{3,20}$" -# -# 2. `nick_check_fun` if defined, is a function that returns true on valid -# nicknames. You can use this for arbitrary custom nick checks in a server -# config. You will need to do case management manually in this function. -# def nick_check_fun(s): -# return s.lower() != "plog" and s.lower() != "muggle" -# -# 3. For easily excluding a larger list of usernames from account creation, you -# can use the `banned` option. This can take a simple list of names, or some -# more complex things. Instead of or in addition to putting banned names in -# config, you can put them in files named `banned_players.txt` and -# `banned_players.yml`. The latter must have a single dict entry `banned` -# that is allowed to use the complex options below. -# -# Simple example: -# banned = ['plog', 'muggle', 'muggles', 'ihatemuggles'] -# -# Complex example. This will ban many things, for example, -# plain 'muggle', leetspeak variants like 'mugg13s', versions of the phrase -# embedded into other contexts with different letter repeats such as -# 'xx1hatemugggglesxx', etc. It is recommended to be fairly cautious when using -# these extended options, because of -# https://en.wikipedia.org/wiki/Scunthorpe_problem; there are very few English -# slurs where it is a good idea to turn on all three of these options. -# You can mix plain strings with complex entries, as shown here: -# -# banned = ['plog', -# {'options': {'leet': True, 'repeats': True, 'part': True}, -# 'names': ['muggle']}] -# it is allowed to mix in plain strings with dicts in this list, - -# Example to demonstrate this same list in yml form: -# banned: -# - plog -# - options: -# leet: True -# repeats: True -# part: True -# names: -# - muggle -# -# It is recommended to use an external file rather than defining this option -# directly in config. (Among other reasons, this means that server admins are -# only viewing/editing a file likely filled with slurs when they are actually -# intending to...) - -# Set to True to allow users to request a password reset email. Some settings -# must be properly configured for this to work: -# allow_password_reset = False -# Set to True to allow dgl admin users to generate password reset tokens in the -# admin panel. Only use if you really trust your admin users! -# admin_password_reset = False - -# Set to the primary URL where a player would reach the main lobby -# For example: "http://crawl.akrasiac.org/" -# This is required for for password reset, as it will be the base URL for -# recovery URLs. Use "http://localhost:8080/" for testing. lobby_url = "http://localhost:8080/" -# Proper SMTP settings are required for password reset to function properly. -# if smtp_host is anything other than `localhost`, you may need to adjust the -# timeout settings (see server.py, calls to ioloop.set_blocking_log_threshold). -# TODO: set_blocking_log_threshold is deprecated in tornado 5+... -# Ideally, test out these settings carefully in a non-production setting -# before enabling this, as there's a bunch of ways for this to go wrong and you -# don't want to get your SMTP server blocklisted. smtp_host = "localhost" smtp_port = 25 smtp_use_ssl = False smtp_user = "" # set to None for no auth smtp_password = "" -smtp_from_addr = "noreply@crawl.example.org" # The address from which automated - # emails will be sent - -# crypt() algorithm, e.g. "1" for MD5 or "6" for SHA-512; see crypt(3). If -# false, use traditional DES (but then only the first eight characters of the -# password are significant). If set to "broken", use traditional DES with -# the password itself as the salt; this is necessary for compatibility with -# dgamelaunch, but should be avoided if possible because it leaks the first -# two characters of the password's plaintext. -# crypt_algorithm = "broken" - -# The length of the salt string to use. If crypt_algorithm is false, this -# setting is ignored and the salt is two characters. -# crypt_salt_length = 16 - -# login_token_lifetime = 7 # Days +smtp_from_addr = "noreply@crawl.example.org" uid = None # If this is not None, the server will setuid to that (numeric) id gid = None # after binding its sockets. @@ -419,40 +111,9 @@ chroot = None pidfile = None -# daemon = False # If true, the server will detach from the session after startup -# Set to a URL with %s where lowercased player name should go in order to -# hyperlink WebTiles spectator names to their player pages. -# For example: "http://crawl.akrasiac.org/scoring/players/%s.html" -# Set to None to disable player page hyperlinks player_url = None -# set one of these for various moderation modes. Disabled preempts hold. In -# account hold mode, new accounts cannot use chat, cannot spectate, and do -# not appear in the lobby until explicitly approved by an admin. They can still -# play. (Of course, they can still log out and spectate as anon.) -# new_accounts_disabled = True -# new_accounts_hold = True - -# customize chat limits. Set to 0 or False to disable chat. Value in characters. -# max_chat_length = 1000 - -# If set to True, a SIGHUP triggers an attempt to reload the config and game -# data. Some values cannot be reloaded (including this one), and to reset a -# value to its default, you need to explicitly set the value rather than -# comment it out. -# If not explicitly set, this defaults to False. hup_reloads_config = True -# set to do periodic logging of user load -# load_logging_rate = 10 # seconds, set to 0 to explicitly disable -# slow_callback_alert = 0.25 # seconds, set to None to explicitly disable - -# Only for development: -# This is insecure; do not set development_mode = True in production! -# development_mode = False - -# Disable caching of static files which are not part of game data. -# no_cache = development_mode -# Automatically log in all users with the username given here. autologin = None diff --git a/dcss-api-python/tests/rc_file_test.py b/dcss-api-python/tests/rc_file_test.py index 1e65cf6..d18ab25 100644 --- a/dcss-api-python/tests/rc_file_test.py +++ b/dcss-api-python/tests/rc_file_test.py @@ -2,9 +2,11 @@ import dcss_api from dcss_api import APIErr import json - +import os def test_write_read_rc(): + game_id = os.environ['GAME_ID'] + # Connect to DCSS Webtile webtile = dcss_api.WebtilePy("ws://localhost:8080/socket", 0, "0.32") @@ -16,18 +18,18 @@ def test_write_read_rc(): while (message := webtile.get_message()) != None: pass - webtile.set_rc_file("dcss-0.32", "this is a test") + webtile.set_rc_file(game_id, "this is a test") - rc_file = webtile.get_rc_file("dcss-0.32") + rc_file = webtile.get_rc_file(game_id) assert rc_file == "this is a test" while (message := webtile.get_message()) != None: pass - webtile.set_rc_file("dcss-0.32", "show_more = false\nrest_delay = -1") + webtile.set_rc_file(game_id, "show_more = false\nrest_delay = -1") - rc_file = webtile.get_rc_file("dcss-0.32") + rc_file = webtile.get_rc_file(game_id) assert rc_file == "show_more = false\nrest_delay = -1" @@ -35,6 +37,8 @@ def test_write_read_rc(): def test_blank_rc_file(): + game_id = os.environ['GAME_ID'] + # Connect to DCSS Webtile webtile = dcss_api.WebtilePy("ws://localhost:8080/socket", 0, "0.32") @@ -46,18 +50,18 @@ def test_blank_rc_file(): while (message := webtile.get_message()) != None: pass - webtile.set_rc_file("dcss-0.32", "") + webtile.set_rc_file(game_id, "") - rc_file = webtile.get_rc_file("dcss-0.32") + rc_file = webtile.get_rc_file(game_id) assert rc_file == "" while (message := webtile.get_message()) != None: pass - webtile.set_rc_file("dcss-0.32", "show_more = false\nrest_delay = -1") + webtile.set_rc_file(game_id, "show_more = false\nrest_delay = -1") - rc_file = webtile.get_rc_file("dcss-0.32") + rc_file = webtile.get_rc_file(game_id) assert rc_file == "show_more = false\nrest_delay = -1" diff --git a/dcss-api-python/tests/scenario_test.py b/dcss-api-python/tests/scenario_test.py index c77c4f8..31c7960 100644 --- a/dcss-api-python/tests/scenario_test.py +++ b/dcss-api-python/tests/scenario_test.py @@ -1,9 +1,11 @@ import pytest import dcss_api import json +import os from dcss_api import ScenarioErr -def reset_test(username): +def reset_test(username, game_id): + # Connect to DCSS Webtile webtile = dcss_api.WebtilePy("ws://localhost:8080/socket", 0, "0.32") @@ -15,7 +17,7 @@ def reset_test(username): while (message := webtile.get_message()) != None: pass - webtile.start_game("dcss-0.32", "b", "f", "b") + webtile.start_game(game_id, "b", "f", "b") while (message := webtile.get_message()) != None: pass @@ -28,7 +30,9 @@ def reset_test(username): webtile.disconnect() def test_wizmode(): - reset_test("Username") + game_id = os.environ['GAME_ID'] + + reset_test("Username", game_id) webtile = dcss_api.WebtilePy("ws://localhost:8080/socket", 0, "0.32") @@ -41,11 +45,11 @@ def test_wizmode(): pass yaml_file = "./dcss-scenario-builder/tests/test_scenarios/simple_map.yaml" - webtile.start_game_with_scenario("dcss-0.32", "b", "f", "b", yaml_file) + webtile.start_game_with_scenario(game_id, "b", "f", "b", yaml_file) webtile.save_game() - webtile.continue_game("dcss-0.32") + webtile.continue_game(game_id) while (message := webtile.get_message()) != None: json_message = json.loads(message) @@ -61,7 +65,9 @@ def test_wizmode(): def test_no_character(): - reset_test("Username") + game_id = os.environ['GAME_ID'] + + reset_test("Username", game_id) webtile = dcss_api.WebtilePy("ws://localhost:8080/socket", 0, "0.32") @@ -76,7 +82,7 @@ def test_no_character(): yaml_file = "./dcss-scenario-builder/tests/test_scenarios/no_char.yaml" try: - webtile.start_game_with_scenario("dcss-0.32", "b", "f", "b", yaml_file) + webtile.start_game_with_scenario(game_id, "b", "f", "b", yaml_file) except ScenarioErr as e: if "Missing `@` on `D:1`" in e.args[0]: assert True @@ -85,7 +91,9 @@ def test_no_character(): def test_too_wide(): - reset_test("Username") + game_id = os.environ['GAME_ID'] + + reset_test("Username", game_id) webtile = dcss_api.WebtilePy("ws://localhost:8080/socket", 0, "0.32") @@ -100,7 +108,7 @@ def test_too_wide(): yaml_file = "./dcss-scenario-builder/tests/test_scenarios/too_wide.yaml" try: - webtile.start_game_with_scenario("dcss-0.32", "b", "f", "b", yaml_file) + webtile.start_game_with_scenario(game_id, "b", "f", "b", yaml_file) except ScenarioErr as e: if "Maximum width of map is 79 columns" in e.args[0]: assert True @@ -109,7 +117,9 @@ def test_too_wide(): def test_too_long(): - reset_test("Username") + game_id = os.environ['GAME_ID'] + + reset_test("Username", game_id) webtile = dcss_api.WebtilePy("ws://localhost:8080/socket", 0, "0.32") @@ -124,7 +134,7 @@ def test_too_long(): yaml_file = "./dcss-scenario-builder/tests/test_scenarios/too_long.yaml" try: - webtile.start_game_with_scenario("dcss-0.32", "b", "f", "b", yaml_file) + webtile.start_game_with_scenario(game_id, "b", "f", "b", yaml_file) except ScenarioErr as e: if "Maximum height of map is 69 rows" in e.args[0]: assert True diff --git a/dcss-api-python/tests/start_game_test.py b/dcss-api-python/tests/start_game_test.py index e67d362..4925532 100644 --- a/dcss-api-python/tests/start_game_test.py +++ b/dcss-api-python/tests/start_game_test.py @@ -1,10 +1,11 @@ import pytest import dcss_api -from dcss_api import BlockingErr import json +import os +from dcss_api import BlockingErr -def reset_test(username): +def reset_test(username, game_id): # Connect to DCSS Webtile webtile = dcss_api.WebtilePy("ws://localhost:8080/socket", 0, "0.32") @@ -16,7 +17,7 @@ def reset_test(username): while (message := webtile.get_message()) != None: pass - webtile.start_game("dcss-0.32", "b", "f", "b") + webtile.start_game(game_id, "b", "f", "b") while (message := webtile.get_message()) != None: pass @@ -30,7 +31,9 @@ def reset_test(username): def test_start_game_seeded(): - reset_test("Username") + game_id = os.environ['GAME_ID'] + + reset_test("Username", game_id) # Connect to DCSS Webtile webtile = dcss_api.WebtilePy("ws://localhost:8080/socket", 0, "0.32") @@ -43,7 +46,7 @@ def test_start_game_seeded(): while (message := webtile.get_message()) != None: pass - webtile.start_game_seeded("dcss-0.32", "1", True, "b", "f", "b") + webtile.start_game_seeded(game_id, "1", True, "b", "f", "b") msgs = None while (message := webtile.get_message()) != None: @@ -77,7 +80,7 @@ def test_start_game_seeded(): while (message := webtile.get_message()) != None: pass - webtile.start_game_seeded("dcss-0.32", "158985", True, "b", "f", "b") + webtile.start_game_seeded(game_id, "158985", True, "b", "f", "b") msgs = None while (message := webtile.get_message()) != None: @@ -103,7 +106,9 @@ def test_start_game_seeded(): def test_start_game(): - reset_test("Username") + game_id = os.environ['GAME_ID'] + + reset_test("Username", game_id) # Connect to DCSS Webtile webtile = dcss_api.WebtilePy("ws://localhost:8080/socket", 0, "0.32") @@ -116,7 +121,7 @@ def test_start_game(): while (message := webtile.get_message()) != None: pass - webtile.start_game("dcss-0.32", "b", "f", "b") + webtile.start_game(game_id, "b", "f", "b") msgs = None while (message := webtile.get_message()) != None: @@ -137,7 +142,9 @@ def test_start_game(): def test_start_game(): - reset_test("Username") + game_id = os.environ['GAME_ID'] + + reset_test("Username", game_id) # Connect to DCSS Webtile webtile = dcss_api.WebtilePy("ws://localhost:8080/socket", 0, "0.32") @@ -150,7 +157,7 @@ def test_start_game(): while (message := webtile.get_message()) != None: pass - webtile.start_game("dcss-0.32", "b", "f", "b") + webtile.start_game(game_id, "b", "f", "b") json_message = None while (message := webtile.get_message()) != None: @@ -166,7 +173,7 @@ def test_start_game(): assert json_message["msg"] == "go_lobby" - webtile.continue_game("dcss-0.32") + webtile.continue_game(game_id) json_message = None while (message := webtile.get_message()) != None: @@ -180,7 +187,9 @@ def test_start_game(): def test_start_game_two_accounts(): - reset_test("Username") + game_id = os.environ['GAME_ID'] + + reset_test("Username", game_id) webtile = dcss_api.WebtilePy("ws://localhost:8080/socket", 0, "0.32") @@ -192,7 +201,7 @@ def test_start_game_two_accounts(): while (message := webtile.get_message()) != None: pass - webtile.start_game("dcss-0.32", "b", "f", "b") + webtile.start_game(game_id, "b", "f", "b") msgs = None while (message := webtile.get_message()) != None: @@ -219,7 +228,7 @@ def test_start_game_two_accounts(): webtile.disconnect() - reset_test("Username2") + reset_test("Username2", game_id) webtile = dcss_api.WebtilePy("ws://localhost:8080/socket", 0, "0.32") @@ -231,7 +240,7 @@ def test_start_game_two_accounts(): while (message := webtile.get_message()) != None: pass - webtile.start_game("dcss-0.32", "b", "f", "b") + webtile.start_game(game_id, "b", "f", "b") msgs = None while (message := webtile.get_message()) != None: @@ -260,8 +269,10 @@ def test_start_game_two_accounts(): def test_start_game_two_accounts_combined(): - reset_test("Username") - reset_test("Username2") + game_id = os.environ['GAME_ID'] + + reset_test("Username", game_id) + reset_test("Username2", game_id) webtile1 = dcss_api.WebtilePy("ws://localhost:8080/socket", 0, "0.32") webtile2 = dcss_api.WebtilePy("ws://localhost:8080/socket", 0, "0.32") @@ -279,8 +290,8 @@ def test_start_game_two_accounts_combined(): while (message := webtile2.get_message()) != None: pass - webtile1.start_game("dcss-0.32", "b", "f", "b") - webtile2.start_game("dcss-0.32", "b", "f", "b") + webtile1.start_game(game_id, "b", "f", "b") + webtile2.start_game(game_id, "b", "f", "b") msgs = None while (message := webtile1.get_message()) != None: @@ -332,7 +343,9 @@ def test_start_game_two_accounts_combined(): def test_real_blocking_error(): - reset_test("Username") + game_id = os.environ['GAME_ID'] + + reset_test("Username", game_id) webtile = dcss_api.WebtilePy("ws://localhost:8080/socket", 0, "0.32") @@ -344,7 +357,7 @@ def test_real_blocking_error(): while (message := webtile.get_message()) != None: pass - webtile.start_game("dcss-0.32", "b", "f", "b") + webtile.start_game(game_id, "b", "f", "b") msgs = None while (message := webtile.get_message()) != None: diff --git a/dcss-api-python/tests/versions_test.py b/dcss-api-python/tests/versions_test.py deleted file mode 100644 index 8cbd8ca..0000000 --- a/dcss-api-python/tests/versions_test.py +++ /dev/null @@ -1,321 +0,0 @@ -import pytest -import dcss_api -from dcss_api import BlockingErr -import json - - -def reset_test(username, version): - # Connect to DCSS Webtile - webtile = dcss_api.WebtilePy("ws://localhost:8080/socket", 0, "0.32") - - while (message := webtile.get_message()) != None: - pass - - webtile.login_with_credentials(username, "Password") - - while (message := webtile.get_message()) != None: - pass - - webtile.start_game(version, "b", "f", "b") - - while (message := webtile.get_message()) != None: - pass - - webtile.quit_game() - - while (message := webtile.get_message()) != None: - pass - - webtile.disconnect() - - -def test_start_game_seeded_0_29(): - reset_test("Username", "dcss-0.29") - - # Connect to DCSS Webtile - webtile = dcss_api.WebtilePy("ws://localhost:8080/socket", 0, "0.29") - - while (message := webtile.get_message()) != None: - pass - - webtile.login_with_credentials("Username", "Password") - - while (message := webtile.get_message()) != None: - pass - - webtile.start_game_seeded("dcss-0.29", "1", True, "b", "f", "b") - - msgs = None - while (message := webtile.get_message()) != None: - json_message = json.loads(message) - if json_message["msg"] == "msgs": - msgs = json_message - break - - found = False - for msg in msgs["messages"]: - if "Game seed: 1 (custom seed)" in msg["text"]: - found = True - break - - assert found - - webtile.quit_game() - - while (message := webtile.get_message()) != None: - pass - - webtile.disconnect() - - webtile = dcss_api.WebtilePy("ws://localhost:8080/socket", 0, "0.29") - - while (message := webtile.get_message()) != None: - pass - - webtile.login_with_credentials("Username", "Password") - - while (message := webtile.get_message()) != None: - pass - - webtile.start_game_seeded("dcss-0.29", "158985", True, "b", "f", "b") - - msgs = None - while (message := webtile.get_message()) != None: - json_message = json.loads(message) - if json_message["msg"] == "msgs": - msgs = json_message - break - - found = False - for msg in msgs["messages"]: - if "Game seed: 158985 (custom seed)" in msg["text"]: - found = True - break - - assert found - - webtile.quit_game() - - while (message := webtile.get_message()) != None: - pass - - webtile.disconnect() - - -def test_start_game_seeded_0_30(): - reset_test("Username", "dcss-0.30") - - # Connect to DCSS Webtile - webtile = dcss_api.WebtilePy("ws://localhost:8080/socket", 0, "0.30") - - while (message := webtile.get_message()) != None: - pass - - webtile.login_with_credentials("Username", "Password") - - while (message := webtile.get_message()) != None: - pass - - webtile.start_game_seeded("dcss-0.30", "1", True, "b", "f", "b") - - msgs = None - while (message := webtile.get_message()) != None: - json_message = json.loads(message) - if json_message["msg"] == "msgs": - msgs = json_message - break - - found = False - for msg in msgs["messages"]: - if "Game seed: 1 (custom seed)" in msg["text"]: - found = True - break - - assert found - - webtile.quit_game() - - while (message := webtile.get_message()) != None: - pass - - webtile.disconnect() - - webtile = dcss_api.WebtilePy("ws://localhost:8080/socket", 0, "0.30") - - while (message := webtile.get_message()) != None: - pass - - webtile.login_with_credentials("Username", "Password") - - while (message := webtile.get_message()) != None: - pass - - webtile.start_game_seeded("dcss-0.30", "158985", True, "b", "f", "b") - - msgs = None - while (message := webtile.get_message()) != None: - json_message = json.loads(message) - if json_message["msg"] == "msgs": - msgs = json_message - break - - found = False - for msg in msgs["messages"]: - if "Game seed: 158985 (custom seed)" in msg["text"]: - found = True - break - - assert found - - webtile.quit_game() - - while (message := webtile.get_message()) != None: - pass - - webtile.disconnect() - - -def test_start_game_seeded_0_31(): - reset_test("Username", "dcss-0.31") - - # Connect to DCSS Webtile - webtile = dcss_api.WebtilePy("ws://localhost:8080/socket", 0, "0.31") - - while (message := webtile.get_message()) != None: - pass - - webtile.login_with_credentials("Username", "Password") - - while (message := webtile.get_message()) != None: - pass - - webtile.start_game_seeded("dcss-0.31", "1", True, "b", "f", "b") - - msgs = None - while (message := webtile.get_message()) != None: - json_message = json.loads(message) - if json_message["msg"] == "msgs": - msgs = json_message - break - - found = False - for msg in msgs["messages"]: - if "Game seed: 1 (custom seed)" in msg["text"]: - found = True - break - - assert found - - webtile.quit_game() - - while (message := webtile.get_message()) != None: - pass - - webtile.disconnect() - - webtile = dcss_api.WebtilePy("ws://localhost:8080/socket", 0, "0.31") - - while (message := webtile.get_message()) != None: - pass - - webtile.login_with_credentials("Username", "Password") - - while (message := webtile.get_message()) != None: - pass - - webtile.start_game_seeded("dcss-0.31", "158985", True, "b", "f", "b") - - msgs = None - while (message := webtile.get_message()) != None: - json_message = json.loads(message) - if json_message["msg"] == "msgs": - msgs = json_message - break - - found = False - for msg in msgs["messages"]: - if "Game seed: 158985 (custom seed)" in msg["text"]: - found = True - break - - assert found - - webtile.quit_game() - - while (message := webtile.get_message()) != None: - pass - - webtile.disconnect() - - -def test_start_game_seeded_0_32(): - reset_test("Username", "dcss-0.32") - - # Connect to DCSS Webtile - webtile = dcss_api.WebtilePy("ws://localhost:8080/socket", 0, "0.32") - - while (message := webtile.get_message()) != None: - pass - - webtile.login_with_credentials("Username", "Password") - - while (message := webtile.get_message()) != None: - pass - - webtile.start_game_seeded("dcss-0.32", "1", True, "b", "f", "b") - - msgs = None - while (message := webtile.get_message()) != None: - json_message = json.loads(message) - if json_message["msg"] == "msgs": - msgs = json_message - break - - found = False - for msg in msgs["messages"]: - if "Game seed: 1 (custom seed)" in msg["text"]: - found = True - break - - assert found - - webtile.quit_game() - - while (message := webtile.get_message()) != None: - pass - - webtile.disconnect() - - webtile = dcss_api.WebtilePy("ws://localhost:8080/socket", 0, "0.32") - - while (message := webtile.get_message()) != None: - pass - - webtile.login_with_credentials("Username", "Password") - - while (message := webtile.get_message()) != None: - pass - - webtile.start_game_seeded("dcss-0.32", "158985", True, "b", "f", "b") - - msgs = None - while (message := webtile.get_message()) != None: - json_message = json.loads(message) - if json_message["msg"] == "msgs": - msgs = json_message - break - - found = False - for msg in msgs["messages"]: - if "Game seed: 158985 (custom seed)" in msg["text"]: - found = True - break - - assert found - - webtile.quit_game() - - while (message := webtile.get_message()) != None: - pass - - webtile.disconnect() \ No newline at end of file diff --git a/dcss-api/tests/common.rs b/dcss-api/tests/common.rs new file mode 100644 index 0000000..e346f72 --- /dev/null +++ b/dcss-api/tests/common.rs @@ -0,0 +1,34 @@ +#![allow(dead_code)] + +use dcss_api::Webtile; + +pub(crate) fn reset_test(username: &str, game_id: &str) { + // Connect to DCSS Webtile + let mut webtile = + Webtile::connect("ws://localhost:8080/socket", 0, "0.32").expect("Failed to connect"); + + // Empty message queue; + while webtile.get_message().is_some() {} + + // Log in (to a user called "Username", with a password "Password") + let _game_ids = webtile + .login_with_credentials(username, "Password") + .expect("Failed to login"); + + // Empty message queue; + while webtile.get_message().is_some() {} + + webtile + .start_game(game_id, "b", "f", "b") + .expect("Failed to start game"); + + // Empty message queue; + while webtile.get_message().is_some() {} + + webtile.quit_game().expect("Failed to quit game"); + + // Empty message queue; + while webtile.get_message().is_some() {} + + webtile.disconnect().expect("Failed to disconnect"); +} diff --git a/dcss-api/tests/rc_file_test.rs b/dcss-api/tests/rc_file_test.rs index f81b98d..d0d1283 100644 --- a/dcss-api/tests/rc_file_test.rs +++ b/dcss-api/tests/rc_file_test.rs @@ -2,6 +2,8 @@ use dcss_api::Webtile; #[test] fn write_read_rc() { + let game_id = std::env::var("GAME_ID").unwrap(); + let mut webtile = Webtile::connect("ws://localhost:8080/socket", 0, "0.32").expect("Failed to connect."); @@ -16,10 +18,12 @@ fn write_read_rc() { while webtile.get_message().is_some() {} webtile - .set_rc_file("dcss-0.32", "this is a test") + .set_rc_file(game_id.as_str(), "this is a test") .expect("Failed to write"); - let rc_file = webtile.get_rc_file("dcss-0.32").expect("Failed to read."); + let rc_file = webtile + .get_rc_file(game_id.as_str()) + .expect("Failed to read."); assert_eq!("this is a test", rc_file); @@ -27,10 +31,12 @@ fn write_read_rc() { while webtile.get_message().is_some() {} webtile - .set_rc_file("dcss-0.32", "show_more = false\nrest_delay = -1") + .set_rc_file(game_id.as_str(), "show_more = false\nrest_delay = -1") .expect("Failed to write"); - let rc_file = webtile.get_rc_file("dcss-0.32").expect("Failed to read."); + let rc_file = webtile + .get_rc_file(game_id.as_str()) + .expect("Failed to read."); assert_eq!("show_more = false\nrest_delay = -1", rc_file); @@ -39,6 +45,8 @@ fn write_read_rc() { #[test] fn blank_rc_file() { + let game_id = std::env::var("GAME_ID").unwrap(); + let mut webtile = Webtile::connect("ws://localhost:8080/socket", 0, "0.32").expect("Failed to connect."); @@ -53,10 +61,12 @@ fn blank_rc_file() { while webtile.get_message().is_some() {} webtile - .set_rc_file("dcss-0.32", "") + .set_rc_file(game_id.as_str(), "") .expect("Failed to write"); - let rc_file = webtile.get_rc_file("dcss-0.32").expect("Failed to read."); + let rc_file = webtile + .get_rc_file(game_id.as_str()) + .expect("Failed to read."); assert_eq!("", rc_file); @@ -64,10 +74,12 @@ fn blank_rc_file() { while webtile.get_message().is_some() {} webtile - .set_rc_file("dcss-0.32", "show_more = false\nrest_delay = -1") + .set_rc_file(game_id.as_str(), "show_more = false\nrest_delay = -1") .expect("Failed to write"); - let rc_file = webtile.get_rc_file("dcss-0.32").expect("Failed to read."); + let rc_file = webtile + .get_rc_file(game_id.as_str()) + .expect("Failed to read."); assert_eq!("show_more = false\nrest_delay = -1", rc_file); diff --git a/dcss-api/tests/start_game_test.rs b/dcss-api/tests/start_game_test.rs index 6255530..8229a5f 100644 --- a/dcss-api/tests/start_game_test.rs +++ b/dcss-api/tests/start_game_test.rs @@ -1,41 +1,14 @@ +mod common; + use dcss_api::{BlockingError, Error, Webtile}; use serde_json::from_str; -fn reset_test(username: &str) { - // Connect to DCSS Webtile - let mut webtile = - Webtile::connect("ws://localhost:8080/socket", 0, "0.32").expect("Failed to connect"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - // Log in (to a user called "Username", with a password "Password") - let _game_ids = webtile - .login_with_credentials(username, "Password") - .expect("Failed to login"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - webtile - .start_game("dcss-0.32", "b", "f", "b") - .expect("Failed to start game"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - webtile.quit_game().expect("Failed to quit game"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - webtile.disconnect().expect("Failed to disconnect"); -} - #[test] fn start_game_seeded() { + let game_id = std::env::var("GAME_ID").unwrap(); + // Safe test -- login start game, quit, and then test - reset_test("Username"); + common::reset_test("Username", game_id.as_str()); // Connect to DCSS Webtile let mut webtile = @@ -53,7 +26,7 @@ fn start_game_seeded() { while webtile.get_message().is_some() {} webtile - .start_game_seeded("dcss-0.32", "1", true, "b", "f", "b") + .start_game_seeded(game_id.as_str(), "1", true, "b", "f", "b") .expect("Failed to start game"); // Get last message @@ -89,7 +62,7 @@ fn start_game_seeded() { while webtile.get_message().is_some() {} webtile - .start_game_seeded("dcss-0.32", "158985", false, "b", "f", "b") + .start_game_seeded(game_id.as_str(), "158985", false, "b", "f", "b") .expect("Failed to start game"); // Get last message @@ -112,8 +85,10 @@ fn start_game_seeded() { #[test] fn start_game() { + let game_id = std::env::var("GAME_ID").unwrap(); + // Safe test -- login start game, quit, and then test - reset_test("Username"); + common::reset_test("Username", game_id.as_str()); // Connect to DCSS Webtile let mut webtile = @@ -131,7 +106,7 @@ fn start_game() { while webtile.get_message().is_some() {} webtile - .start_game("dcss-0.32", "b", "f", "b") + .start_game(game_id.as_str(), "b", "f", "b") .expect("Failed to start game"); let mut msgs = from_str("{}").unwrap(); @@ -159,8 +134,10 @@ fn start_game() { #[test] fn save_game_continue() { + let game_id = std::env::var("GAME_ID").unwrap(); + // Safe test -- login start game, quit, and then test - reset_test("Username"); + common::reset_test("Username", game_id.as_str()); // Connect to DCSS Webtile let mut webtile = @@ -178,7 +155,7 @@ fn save_game_continue() { while webtile.get_message().is_some() {} webtile - .start_game("dcss-0.32", "b", "f", "b") + .start_game(game_id.as_str(), "b", "f", "b") .expect("Failed to start game"); // Get last message @@ -200,7 +177,7 @@ fn save_game_continue() { assert!(last_message["msg"] == "go_lobby"); webtile - .continue_game("dcss-0.32") + .continue_game(game_id.as_str()) .expect("Failed to continue game"); // Get last message @@ -218,8 +195,10 @@ fn save_game_continue() { #[test] fn start_game_two_accounts() { + let game_id = std::env::var("GAME_ID").unwrap(); + // Safe test -- login start game, quit, and then test - reset_test("Username"); + common::reset_test("Username", game_id.as_str()); // Connect to DCSS Webtile let mut webtile = @@ -237,7 +216,7 @@ fn start_game_two_accounts() { while webtile.get_message().is_some() {} webtile - .start_game("dcss-0.32", "b", "f", "b") + .start_game(game_id.as_str(), "b", "f", "b") .expect("Failed to start game"); let mut msgs = from_str("{}").unwrap(); @@ -263,7 +242,7 @@ fn start_game_two_accounts() { webtile.disconnect().expect("Failed to disconnect"); // Safe test -- login start game, quit, and then test - reset_test("Username2"); + common::reset_test("Username2", game_id.as_str()); // Connect to DCSS Webtile let mut webtile = @@ -281,7 +260,7 @@ fn start_game_two_accounts() { while webtile.get_message().is_some() {} webtile - .start_game("dcss-0.32", "b", "f", "b") + .start_game(game_id.as_str(), "b", "f", "b") .expect("Failed to start game"); let mut msgs = from_str("{}").unwrap(); @@ -309,9 +288,11 @@ fn start_game_two_accounts() { #[test] fn start_game_two_accounts_combined() { + let game_id = std::env::var("GAME_ID").unwrap(); + // Safe test -- login start game, quit, and then test - reset_test("Username"); - reset_test("Username2"); + common::reset_test("Username", game_id.as_str()); + common::reset_test("Username2", game_id.as_str()); // Connect to DCSS Webtile let mut webtile1 = @@ -336,10 +317,10 @@ fn start_game_two_accounts_combined() { while webtile2.get_message().is_some() {} webtile1 - .start_game("dcss-0.32", "b", "f", "b") + .start_game(game_id.as_str(), "b", "f", "b") .expect("Failed to start game"); webtile2 - .start_game("dcss-0.32", "b", "f", "b") + .start_game(game_id.as_str(), "b", "f", "b") .expect("Failed to start game"); let mut msgs = from_str("{}").unwrap(); @@ -387,8 +368,10 @@ fn start_game_two_accounts_combined() { #[test] fn real_blocking_error() { + let game_id = std::env::var("GAME_ID").unwrap(); + // Safe test -- login start game, quit, and then test - reset_test("Username"); + common::reset_test("Username", game_id.as_str()); // Connect to DCSS Webtile let mut webtile = @@ -406,7 +389,7 @@ fn real_blocking_error() { while webtile.get_message().is_some() {} webtile - .start_game_seeded("dcss-0.32", "1", true, "b", "f", "b") + .start_game_seeded(game_id.as_str(), "1", true, "b", "f", "b") .expect("Failed to start game"); // Get last message diff --git a/dcss-api/tests/versions_test.rs b/dcss-api/tests/versions_test.rs deleted file mode 100644 index d05a5de..0000000 --- a/dcss-api/tests/versions_test.rs +++ /dev/null @@ -1,345 +0,0 @@ -use dcss_api::Webtile; -use serde_json::from_str; - -fn reset_test(username: &str, version: &str) { - // Connect to DCSS Webtile - let mut webtile = - Webtile::connect("ws://localhost:8080/socket", 0, "0.32").expect("Failed to connect"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - // Log in (to a user called "Username", with a password "Password") - let _game_ids = webtile - .login_with_credentials(username, "Password") - .expect("Failed to login"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - webtile - .start_game(version, "b", "f", "b") - .expect("Failed to start game"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - webtile.quit_game().expect("Failed to quit game"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - webtile.disconnect().expect("Failed to disconnect"); -} - -#[test] -fn start_game_seeded_0_29() { - // Safe test -- login start game, quit, and then test - reset_test("Username", "dcss-0.29"); - - // Connect to DCSS Webtile - let mut webtile = - Webtile::connect("ws://localhost:8080/socket", 0, "0.29").expect("Failed to connect"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - // Log in (to a user called "Username", with a password "Password") - let _game_ids = webtile - .login_with_credentials("Username", "Password") - .expect("Failed to login"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - webtile - .start_game_seeded("dcss-0.29", "1", true, "b", "f", "b") - .expect("Failed to start game"); - - // Get last message - let mut msgs = from_str("{}").unwrap(); - while let Some(message) = webtile.get_message() { - if message["msg"] == "msgs" { - msgs = message; - break; - } - } - - assert!(msgs["messages"] - .to_string() - .contains("Game seed: 1 (custom seed)")); - - webtile.quit_game().expect("Failed to quit game"); - - webtile.disconnect().expect("Failed to disconnect"); - - // Connect to DCSS Webtile - let mut webtile = - Webtile::connect("ws://localhost:8080/socket", 0, "0.29").expect("Failed to connect"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - // Log in (to a user called "Username", with a password "Password") - let _game_ids = webtile - .login_with_credentials("Username", "Password") - .expect("Failed to login"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - webtile - .start_game_seeded("dcss-0.29", "158985", false, "b", "f", "b") - .expect("Failed to start game"); - - // Get last message - let mut msgs = from_str("{}").unwrap(); - while let Some(message) = webtile.get_message() { - if message["msg"] == "msgs" { - msgs = message; - break; - } - } - - assert!(msgs["messages"] - .to_string() - .contains("Game seed: 158985 (custom seed)")); - - webtile.quit_game().expect("Failed to quit game"); - - webtile.disconnect().expect("Failed to disconnect"); -} - -#[test] -fn start_game_seeded_0_30() { - // Safe test -- login start game, quit, and then test - reset_test("Username", "dcss-0.30"); - - // Connect to DCSS Webtile - let mut webtile = - Webtile::connect("ws://localhost:8080/socket", 0, "0.30").expect("Failed to connect"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - // Log in (to a user called "Username", with a password "Password") - let _game_ids = webtile - .login_with_credentials("Username", "Password") - .expect("Failed to login"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - webtile - .start_game_seeded("dcss-0.30", "1", true, "b", "f", "b") - .expect("Failed to start game"); - - // Get last message - let mut msgs = from_str("{}").unwrap(); - while let Some(message) = webtile.get_message() { - if message["msg"] == "msgs" { - msgs = message; - break; - } - } - - assert!(msgs["messages"] - .to_string() - .contains("Game seed: 1 (custom seed)")); - - webtile.quit_game().expect("Failed to quit game"); - - webtile.disconnect().expect("Failed to disconnect"); - - // Connect to DCSS Webtile - let mut webtile = - Webtile::connect("ws://localhost:8080/socket", 0, "0.30").expect("Failed to connect"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - // Log in (to a user called "Username", with a password "Password") - let _game_ids = webtile - .login_with_credentials("Username", "Password") - .expect("Failed to login"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - webtile - .start_game_seeded("dcss-0.30", "158985", false, "b", "f", "b") - .expect("Failed to start game"); - - // Get last message - let mut msgs = from_str("{}").unwrap(); - while let Some(message) = webtile.get_message() { - if message["msg"] == "msgs" { - msgs = message; - break; - } - } - - assert!(msgs["messages"] - .to_string() - .contains("Game seed: 158985 (custom seed)")); - - webtile.quit_game().expect("Failed to quit game"); - - webtile.disconnect().expect("Failed to disconnect"); -} - -#[test] -fn start_game_seeded_0_31() { - // Safe test -- login start game, quit, and then test - reset_test("Username", "dcss-0.31"); - - // Connect to DCSS Webtile - let mut webtile = - Webtile::connect("ws://localhost:8080/socket", 0, "0.31").expect("Failed to connect"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - // Log in (to a user called "Username", with a password "Password") - let _game_ids = webtile - .login_with_credentials("Username", "Password") - .expect("Failed to login"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - webtile - .start_game_seeded("dcss-0.31", "1", true, "b", "f", "b") - .expect("Failed to start game"); - - // Get last message - let mut msgs = from_str("{}").unwrap(); - while let Some(message) = webtile.get_message() { - if message["msg"] == "msgs" { - msgs = message; - break; - } - } - - assert!(msgs["messages"] - .to_string() - .contains("Game seed: 1 (custom seed)")); - - webtile.quit_game().expect("Failed to quit game"); - - webtile.disconnect().expect("Failed to disconnect"); - - // Connect to DCSS Webtile - let mut webtile = - Webtile::connect("ws://localhost:8080/socket", 0, "0.31").expect("Failed to connect"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - // Log in (to a user called "Username", with a password "Password") - let _game_ids = webtile - .login_with_credentials("Username", "Password") - .expect("Failed to login"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - webtile - .start_game_seeded("dcss-0.31", "158985", false, "b", "f", "b") - .expect("Failed to start game"); - - // Get last message - let mut msgs = from_str("{}").unwrap(); - while let Some(message) = webtile.get_message() { - if message["msg"] == "msgs" { - msgs = message; - break; - } - } - - assert!(msgs["messages"] - .to_string() - .contains("Game seed: 158985 (custom seed)")); - - webtile.quit_game().expect("Failed to quit game"); - - webtile.disconnect().expect("Failed to disconnect"); -} - -#[test] -fn start_game_seeded_0_32() { - // Safe test -- login start game, quit, and then test - reset_test("Username", "dcss-0.32"); - - // Connect to DCSS Webtile - let mut webtile = - Webtile::connect("ws://localhost:8080/socket", 0, "0.32").expect("Failed to connect"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - // Log in (to a user called "Username", with a password "Password") - let _game_ids = webtile - .login_with_credentials("Username", "Password") - .expect("Failed to login"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - webtile - .start_game_seeded("dcss-0.32", "1", true, "b", "f", "b") - .expect("Failed to start game"); - - // Get last message - let mut msgs = from_str("{}").unwrap(); - while let Some(message) = webtile.get_message() { - if message["msg"] == "msgs" { - msgs = message; - break; - } - } - - assert!(msgs["messages"] - .to_string() - .contains("Game seed: 1 (custom seed)")); - - webtile.quit_game().expect("Failed to quit game"); - - webtile.disconnect().expect("Failed to disconnect"); - - // Connect to DCSS Webtile - let mut webtile = - Webtile::connect("ws://localhost:8080/socket", 0, "0.32").expect("Failed to connect"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - // Log in (to a user called "Username", with a password "Password") - let _game_ids = webtile - .login_with_credentials("Username", "Password") - .expect("Failed to login"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - webtile - .start_game_seeded("dcss-0.32", "158985", false, "b", "f", "b") - .expect("Failed to start game"); - - // Get last message - let mut msgs = from_str("{}").unwrap(); - while let Some(message) = webtile.get_message() { - if message["msg"] == "msgs" { - msgs = message; - break; - } - } - - assert!(msgs["messages"] - .to_string() - .contains("Game seed: 158985 (custom seed)")); - - webtile.quit_game().expect("Failed to quit game"); - - webtile.disconnect().expect("Failed to disconnect"); -} diff --git a/dcss-data/tests/common.rs b/dcss-data/tests/common.rs index fbb956a..008876d 100644 --- a/dcss-data/tests/common.rs +++ b/dcss-data/tests/common.rs @@ -1,3 +1,5 @@ +#![allow(dead_code)] + use dcss_api::Webtile; fn reset_test(username: &str) { diff --git a/dcss-scenario-builder/tests/common.rs b/dcss-scenario-builder/tests/common.rs new file mode 100644 index 0000000..e346f72 --- /dev/null +++ b/dcss-scenario-builder/tests/common.rs @@ -0,0 +1,34 @@ +#![allow(dead_code)] + +use dcss_api::Webtile; + +pub(crate) fn reset_test(username: &str, game_id: &str) { + // Connect to DCSS Webtile + let mut webtile = + Webtile::connect("ws://localhost:8080/socket", 0, "0.32").expect("Failed to connect"); + + // Empty message queue; + while webtile.get_message().is_some() {} + + // Log in (to a user called "Username", with a password "Password") + let _game_ids = webtile + .login_with_credentials(username, "Password") + .expect("Failed to login"); + + // Empty message queue; + while webtile.get_message().is_some() {} + + webtile + .start_game(game_id, "b", "f", "b") + .expect("Failed to start game"); + + // Empty message queue; + while webtile.get_message().is_some() {} + + webtile.quit_game().expect("Failed to quit game"); + + // Empty message queue; + while webtile.get_message().is_some() {} + + webtile.disconnect().expect("Failed to disconnect"); +} diff --git a/dcss-scenario-builder/tests/test_incorrect.rs b/dcss-scenario-builder/tests/test_incorrect.rs index 8c26043..b7f020b 100644 --- a/dcss-scenario-builder/tests/test_incorrect.rs +++ b/dcss-scenario-builder/tests/test_incorrect.rs @@ -1,42 +1,15 @@ +mod common; + use dcss_api::Webtile; use dcss_scenario_builder::start_game_with_scenario; -fn reset_test(username: &str) { - // Connect to DCSS Webtile - let mut webtile = - Webtile::connect("ws://localhost:8080/socket", 0, "0.32").expect("Failed to connect"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - // Log in (to a user called "Username", with a password "Password") - let _game_ids = webtile - .login_with_credentials(username, "Password") - .expect("Failed to login"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - webtile - .start_game("dcss-0.32", "b", "f", "b") - .expect("Failed to start game"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - webtile.quit_game().expect("Failed to quit game"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - webtile.disconnect().expect("Failed to disconnect"); -} - #[should_panic] #[test] fn verify_no_character() { + let game_id = std::env::var("GAME_ID").unwrap(); + // Safe test -- login start game, quit, and then test - reset_test("Username"); + common::reset_test("Username", game_id.as_str()); // Connect to DCSS Webtile let mut webtile = @@ -53,7 +26,7 @@ fn verify_no_character() { // Start game with simple scenario. start_game_with_scenario( &mut webtile, - "dcss-0.32", + game_id.as_str(), "b", "i", "c", @@ -65,8 +38,10 @@ fn verify_no_character() { #[should_panic] #[test] fn verify_too_wide() { + let game_id = std::env::var("GAME_ID").unwrap(); + // Safe test -- login start game, quit, and then test - reset_test("Username"); + common::reset_test("Username", game_id.as_str()); // Connect to DCSS Webtile let mut webtile = @@ -83,7 +58,7 @@ fn verify_too_wide() { // Start game with simple scenario. start_game_with_scenario( &mut webtile, - "dcss-0.32", + game_id.as_str(), "b", "i", "c", @@ -95,8 +70,10 @@ fn verify_too_wide() { #[should_panic] #[test] fn verify_too_long() { + let game_id = std::env::var("GAME_ID").unwrap(); + // Safe test -- login start game, quit, and then test - reset_test("Username"); + common::reset_test("Username", game_id.as_str()); // Connect to DCSS Webtile let mut webtile = @@ -113,7 +90,7 @@ fn verify_too_long() { // Start game with simple scenario. start_game_with_scenario( &mut webtile, - "dcss-0.32", + game_id.as_str(), "b", "i", "c", diff --git a/dcss-scenario-builder/tests/test_wizmode.rs b/dcss-scenario-builder/tests/test_wizmode.rs index cd7433e..53e44d1 100644 --- a/dcss-scenario-builder/tests/test_wizmode.rs +++ b/dcss-scenario-builder/tests/test_wizmode.rs @@ -1,41 +1,14 @@ +mod common; + use dcss_api::{Error, Webtile}; use dcss_scenario_builder::start_game_with_scenario; -fn reset_test(username: &str) { - // Connect to DCSS Webtile - let mut webtile = - Webtile::connect("ws://localhost:8080/socket", 0, "0.32").expect("Failed to connect"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - // Log in (to a user called "Username", with a password "Password") - let _game_ids = webtile - .login_with_credentials(username, "Password") - .expect("Failed to login"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - webtile - .start_game("dcss-0.32", "b", "f", "b") - .expect("Failed to start game"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - webtile.quit_game().expect("Failed to quit game"); - - // Empty message queue; - while webtile.get_message().is_some() {} - - webtile.disconnect().expect("Failed to disconnect"); -} - #[test] fn verify_wizmode() -> Result<(), Error> { + let game_id = std::env::var("GAME_ID").unwrap(); + // Safe test -- login start game, quit, and then test - reset_test("Username"); + common::reset_test("Username", game_id.as_str()); // Connect to DCSS Webtile let mut webtile = @@ -52,7 +25,7 @@ fn verify_wizmode() -> Result<(), Error> { // Start game with simple scenario. start_game_with_scenario( &mut webtile, - "dcss-0.32", + game_id.as_str(), "b", "i", "c", @@ -62,14 +35,14 @@ fn verify_wizmode() -> Result<(), Error> { webtile.save_game().expect("Failed to save game."); - webtile.continue_game("dcss-0.32")?; + webtile.continue_game(game_id.as_str())?; while let Some(message) = webtile.get_message() { if message["msg"].as_str().unwrap() == "player" && message.as_object().unwrap().contains_key("wizard") && message["wizard"].as_u64().unwrap() == 1 { - // webtile.quit_game()?; + webtile.quit_game()?; webtile.disconnect().expect("Failed"); return Ok(()); }