Mercurial > prosody-hg
comparison spec/net_websocket_frames_spec.lua @ 10584:0c464bb7eb03
net.websocket.frames: Add ping and pong test cases
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 02 Jan 2020 13:17:43 +0100 |
| parents | 624ad69dbaf7 |
| children | 51e5149ed0ad |
comparison
equal
deleted
inserted
replaced
| 10583:624ad69dbaf7 | 10584:0c464bb7eb03 |
|---|---|
| 41 ["RSV1"] = false; | 41 ["RSV1"] = false; |
| 42 ["RSV2"] = false; | 42 ["RSV2"] = false; |
| 43 ["RSV3"] = false; | 43 ["RSV3"] = false; |
| 44 ["key"] = { 0x20, 0x20, 0x20, 0x20, }; | 44 ["key"] = { 0x20, 0x20, 0x20, 0x20, }; |
| 45 }; | 45 }; |
| 46 ping = { | |
| 47 ["opcode"] = 0x9; | |
| 48 ["length"] = 4; | |
| 49 ["data"] = "ping"; | |
| 50 ["FIN"] = true; | |
| 51 ["MASK"] = false; | |
| 52 ["RSV1"] = false; | |
| 53 ["RSV2"] = false; | |
| 54 ["RSV3"] = false; | |
| 55 }; | |
| 56 pong = { | |
| 57 ["opcode"] = 0xa; | |
| 58 ["length"] = 4; | |
| 59 ["data"] = "pong"; | |
| 60 ["FIN"] = true; | |
| 61 ["MASK"] = false; | |
| 62 ["RSV1"] = false; | |
| 63 ["RSV2"] = false; | |
| 64 ["RSV3"] = false; | |
| 65 }; | |
| 46 } | 66 } |
| 47 | 67 |
| 48 describe("build", function () | 68 describe("build", function () |
| 49 local build = nwf.build; | 69 local build = nwf.build; |
| 50 it("works", function () | 70 it("works", function () |
| 51 assert.equal("\0\0", build(test_frames.simple_empty)); | 71 assert.equal("\0\0", build(test_frames.simple_empty)); |
| 52 assert.equal("\0\5hello", build(test_frames.simple_data)); | 72 assert.equal("\0\5hello", build(test_frames.simple_data)); |
| 53 assert.equal("\128\0", build(test_frames.simple_fin)); | 73 assert.equal("\128\0", build(test_frames.simple_fin)); |
| 54 assert.equal("\128\133 HELLO", build(test_frames.masked_data)); | 74 assert.equal("\128\133 HELLO", build(test_frames.masked_data)); |
| 75 assert.equal("\137\4ping", build(test_frames.ping)); | |
| 76 assert.equal("\138\4pong", build(test_frames.pong)); | |
| 55 end); | 77 end); |
| 56 end); | 78 end); |
| 57 | 79 |
| 58 describe("parse", function () | 80 describe("parse", function () |
| 59 local parse = nwf.parse; | 81 local parse = nwf.parse; |
| 60 it("works", function () | 82 it("works", function () |
| 61 assert.same(test_frames.simple_empty, parse("\0\0")); | 83 assert.same(test_frames.simple_empty, parse("\0\0")); |
| 62 assert.same(test_frames.simple_data, parse("\0\5hello")); | 84 assert.same(test_frames.simple_data, parse("\0\5hello")); |
| 63 assert.same(test_frames.simple_fin, parse("\128\0")); | 85 assert.same(test_frames.simple_fin, parse("\128\0")); |
| 64 assert.same(test_frames.masked_data, parse("\128\133 HELLO")); | 86 assert.same(test_frames.masked_data, parse("\128\133 HELLO")); |
| 87 assert.same(test_frames.ping, parse("\137\4ping")); | |
| 88 assert.same(test_frames.pong, parse("\138\4pong")); | |
| 65 end); | 89 end); |
| 66 end); | 90 end); |
| 67 | 91 |
| 68 end); | 92 end); |
| 69 | 93 |
