-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Develop to master (#117) * new incremental version (#111) * fixing mocka failing some nginx tests * version 1.3.0 * update code * making a centos docker * add loop script * working nginx/openresty * add boiler plate * small refactoring * update some more * fixing issues and adding docker-compose for running * correct mapping * adding example * adding examples * adding examples * finished example * support and example + coverage * update
- Loading branch information
Showing
22 changed files
with
528 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
exclude = { | ||
".*test.*$", | ||
".*mocka.*$", | ||
".*5%.1.*$", | ||
".*ngx.*$", | ||
".*lualib.*resty.*$" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
--- Generated by EmmyLua(https://github.com/EmmyLua) | ||
--- Created by trifan. | ||
--- DateTime: 13/08/2018 17:06 | ||
--- | ||
local coverage_info = require "coverage_modules" | ||
local configuration = { | ||
-- standard luacov configuration keys and values here | ||
cobertura = { | ||
-- this function will be called for each filename in the stats file | ||
-- the function may be used to manipulate the path before the file is | ||
-- processed by the report generator | ||
mangleFile = function(filename) | ||
-- do stuff with the filename here | ||
local words = filename:gmatch("([^/%.)]+)") | ||
local splitPath = {} | ||
for word in words do | ||
table.insert(splitPath, word) | ||
end | ||
|
||
if coverage_info.modules[splitPath[#splitPath - 1]] then | ||
return coverage_info.modules[splitPath[#splitPath - 1]] | ||
end | ||
|
||
return filename | ||
end | ||
} | ||
} | ||
return configuration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
version: '2.1' | ||
services: | ||
mocka_openresty: | ||
mem_limit: 2048m | ||
image: mocka:latest | ||
entrypoint: /scripts/start_nginx.sh | ||
privileged: true | ||
cap_add: | ||
- SYS_PTRACE | ||
volumes: | ||
- ./nginx:/usr/local/openresty/nginx/conf | ||
- ./example/openresty:/usr/local/openresty/nginx/conf/tests | ||
- ./logs:/var/log/nginx | ||
- ./test-results-openresty.xml:/mocka_space/test-results.xml | ||
- ./coverage_report.xml:/mocka_space/coverage_report.xml | ||
- ./.luacov.openresty:/mocka_space/.luacov | ||
- ./luacov.stats.out:/mocka_space/luacov.stats.out | ||
- ./luacov.report.out:/mocka_space/luacov.report.out | ||
- ./config_cobertura.lua:/mocka_space/config_cobertura.lua | ||
- ./coverage_modules.lua:/mocka_space/coverage_modules.lua | ||
- ./cores:/tmp/cores |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
|
||
echo "This is a idle script (infinite loop) to keep container running." | ||
echo "Please replace this script." | ||
|
||
cleanup () | ||
{ | ||
kill -s SIGTERM $! | ||
exit 0 | ||
} | ||
|
||
trap cleanup SIGINT SIGTERM | ||
|
||
while [ 1 ] | ||
do | ||
sleep 60 & | ||
wait $! | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/env bash | ||
wget https://openresty.org/package/centos/openresty.repo | ||
sudo mv openresty.repo /etc/yum.repos.d/ | ||
|
||
# update the yum index: | ||
sudo yum check-update | ||
|
||
sudo yum install openresty -y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/bin/bash | ||
|
||
nginx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
server { | ||
listen 9191; | ||
server_name test.example.adobe; | ||
access_log /var/log/nginx/test.example.adobe_access.log; | ||
error_log /var/log/nginx/test.example.adobe_error.log debug; | ||
|
||
location /test { | ||
content_by_lua_block { | ||
local module = require "adobe.module.say":new() | ||
module:say("hello") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
local http_util = require "mocka.http_util" | ||
|
||
return function() | ||
-- order matters - first beforeEach then afterEach | ||
beforeEach(function() | ||
-- do something here | ||
end) | ||
afterEach(function() | ||
-- do something here | ||
end) | ||
test('test spy say negation', function() | ||
spy('adobe.module.say', "say", function(self, what) | ||
ngx.status = 200 | ||
ngx.print("not " .. what) | ||
end) | ||
|
||
local res, err = http_util:request("127.0.0.1", 9191) | ||
:path("/test") | ||
:header("Host", "test.example.adobe") | ||
:get() | ||
|
||
assertNil(err) | ||
assertEquals(res.status, 200) | ||
|
||
--test that the spy works | ||
assertEquals(res.body, "not hello") | ||
end) | ||
test('test that a spy is back to normal', function() | ||
local res, err = http_util:request("127.0.0.1", 9191) | ||
:path("/test") | ||
:header("Host", "test.example.adobe") | ||
:get() | ||
|
||
assertNil(err) | ||
assertEquals(res.status, 200) | ||
|
||
calls(spy("adobe.module.say").say, 1) | ||
assertEquals(res.body, "hello") | ||
end) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
-- | ||
-- Created by IntelliJ IDEA. | ||
-- User: trifan | ||
-- Date: 07/01/17 | ||
-- Time: 03:15 | ||
-- To change this template use File | Settings | File Templates. | ||
-- | ||
local defaultTests = { | ||
"adobe.example.test" | ||
} | ||
|
||
return { | ||
["run"] = function(self, tests) | ||
if tests == nil or next(tests) == nil then | ||
tests = defaultTests | ||
end | ||
return require("mocka.ngx_suite")(tests) | ||
end | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
|
||
lua_package_path '/usr/local/openresty/nginx/conf/lua/?.lua;scripts/?.lua;/usr/local/lib/lua/?.lua;/opt/zbstudio/lualibs/?/?.lua;/opt/zbstudio/lualibs/?.lua;/usr/local/openresty/nginx/conf/tests/lua/?.lua;;'; | ||
lua_package_cpath '/opt/zbstudio/bin/linux/x64/clibs/?.so;/usr/local/openresty/nginx/conf/lua/?.so;/usr/local/openresty/nginx/conf/tests/lua/?.so;;'; | ||
|
||
init_worker_by_lua_file /usr/local/openresty/nginx/conf/lua/worker_init.lua; | ||
|
||
|
||
server_names_hash_bucket_size 1024; | ||
|
||
# Sendfile copies data between one FD and other from within the kernel. | ||
# More efficient than read() + write(), since the requires transferring data to and from the user space. | ||
sendfile on; | ||
|
||
# Tcp_nopush causes nginx to attempt to send its HTTP response head in one packet, | ||
# instead of using partial frames. This is useful for prepending headers before calling sendfile, | ||
# or for throughput optimization. | ||
tcp_nopush on; | ||
|
||
# Caches information about open FDs, freqently accessed files. | ||
open_file_cache max=200000 inactive=20s; | ||
open_file_cache_valid 30s; | ||
open_file_cache_min_uses 2; | ||
open_file_cache_errors on; | ||
|
||
|
||
#define the limit request zone for default locations | ||
limit_req_zone $http_x_forwarded_for zone=free_ip_def:10m rate=10r/s; | ||
client_body_temp_path /var/tmp/client_body_temp 1 2; | ||
proxy_temp_path /var/tmp/proxy_temp; | ||
keepalive_timeout 65; | ||
# allow the server to close the connection after a client stops responding. Frees up socket-associated memory. | ||
reset_timedout_connection on; | ||
|
||
default_type application/octet-stream; | ||
|
||
variables_hash_max_size 2048; | ||
proxy_headers_hash_max_size 2048; | ||
#gzip on; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
server { | ||
listen 9191; | ||
server_name mocka.tests.io; | ||
|
||
access_log /var/log/nginx/mocka.log; | ||
error_log /var/log/nginx/mocka_error.log debug ; | ||
|
||
# url /run-tests?tests=com.adobe.io.sometest | ||
location /run-tests { | ||
content_by_lua_block { | ||
local tests = ngx.var.arg_tests | ||
if tests == nil or tests == "" then | ||
tests = {} | ||
else | ||
local tests_string = ngx.var.arg_tests | ||
tests = {} | ||
for test_name in tests_string:gmatch("([^,]+)") do | ||
table.insert(tests, test_name) | ||
end | ||
end | ||
local runner = require("luacov.runner") | ||
runner.init() | ||
local integration_tests = require "integration_tests" | ||
local response = integration_tests:run(tests) | ||
ngx.status = 200 | ||
ngx.say(response) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
local M = {} | ||
|
||
function M:new(o) | ||
o = o or {} | ||
setmetatable(o, self) | ||
self.__index = self | ||
return o | ||
end | ||
|
||
function M:say(what) | ||
ngx.status = 200 | ||
ngx.print(what) | ||
end | ||
|
||
return M |
Oops, something went wrong.