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 68
|
# frozen_string_literal: true
# Released under the MIT License.
# Copyright, 2019-2024, by Samuel Williams.
require "protocol/http2/ping_frame"
require "protocol/http2/a_frame"
describe Protocol::HTTP2::PingFrame do
let(:data) {"PingPong"}
let(:frame) {subject.new}
it_behaves_like Protocol::HTTP2::AFrame do
def before
frame.pack data
super
end
end
it "applies to the connection" do
expect(frame).to be(:connection?)
end
with "#pack" do
it "packs data" do
frame.pack data
expect(frame.length).to be == 8
end
end
with "#unpack" do
it "unpacks data" do
frame.pack data
expect(frame.unpack).to be == data
end
end
with "#read_payload" do
let(:stream) {StringIO.new([0, 0, 0, 0, 0, 0, 0, 0].pack("C*"))}
with "invalid stream id" do
it "raises an error" do
frame.stream_id = 1
frame.length = 0
expect{frame.read_payload(stream)}.to raise_exception(
Protocol::HTTP2::ProtocolError,
message: be =~ /Settings apply to connection only, but stream_id was given/
)
end
end
with "a length other than 8" do
it "raises an error" do
frame.stream_id = 0
frame.length = 4
expect{frame.read_payload(stream)}.to raise_exception(
Protocol::HTTP2::FrameSizeError,
message: be =~ /Invalid frame length/
)
end
end
end
end
|