Skip to content
Permalink
Browse files

test(storage) add ci tests for storages

  • Loading branch information...
fffonion committed Oct 23, 2019
1 parent 028daa5 commit ce89b7617ddd11741b9d6889213d9b9700f73427
Showing with 666 additions and 2 deletions.
  1. +8 −2 .travis.yml
  2. +135 −0 t/storage/consul.t
  3. +117 −0 t/storage/file.t
  4. +135 −0 t/storage/redis.t
  5. +136 −0 t/storage/shm.t
  6. +135 −0 t/storage/vault.t
@@ -8,6 +8,7 @@ compiler: gcc

services:
- redis-server
- docker

cache:
directories:
@@ -34,6 +35,10 @@ env:
- NGINX_VERSION=1.15.8 OPENSSL_VER=1.1.0l
- NGINX_VERSION=1.15.8 OPENSSL_VER=1.1.1d

before_install:
- docker run -d -e CONSUL_CLIENT_INTERFACE='eth0' -e CONSUL_BIND_INTERFACE='eth0' -p 127.0.0.1:8500:8500 consul agent -server -bootstrap-expect=1
- docker run -d --user root --cap-add=IPC_LOCK -e VAULT_DEV_ROOT_TOKEN_ID=root --name=ctmpl-vault -p 127.0.0.1:8200:8200 vault server -dev

install:
- export NGX_BUILD_CC=$CC
- export PATH=$PWD/work/nginx/sbin:$PWD/nginx-devel-utils:$PATH
@@ -48,10 +53,11 @@ install:
# lua libraries
- mkdir ../lib
- git clone https://github.com/openresty/lua-resty-lrucache.git ../lua-resty-lrucache
- git clone https://github.com/openresty/lua-resty-redis.git ../lua-resty-redis
- git clone -b v0.15 https://github.com/ledgetech/lua-resty-http ../lua-resty-http
- git clone -b 1.0.0 https://github.com/fffonion/lua-resty-worker-events ../lua-resty-worker-events
- git clone https://github.com/fffonion/lua-resty-openssl ../lua-resty-openssl
- cp -r ../lua-resty-lrucache/lib/* ../lua-resty-http/lib/* ../lua-resty-worker-events/lib/* ../lua-resty-openssl/lib/* ../lib/
- git clone -b 0.2.1 https://github.com/fffonion/lua-resty-openssl ../lua-resty-openssl
- cp -r ../lua-resty-lrucache/lib/* ../lua-resty-redis/lib/* ../lua-resty-http/lib/* ../lua-resty-worker-events/lib/* ../lua-resty-openssl/lib/* ../lib/
- find ../lib
# luajit
- git clone -b v2.1-agentzh https://github.com/openresty/luajit2.git
@@ -0,0 +1,135 @@
# vim:set ft= ts=4 sw=4 et fdm=marker:

use Test::Nginx::Socket::Lua 'no_plan';
use Cwd qw(cwd);


my $pwd = cwd();

our $HttpConfig = qq{
lua_package_path "$pwd/lib/?.lua;$pwd/lib/?/init.lua;$pwd/../lib/?.lua;$pwd/../lib/?/init.lua;;";
};

run_tests();

__DATA__
=== TEST 1: Consul set key
--- http_config eval: $::HttpConfig
--- config
location =/t {
content_by_lua_block {
local st = require("resty.acme.storage.consul")
st = st.new()
local err = st:set("key1", "2")
ngx.say(err)
local err = st:set("key1", "new value")
ngx.say(err)
}
}
--- request
GET /t
--- response_body_like eval
"nil
"
--- no_error_log
[error]
=== TEST 2: Consul get key
--- http_config eval: $::HttpConfig
--- config
location =/t {
content_by_lua_block {
local st = require("resty.acme.storage.consul")
st = st.new()
local err = st:set("key2", "3")
ngx.say(err)
local v, err = st:get("key2")
ngx.say(err)
ngx.say(v)
}
}
--- request
GET /t
--- response_body_like eval
"nil
nil
3
"
--- no_error_log
[error]
=== TEST 3: Consul delete key
--- http_config eval: $::HttpConfig
--- config
location =/t {
content_by_lua_block {
local st = require("resty.acme.storage.consul")
st = st.new()
local err = st:set("key3", "3")
ngx.say(err)
local v, err = st:get("key3")
ngx.say(err)
ngx.say(v)
local err = st:delete("key3")
ngx.say(err)
-- now the key should be deleted
local v, err = st:get("key3")
ngx.say(err)
ngx.say(v)
-- delete again with no error
local err = st:delete("key3")
ngx.say(err)
}
}
--- request
GET /t
--- response_body_like eval
"nil
nil
3
nil
nil
nil
nil
"
--- no_error_log
[error]
=== TEST 4: Consul list keys
--- http_config eval: $::HttpConfig
--- config
location =/t {
content_by_lua_block {
local st = require("resty.acme.storage.consul")
st = st.new()
local err = st:set("prefix1", "bb--")
ngx.say(err)
local err = st:set("pref-x2", "aa--")
ngx.say(err)
local err = st:set("prefix3", "aa--")
ngx.say(err)
local keys, err = st:list("prefix")
ngx.say(err)
table.sort(keys)
for _, p in ipairs(keys) do ngx.say(p) end
local keys, err = st:list("nonexistent")
ngx.say(#keys)
}
}
--- request
GET /t
--- response_body_like eval
"nil
nil
nil
nil
prefix1
prefix3
0
"
--- no_error_log
[error]
@@ -0,0 +1,117 @@
# vim:set ft= ts=4 sw=4 et fdm=marker:

use Test::Nginx::Socket::Lua 'no_plan';
use Cwd qw(cwd);


my $pwd = cwd();

our $HttpConfig = qq{
lua_package_path "$pwd/lib/?.lua;$pwd/lib/?/init.lua;$pwd/../lib/?.lua;$pwd/../lib/?/init.lua;;";
};

run_tests();

__DATA__
=== TEST 1: File set key
--- http_config eval: $::HttpConfig
--- config
location =/t {
content_by_lua_block {
local st = require("resty.acme.storage.file")
st = st.new()
local err = st:set("key1", "2")
ngx.say(err)
local err = st:set("key1", "new value")
ngx.say(err)
}
}
--- request
GET /t
--- response_body_like eval
"nil
"
--- no_error_log
[error]
=== TEST 2: File get key
--- http_config eval: $::HttpConfig
--- config
location =/t {
content_by_lua_block {
local st = require("resty.acme.storage.file")
st = st.new()
local err = st:set("key2", "3")
ngx.say(err)
local v, err = st:get("key2")
ngx.say(err)
ngx.say(v)
}
}
--- request
GET /t
--- response_body_like eval
"nil
nil
3
"
--- no_error_log
[error]
=== TEST 3: File delete key
--- http_config eval: $::HttpConfig
--- config
location =/t {
content_by_lua_block {
local st = require("resty.acme.storage.file")
st = st.new()
local err = st:set("key3", "3")
ngx.say(err)
local v, err = st:get("key3")
ngx.say(err)
ngx.say(v)
local err = st:delete("key3")
ngx.say(err)
-- now the key should be deleted
local v, err = st:get("key3")
ngx.say(err)
ngx.say(v)
-- delete again with no error
local err = st:delete("key3")
ngx.say(err)
}
}
--- request
GET /t
--- response_body_like eval
"nil
nil
3
nil
nil
nil
nil
"
--- error_log
can't read file
=== TEST 4: File list keys is NYI
--- http_config eval: $::HttpConfig
--- config
location =/t {
content_by_lua_block {
local st = require("resty.acme.storage.file")
st = st.new()
local keys, err = st:list("prefix")
ngx.say(err)
}
}
--- request
GET /t
--- response_body_like eval
"nyi
"
--- no_error_log
[error]

0 comments on commit ce89b76

Please sign in to comment.
You can’t perform that action at this time.