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

[hotfix/analytics] alf serializer stringifies records #449

Merged
merged 1 commit into from
Aug 10, 2015
Merged
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
2 changes: 2 additions & 0 deletions kong/plugins/log_serializers/alf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ local function dic_to_array(hash, fn)
v = {v}
end
for _, val in ipairs(v) do
k = tostring(k)
val = tostring(val)
table.insert(arr, {name = k, value = val})
fn(k, val)
end
Expand Down
13 changes: 10 additions & 3 deletions spec/plugins/mashape-analytics/alf_serializer_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ local function sameEntry(state, arguments)
assert.True(math.abs(entry.time - fixture_entry.time) < delta)

-- Compare things that are not computed in the same order depending on the platform
assert.are.equal(#(fixture_entry.request.headers), #(entry.request.headers))
assert.are.equal(#(fixture_entry.request.queryString), #(entry.request.queryString))
assert.are.equal(#(fixture_entry.response.headers), #(entry.response.headers))
assert.equal(#(fixture_entry.request.headers), #(entry.request.headers))
assert.equal(#(fixture_entry.request.queryString), #(entry.request.queryString))
assert.equal(#(fixture_entry.response.headers), #(entry.response.headers))

entry.time = nil
entry.timings = nil
Expand Down Expand Up @@ -98,5 +98,12 @@ describe("ALF serializer", function()
local alf = ALFSerializer.new_alf(fixtures.GET.NGX_STUB, "123456", "test")
assert.equal("test", alf.environment)
end)
-- https://github.com/ahmadnassri/har-validator/blob/8fd21c30edb23a1fed2d50b934d055d1be3dd7c9/lib/schemas/record.json#L12
it("should convert all records to strings", function()
local alf = ALFSerializer.new_alf(fixtures.GET.NGX_STUB, "123456", "test")
for _, record in ipairs(alf.har.log.entries[1].request.queryString) do
assert.equal("string", type(record.value))
end
end)
end)
end)
5 changes: 3 additions & 2 deletions spec/plugins/mashape-analytics/fixtures/requests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ return {
get_method = function() return "GET" end,
http_version = function() return 1.1 end,
get_headers = function() return {["Accept"] = "/*/", ["Host"] = "mockbin.com"} end,
get_uri_args = function() return {["hello"] = "world", ["foo"] = "bar"} end,
get_uri_args = function() return {["hello"] = "world", ["foo"] = "bar", ["number"] = 2} end,
get_post_args = function() return {["hello"] = {"world", "earth"}} end
},
resp = {
Expand Down Expand Up @@ -56,7 +56,8 @@ return {
},
queryString = {
{name = "foo", value = "bar"},
{name = "hello", value = "world"}
{name = "hello", value = "world"},
{name = "hello", value = "2"}
},
url = "http://mockbin.com/request"
},
Expand Down