From f9348593aae6b2f6f06845965e4ab21d0ca56773 Mon Sep 17 00:00:00 2001 From: David Leal Date: Wed, 4 Nov 2020 15:26:05 -0600 Subject: [PATCH] Add Integration Test --- .github/workflows/integration-test.yml | 13 +++++++++++++ init.lua | 5 +++++ integration-test.sh | 20 ++++++++++++++++++++ integration_test.lua | 25 +++++++++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 .github/workflows/integration-test.yml create mode 100644 integration-test.sh create mode 100644 integration_test.lua diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml new file mode 100644 index 0000000..fdb28b5 --- /dev/null +++ b/.github/workflows/integration-test.yml @@ -0,0 +1,13 @@ +name: integration-test +on: [push, pull_request] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@master + + - name: integration-test + run: ./integration-test.sh diff --git a/init.lua b/init.lua index 8dfa0a2..1be4d4d 100644 --- a/init.lua +++ b/init.lua @@ -1,3 +1,8 @@ +-- integration test +if minetest.settings:get_bool("technic_armor.enable_technic_armor_integration_test") then + dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/integration_test.lua") +end + -- support for i18n local S = minetest.get_translator("3d_armor") diff --git a/integration-test.sh b/integration-test.sh new file mode 100644 index 0000000..6e12968 --- /dev/null +++ b/integration-test.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# simple integration test + +CFG=/tmp/minetest.conf +MTDIR=/tmp/mt +WORLDDIR=${MTDIR}/worlds/world + +cat < ${CFG} + technic_armor.enable_technic_armor_integration_test = true +EOF + +mkdir -p ${WORLDDIR} +chmod 777 ${MTDIR} -R +docker run --rm -i \ + -v ${CFG}:/etc/minetest/minetest.conf:ro \ + -v ${MTDIR}:/var/lib/minetest/.minetest \ + -v $(pwd):/var/lib/minetest/.minetest/worlds/world/worldmods/technic_armor \ + registry.gitlab.com/minetest/minetest/server:5.3.0 + +test -f ${WORLDDIR}/integration_test.json && exit 0 || exit 1 diff --git a/integration_test.lua b/integration_test.lua new file mode 100644 index 0000000..65e9dfd --- /dev/null +++ b/integration_test.lua @@ -0,0 +1,25 @@ + +minetest.log("warning", "[TEST] integration-test enabled!") + +minetest.register_on_mods_loaded(function() + minetest.after(1, function() + + local data = minetest.write_json({ success = true }, true); + local file = io.open(minetest.get_worldpath().."/integration_test.json", "w" ); + if file then + file:write(data) + file:close() + end + + file = io.open(minetest.get_worldpath().."/registered_nodes.txt", "w" ); + if file then + for name in pairs(minetest.registered_nodes) do + file:write(name .. '\n') + end + file:close() + end + + minetest.log("warning", "[TEST] integration tests done!") + minetest.request_shutdown("success") + end) +end)