Skip to content

Commit

Permalink
Merge pull request #449 from Mashape/fix/alf-record
Browse files Browse the repository at this point in the history
[hotfix/analytics] alf serializer stringifies records
  • Loading branch information
thibaultcha committed Aug 10, 2015
2 parents 3c37508 + a8ee41d commit 06ef332
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
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

0 comments on commit 06ef332

Please sign in to comment.