File: framer.rb

package info (click to toggle)
ruby-protocol-http2 0.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 472 kB
  • sloc: ruby: 3,627; makefile: 4
file content (53 lines) | stat: -rw-r--r-- 1,271 bytes parent folder | download
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
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2023-2024, by Samuel Williams.

require "protocol/http2/framer"

describe Protocol::HTTP2::Framer do
	let(:stream) {StringIO.new}
	let(:framer) {subject.new(stream)}
	
	with "#flush" do
		it "flushes the underlying stream" do
			expect(stream).to receive(:flush)
			framer.flush
		end
	end
	
	with "#closed?" do
		it "reports the status of the underlying stream" do
			expect(stream).to receive(:closed?).and_return(true)
			expect(framer).to be(:closed?)
		end
	end
	
	with "#read_connection_preface" do
		with "invalid preface" do
			let(:stream) {StringIO.new("Hello World!")}
			
			it "fails with a handshake error" do
				expect{framer.read_connection_preface}.to raise_exception(Protocol::HTTP2::HandshakeError)
			end
		end
		
		with "valid preface" do
			let(:stream) {StringIO.new(Protocol::HTTP2::CONNECTION_PREFACE)}
			
			it "reads the connection preface" do
				expect(framer.read_connection_preface).to be == Protocol::HTTP2::CONNECTION_PREFACE
			end
		end
	end
	
	with "#read_frame" do
		with "invalid frame" do
			let(:stream) {StringIO.new("!")}
			
			it "fails with a end-of-file error" do
				expect{framer.read_frame}.to raise_exception(EOFError)
			end
		end
	end
end