From 696548f6d30064db79d4cc161e5b66fa3a0d4711 Mon Sep 17 00:00:00 2001 From: David Leal <halfpacho@gmail.com> Date: Wed, 4 Nov 2020 12:05:17 -0600 Subject: [PATCH] Add integration test (based on 3D Armor's integration test) (#7) * Add integration test (based from 3D Armor's... ...integration test). * Add Integration Test status badge * make the `integration-test.sh` file executable Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com> --- .github/workflows/integration-test.yml | 14 ++++++++++++++ README.md | 3 ++- init.lua | 5 +++++ integration-test.sh | 20 ++++++++++++++++++++ integration_test.lua | 25 +++++++++++++++++++++++++ 5 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/integration-test.yml create mode 100755 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..eb104ac --- /dev/null +++ b/.github/workflows/integration-test.yml @@ -0,0 +1,14 @@ +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/README.md b/README.md index 03c181f..1032708 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # TravelNet -![](https://github.com/mt-mods/travelnet/workflows/luacheck/badge.svg) +[![Build status](https://github.com/mt-mods/travelnet/workflows/luacheck/badge.svg)](https://github.com/mt-mods/travelnet/actions?query=workflow%3Aluacheck) +[![Integration test status](https://github.com/mt-mods/travelnet/workflows/integration-test/badge.svg)](https://github.com/mt-mods/travelnet/actions?query=workflow%3Aintegration-test) How this works: diff --git a/init.lua b/init.lua index 1e03de1..8121336 100644 --- a/init.lua +++ b/init.lua @@ -85,6 +85,11 @@ - target list is now centered if there are less than 9 targets --]] +-- integration test +if minetest.settings:get_bool("travelnet.enable_travelnet_integration_test") then + dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/integration_test.lua") +end + -- Required to save the travelnet data properly in all cases if not minetest.safe_file_write then error("[Mod travelnet] Your Minetest version is no longer supported. (version < 0.4.17)") diff --git a/integration-test.sh b/integration-test.sh new file mode 100755 index 0000000..7680c07 --- /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 <<EOF > ${CFG} + travelnet.enable_travelnet_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/travelnet \ + 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)