-
Notifications
You must be signed in to change notification settings - Fork 170
/
Copy pathuser_agent_spec.lua
67 lines (49 loc) · 1.87 KB
/
user_agent_spec.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
local user_agent = require 'apicast.user_agent'
local ffi = require("ffi")
local env = require 'resty.env'
describe('User Agent', function()
before_each(function() user_agent.reset() end)
describe('.deployment', function()
it('reads from environment', function()
env.set('THREESCALE_DEPLOYMENT_ENV', 'foobar')
user_agent.reset()
assert.same('foobar', user_agent.deployment())
end)
it('uses internal structure', function()
user_agent.env.threescale_deployment_env = 'bar'
assert.same('bar', user_agent.deployment())
end)
end)
describe('.user_agent', function()
-- User-Agent: <product> / <product-version> <comment>
-- User-Agent: Mozilla/<version> (<system-information>) <platform> (<platform-details>) <extensions>
it('matches common format', function()
user_agent.env.threescale_deployment_env = 'production'
assert.match('APIcast/' .. user_agent._VERSION, user_agent.call(), nil, true)
end)
it('includes system information', function()
assert.match('(' .. user_agent.system_information() .. ')', user_agent.call())
end)
it('works as tostring', function()
assert.equal(user_agent.call(), tostring(user_agent))
end)
it('works as function', function()
assert.equal(user_agent.call(), user_agent())
end)
end)
describe('.system_information', function()
it('includes os information', function()
assert.match(ffi.os ..'; ' .. ffi.arch, user_agent.system_information())
end)
it('includes deployment information', function()
user_agent.env.threescale_deployment_env = 'foobar'
assert.match(' env:foobar', user_agent.system_information())
end)
end)
describe('.call', function()
it('returns a string', function()
stub(user_agent, 'platform').returns(nil)
assert.equal('string', type(user_agent.call()))
end)
end)
end)