diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index 4801347..18b2e32 100755 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -8,7 +8,7 @@ on: jobs: lint-lua-code: - name: Rite of Static Scrutiny (Luacheck) + name: Luacheck static analysis runs-on: ubuntu-latest container: @@ -27,4 +27,27 @@ jobs: - name: 3. Run Luacheck Scrutiny run: | echo "Scanning Lua scripture for syntactical heresy..." - luacheck --std lua51 . \ No newline at end of file + luacheck --std lua51 . + + unit-test-lua: + name: Rite of Unit Inquisition (Busted) + # This job will only start if the 'lint-lua-code' job is successful. + needs: lint-lua-code + runs-on: ubuntu-latest + # Use a container that has Lua and the 'luarocks' package manager. + container: + image: luajit/luajit:v2.1-alpine + steps: + - name: 1. Checkout Repository Code + uses: actions/checkout@v4 + - name: 2. Install Busted Framework + run: | + echo "Sanctifying container with the Busted testing framework..." + # Luarocks is the package manager for Lua modules. + apk add --no-cache git + luarocks install busted + - name: 3. Perform Unit Inquisition + run: | + echo "Initiating unit inquisition..." + # Busted will automatically find and run files in the 'spec/' directory. + busted --lua=lua5.1 --verbose spec/ \ No newline at end of file diff --git a/spec/utisl_spec.lua b/spec/utisl_spec.lua new file mode 100755 index 0000000..251c520 --- /dev/null +++ b/spec/utisl_spec.lua @@ -0,0 +1,40 @@ +-- This test script will verify the functions within skyweave/utils.lua +package.path = './skyweave/?.lua;' .. package.path + +local utils = require("utils") + +describe("Skyweave Utility Functions Module", function() + + -- A nested 'describe' for the specific function we are testing. + describe("parse_query_string", function() + + -- 'it' blocks contain the actual test cases. + it("should correctly parse a single key-value pair", function() + local query = "get_config=network_config" + local expected = { get_config = "network_config" } + -- 'assert' is used to check if the result matches our expectation. + assert.are.same(expected, utils.parse_query_string(query)) + end) + + it("should handle multiple parameters correctly", function() + local query = "ssid=MyWifi&encryption=psk2&channel=11" + local expected = { ssid = "MyWifi", encryption = "psk2", channel = "11" } + assert.are.same(expected, utils.parse_query_string(query)) + end) + + it("should handle URL-encoded characters", function() + local query = "ssid=My%20Awesome%20Wifi" + local expected = { ssid = "My Awesome Wifi" } + assert.are.same(expected, utils.parse_query_string(query)) + end) + + it("should return an empty table for a nil or empty query string", function() + assert.are.same({}, utils.parse_query_string("")) + assert.are.same({}, utils.parse_query_string(nil)) + end) + + end) + + -- more 'describe' blocks here to test other functions in utils.lua + +end) \ No newline at end of file