use mtt for integration tests

This commit is contained in:
BuckarooBanzay 2022-08-02 14:56:32 +02:00
parent 4b496a1e61
commit 5642f139df
17 changed files with 75 additions and 130 deletions

View File

@ -1,15 +0,0 @@
name: integration-test
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@master
- name: integration-test
run: ./test/integration-test.sh

17
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,17 @@
name: test
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
matrix:
ENGINE_VERSION: [5.3.0, 5.4.0, 5.5.0, latest]
steps:
- uses: actions/checkout@v2
- name: test
run: docker-compose up --exit-code-from sut

View File

@ -18,5 +18,5 @@ read_globals = {
"unified_inventory", "default",
-- optional mods
"xban", "QoS"
"xban", "QoS", "mtt"
}

View File

@ -1,7 +1,7 @@
Mail mod for Minetest (ingame mod)
======
![](https://github.com/minetest-mail/mail_mod/workflows/integration-test/badge.svg)
![](https://github.com/minetest-mail/mail_mod/workflows/test/badge.svg)
![](https://github.com/minetest-mail/mail_mod/workflows/luacheck/badge.svg)

19
docker-compose.yml Normal file
View File

@ -0,0 +1,19 @@
version: "3.6"
services:
sut:
build:
context: ./test
args:
ENGINE_VERSION: ${ENGINE_VERSION:-5.5.0}
user: root
volumes:
- "./:/root/.minetest/worlds/world/worldmods/mail/"
- "world_data:/root/.minetest/worlds/world"
- "./test/world.mt:/root/.minetest/worlds/world/world.mt"
- "./test/minetest.conf:/minetest.conf"
ports:
- "30000:30000/udp"
volumes:
world_data: {}

View File

@ -64,3 +64,7 @@ end
-- migrate storage
mail.migrate()
if minetest.get_modpath("mtt") then
dofile(MP .. "/mtt.lua")
end

View File

@ -1,3 +1,3 @@
name = mail
description = mail mod
optional_depends = unified_inventory,default,xban2,qos
description = ingame mail-system
optional_depends = unified_inventory,default,xban2,qos,mtt

10
mtt.lua Normal file
View File

@ -0,0 +1,10 @@
mtt.register("send mail", function(callback)
-- send a mail
mail.send("player1", "player2", "something", "blah")
-- check the receivers inbox
local list2 = mail.getMessages("player2")
assert(list2 ~= nil and #list2 > 0)
callback()
end)

10
test/Dockerfile Normal file
View File

@ -0,0 +1,10 @@
ARG ENGINE_VERSION=5.5.0
FROM registry.gitlab.com/minetest/minetest/server:${ENGINE_VERSION}
USER root
RUN apk add git &&\
mkdir -p /root/.minetest/worlds/world/worldmods/ &&\
git clone https://github.com/BuckarooBanzay/mtt /root/.minetest/worlds/world/worldmods/mtt
ENTRYPOINT minetestserver --config /minetest.conf

Binary file not shown.

View File

@ -1,4 +0,0 @@
User,Password
-----------------
test,enter
test2,enter

View File

@ -1,79 +0,0 @@
#!/bin/bash
MINETEST_VERSION=5.2.0
# prerequisites
jq --version || exit 1
curl --version || exit 1
# ensure proper current directory
CWD=$(dirname $0)
cd ${CWD}
# setup
unset use_proxy
unset http_proxy
unset https_proxy
unset HTTP_PROXY
unset HTTPS_PROXY
# run mail-server
docker pull minetestmail/mail
docker run --name mail --rm \
-e WEBMAILKEY=myserverkey \
-e WEBMAIL_DEBUG=true \
--network host \
minetestmail/mail &
# wait for startup
bash -c 'while !</dev/tcp/localhost/8080; do sleep 1; done;'
# start minetest with mail mod
docker pull registry.gitlab.com/minetest/minetest/server:${MINETEST_VERSION}
docker run --rm --name minetest \
-u root:root \
-v $(pwd)/minetest.conf:/etc/minetest/minetest.conf:ro \
-v $(pwd)/world.mt:/root/.minetest/worlds/world/world.mt \
-v $(pwd)/auth.sqlite:/root/.minetest/worlds/world/auth.sqlite \
-v $(pwd)/../:/root/.minetest/worlds/world/worldmods/mail \
-v $(pwd)/test_mod:/root/.minetest/worlds/world/worldmods/mail_test \
-e use_proxy=false \
-e http_proxy= \
-e HTTP_PROXY= \
--network host \
registry.gitlab.com/minetest/minetest/server:${MINETEST_VERSION} &
# prepare cleanup
function cleanup {
# cleanup
docker stop mail
docker stop minetest
}
trap cleanup EXIT
# wait for startup
sleep 5
# Execute calls against mail-server
# login
LOGIN_DATA='{"username":"test","password":"enter"}'
RES=$(curl --data "${LOGIN_DATA}" -H "Content-Type: application/json" "http://127.0.0.1:8080/api/login")
echo Login response: $RES
SUCCESS=$(echo $RES | jq -r .success)
TOKEN=$(echo $RES | jq -r .token)
# login succeeded
test "$SUCCESS" == "true" || exit 1
# token extracted
test -n "$TOKEN" || exit 1
# fetch mails
RES=$(curl -H "Authorization: ${TOKEN}" "http://127.0.0.1:8080/api/inbox")
echo Mailbox: ${RES}
# inbox count is 1
test "$(echo $RES | jq '. | length')" == "1" || exit 1
echo "Test complete!"

View File

@ -1,4 +1,3 @@
secure.http_mods = mail
webmail.url = http://localhost:8080
webmail.key = myserverkey
webmail.disallow_banned_players = true
default_game = minetest_game
mg_name = v7
mtt_enable = true

View File

@ -1,10 +0,0 @@
#!/bin/sh
docker run --rm -it \
-u root:root \
-v $(pwd)/minetest.conf:/etc/minetest/minetest.conf \
-v $(pwd)/auth.sqlite:/root/.minetest/worlds/world/auth.sqlite \
-v $(pwd)/../:/root/.minetest/worlds/world/worldmods/mail_mod \
-v mail_world:/root/.minetest/worlds/world/ \
--network host \
registry.gitlab.com/minetest/minetest/server:5.2.0

View File

@ -1,7 +0,0 @@
minetest.log("warning", "[TEST] integration-test enabled!")
minetest.register_on_mods_loaded(function()
minetest.log("warning", "[TEST] starting tests")
mail.send("spammer", "test", "subject", "body");
end)

View File

@ -1,2 +0,0 @@
name = mail_test
depends = mail

View File

@ -1,6 +1,9 @@
enable_damage = true
creative_mode = false
gameid = minetest
enable_damage = false
creative_mode = true
mod_storage_backend = sqlite3
auth_backend = sqlite3
backend = sqlite3
player_backend = sqlite3
player_backend = dummy
backend = dummy
gameid = minetest
world_name = mapblock_lib
server_announce = false