{"id":18418647,"url":"https://github.com/bsm/fakengx","last_synced_at":"2025-04-07T13:31:21.571Z","repository":{"id":66021927,"uuid":"3823921","full_name":"bsm/fakengx","owner":"bsm","description":"Library for testing Lua scripts embedded into Nginx","archived":true,"fork":false,"pushed_at":"2013-03-06T09:00:40.000Z","size":166,"stargazers_count":40,"open_issues_count":2,"forks_count":8,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-02T04:20:59.743Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bsm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-03-25T11:51:59.000Z","updated_at":"2023-08-31T10:59:36.000Z","dependencies_parsed_at":"2023-02-19T21:20:29.145Z","dependency_job_id":null,"html_url":"https://github.com/bsm/fakengx","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsm%2Ffakengx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsm%2Ffakengx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsm%2Ffakengx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsm%2Ffakengx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bsm","download_url":"https://codeload.github.com/bsm/fakengx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247661671,"owners_count":20975097,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T04:14:13.224Z","updated_at":"2025-04-07T13:31:21.299Z","avatar_url":"https://github.com/bsm.png","language":"Lua","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FakeNGX #\n\nFakeNGX is an initial attempt to create a library for testing Lua scripts\nembedded into Nginx, via [HttpLuaModule](http://wiki.nginx.org/HttpLuaModule)\n\n## Features ##\n\n* Support for basic constants: ngx.HTTP_OK, etc\n* Support for core functions: ngx.time(...), ngx.encode_args(...), etc\n* Sub-request stubbing, e.g. ngx.location.capture()\n* Fully tested with [Telescope](http://norman.github.com/telescope/)\n\n## Supported functions (currently) ##\n\n* ngx.print()\n* ngx.say()\n* ngx.log()\n* ngx.time()\n* ngx.now()\n* ngx.exit()\n* ngx.escape_uri()\n* ngx.unescape_uri()\n* ngx.encode_args()\n* ngx.crc32_short()\n* ngx.location.capture()\n\n## Usage Example ##\n\nThis is an example for how to test your scripts with FakeNGX. Imagine this is\nyour Nginx configuration:\n\n    -- nginx.conf\n    location /internal {\n      internal;\n      content_by_lua 'ngx.print(\"OK\")';\n    }\n\n    location /main {\n      content_by_lua_file 'main.lua';\n    }\n\nIt's good practice to keep file loaded by\n[content_by_lua_file](http://wiki.nginx.org/HttpLuaModule#content_by_lua_file)\nat a minimum and place all processing logic into external modules. This allows\n[lua_code_cache](http://wiki.nginx.org/HttpLuaModule#lua_code_cache)\nto work its magic and simplifies your testing. For example:\n\n    -- main.lua\n    local my_module = require 'my_module'\n    my_module.run()\n\nThen, place all the controller code into separate module(s):\n\n    -- my_module.lua\n    module(\"my_module\", package.seeall)\n\n    local function respond()\n      local res = ngx.location.capture(\"/internal\", { method = ngx.HTTP_POST })\n\n      if res.status == ngx.HTTP_OK then\n        ngx.print(res.body)\n      else\n        ngx.print(\"ERR\")\n        ngx.exit(500)\n      end\n    end\n\n    function run()\n      if ngx.var.http_authentication == \"TOKEN\"\n        respond()\n      else\n        ngx.exit(403)\n      end\n    end\n\n    return my_module\n\nIn your tests e.g. with [Telescope](http://norman.github.com/telescope/):\n\n    fakengx   = require 'fakengx'\n    my_module = require 'my_module'\n\n    context('my_module', function()\n\n      before(function()\n        ngx = fakengx.new() -- create a fresh ngx on each request context\n      end)\n\n      test('run unauthenticated', function()\n        my_module.run()\n        assert_equal(ngx._body, '')   -- No output\n        assert_equal(ngx._exit, 403)  -- Exited with 403\n        assert_equal(ngx.status, 403) -- Response status\n      end)\n\n      test('run success', function()\n        ngx.location.stub('/internal', {}, { body = \"OK\" })\n        ngx.var['http_authentication' = \"TOKEN\"\n        my_module.run()\n        assert_equal(ngx._body, 'OK') -- Written \"OK\"\n        assert_nil(ngx._exit)         -- No explicit exit\n        assert_equal(ngx.status, 200) -- Response status\n      end)\n\n      test('run failure', function()\n        ngx.location.stub('/internal', {}, { status = 302 })\n        my_module.run()\n        assert_equal(ngx._body, 'ERR')\n        assert_equal(ngx._exit, 500)\n        assert_equal(ngx.status, 500)\n      end)\n\n    end)\n\n## Prerequsites ##\n\nFakeNGX relies on the [luasocket](http://w3.impa.br/~diego/software/luasocket/)\nand the [bitop](http://bitop.luajit.org/) libraries.\n\nTo install (on Debian, Ubuntu, etc):\n\n    sudo apt-get install lua5.1 luarocks liblua5.1-socket2 liblua5.1-bitop0 liblua5.1-md5-0\n\n## Contributing ##\n\nYou need to install telescope, via LuaRocks:\n\n    sudo luarocks install telescope\n\nAnd run:\n\n    tsc -f spec/*_spec.lua\n\n\n## License ##\n\nThe MIT License\n\nCopyright (c) 2012 Dimitrij Denissenko\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of\nthis software and associated documentation files (the \"Software\"), to deal in\nthe Software without restriction, including without limitation the rights to\nuse, copy, modify, merge, publish, distribute, sublicense, and/or sell copies\nof the Software, and to permit persons to whom the Software is furnished to do\nso, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsm%2Ffakengx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbsm%2Ffakengx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsm%2Ffakengx/lists"}