Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test case #5

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
language: python
sudo: false

env:
- LUA="lua=5.1"

before_install:
- sudo apt-get update
- sudo apt-get install -y libssl-dev luarocks
- sudo luarocks install busted
- sudo luarocks install kong

jobs:
include:
- env: BUID="Plugin Build"
script: sudo luarocks make --pack-binary-rock
- env: BUID="TEST"
script: busted spec/
2 changes: 1 addition & 1 deletion schema.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
return {
no_consumer = true,
fields = {
cookie_name = { type = "string", default="SESSION" }
cookie_name = { type = "string", default="SESSION", required = false }
}
}
75 changes: 75 additions & 0 deletions spec/handler_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
-- local mock_req_headers = { ['Set-Cookie'] = "oauthtoken=13ca678d2aa8454599678e792266ea96; path=/" }
-- local mock_body = '{ "data": "payload_data" }'
-- local mock_ngx_headers = { ['Set-Cookie'] = "oauthtoken=13ca678d2aa8454599678e792266ea96; path=/" }
-- local mock_query_args = "query_args"
-- local mock_resp_headers = {["Set-Cookie"] = "oauthtoken=13ca678d2aa8454599678e792266ea96; path=/;", }
-- local mock_router_matches = { group_one = "test_match" }

-- local ngx = {
-- log = function() end,
-- config = {
-- subsystem = "http",
-- },
-- header = {

-- },
-- arg = {},
-- ctx = {
-- buffer = "",
-- },
-- req = {
-- get_headers = {["Set-Cookie"] = "oauthtoken=13ca678d2aa8454599678e792266ea96; Path=/;",},
-- set_header = {["Set-Cookie"] = "oauthtoken=13ca678d2aa8454599678e792266ea96; Path=/;",},
-- },
-- resp = {
-- get_headers = {["Set-Cookie"] = "oauthtoken=13ca678d2aa8454599678e792266ea96; Path=/;",},
-- },
-- var = {
-- _cookie = "13ca678d2aa8454599678e792266ea96",
-- }
-- }

-- ngx.header["Set-Cookie"] = "oauthtoken=13ca678d2aa8454599678e792266ea96; Path=/;"

-- _G.ngx = ngx

-- local CookieToHeaders = require('../handler')

-- local inspect = require('inspect')

-- -- describe("Test TemplateTransformerHandler constructor", function()
-- -- it("should set object name correctly", function()
-- -- CookieToHeaders:new()
-- -- assert.equal("cookies-to-headers", CookieToHeaders._name)
-- -- end)
-- -- end)

-- describe("Test TemplateTransformerHandler header_filter", function()
-- it("should not unset content-length header when there is no templates", function()
-- CookieToHeaders:new()
-- local mock_config = {
-- cookie_name = "oauthtoken"
-- }
-- local cookie = require "resty.cookie"

-- local ck = cookie:new()

-- -- local ok, err = ck:set({ key = "ckey",
-- -- value = "cvalue" })

-- -- print(ok)
-- local oauthToken, err = ck:get('oauthtoken')
-- if not oauthToken then
-- print(err)
-- else
-- print (oauthToken)
-- end

-- CookieToHeaders:access(mock_config)
-- -- assert.not_nil(ngx.resp)
-- -- print ( inspect (ngx))
-- print ( inspect (_G.ngx))
-- -- assert.equal(mock_resp_headers["Set-Cookie"], "123")
-- -- assert.not_nil(ngx.)
-- end)
-- end)
11 changes: 11 additions & 0 deletions spec/schema_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
local schema = require('../schema')

describe("TestSchema", function()
it("should initialize schema correctly", function()
assert.is_true(schema.no_consumer)
assert.equal("string", schema.fields.cookie_name.type)
assert.equal(false, schema.fields.cookie_name.required)
assert.equal("SESSION", schema.fields.cookie_name.default)
end)

end)