Software / code / prosody
Comparison
spec/net_http_parser_spec.lua @ 8236:4878e4159e12
Port tests to the `busted` test runner
| author | Waqas Hussain <waqas20@gmail.com> |
|---|---|
| date | Fri, 15 Sep 2017 17:07:57 -0400 |
| child | 10497:a9fb553b6dbb |
comparison
equal
deleted
inserted
replaced
| 8235:7d9a2c200736 | 8236:4878e4159e12 |
|---|---|
| 1 local httpstreams = { [[ | |
| 2 GET / HTTP/1.1 | |
| 3 Host: example.com | |
| 4 | |
| 5 ]], [[ | |
| 6 HTTP/1.1 200 OK | |
| 7 Content-Length: 0 | |
| 8 | |
| 9 ]], [[ | |
| 10 HTTP/1.1 200 OK | |
| 11 Content-Length: 7 | |
| 12 | |
| 13 Hello | |
| 14 HTTP/1.1 200 OK | |
| 15 Transfer-Encoding: chunked | |
| 16 | |
| 17 1 | |
| 18 H | |
| 19 1 | |
| 20 e | |
| 21 2 | |
| 22 ll | |
| 23 1 | |
| 24 o | |
| 25 0 | |
| 26 | |
| 27 | |
| 28 ]] | |
| 29 } | |
| 30 | |
| 31 | |
| 32 local http_parser = require "net.http.parser"; | |
| 33 | |
| 34 describe("net.http.parser", function() | |
| 35 describe("#new()", function() | |
| 36 it("should work", function() | |
| 37 for _, stream in ipairs(httpstreams) do | |
| 38 local success; | |
| 39 local function success_cb(packet) | |
| 40 success = true; | |
| 41 end | |
| 42 stream = stream:gsub("\n", "\r\n"); | |
| 43 local parser = http_parser.new(success_cb, error, stream:sub(1,4) == "HTTP" and "client" or "server") | |
| 44 for chunk in stream:gmatch("..?.?") do | |
| 45 parser:feed(chunk); | |
| 46 end | |
| 47 | |
| 48 assert.is_true(success); | |
| 49 end | |
| 50 end); | |
| 51 end); | |
| 52 end); |