From 4438b87e49f33f459808f0e0b784876a8f12dfcb Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Sun, 23 Jun 2024 12:22:05 +0900 Subject: [PATCH] Move test fixtures into proper namespace. --- fixtures/connection_context.rb | 17 --------- fixtures/frame_examples.rb | 30 ---------------- fixtures/protocol/http2/connection_context.rb | 21 +++++++++++ fixtures/protocol/http2/frame_examples.rb | 35 +++++++++++++++++++ test/protocol/http2/client.rb | 4 +-- test/protocol/http2/connection.rb | 2 +- test/protocol/http2/continuation_frame.rb | 4 +-- test/protocol/http2/data_frame.rb | 4 +-- test/protocol/http2/dependency.rb | 4 +-- test/protocol/http2/goaway_frame.rb | 4 +-- test/protocol/http2/headers_frame.rb | 10 +++--- test/protocol/http2/ping_frame.rb | 4 +-- test/protocol/http2/priority_frame.rb | 4 +-- test/protocol/http2/push_promise_frame.rb | 8 ++--- test/protocol/http2/reset_stream_frame.rb | 4 +-- test/protocol/http2/server.rb | 4 +-- test/protocol/http2/settings_frame.rb | 4 +-- test/protocol/http2/stream.rb | 4 +-- test/protocol/http2/window.rb | 2 +- test/protocol/http2/window_update_frame.rb | 8 ++--- 20 files changed, 93 insertions(+), 84 deletions(-) delete mode 100644 fixtures/connection_context.rb delete mode 100644 fixtures/frame_examples.rb create mode 100644 fixtures/protocol/http2/connection_context.rb create mode 100644 fixtures/protocol/http2/frame_examples.rb diff --git a/fixtures/connection_context.rb b/fixtures/connection_context.rb deleted file mode 100644 index aa83e48..0000000 --- a/fixtures/connection_context.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -# Released under the MIT License. -# Copyright, 2019-2023, by Samuel Williams. - -require 'protocol/http2/client' -require 'protocol/http2/server' -require 'protocol/http2/stream' - -require 'socket' - -ConnectionContext = Sus::Shared("a connection") do - let(:sockets) {Socket.pair(Socket::PF_UNIX, Socket::SOCK_STREAM)} - - let(:client) {Protocol::HTTP2::Client.new(Protocol::HTTP2::Framer.new(sockets.first))} - let(:server) {Protocol::HTTP2::Server.new(Protocol::HTTP2::Framer.new(sockets.last))} -end diff --git a/fixtures/frame_examples.rb b/fixtures/frame_examples.rb deleted file mode 100644 index b40671c..0000000 --- a/fixtures/frame_examples.rb +++ /dev/null @@ -1,30 +0,0 @@ -# frozen_string_literal: true - -# Released under the MIT License. -# Copyright, 2019-2023, by Samuel Williams. - -require 'protocol/http2/framer' - -FrameExamples = Sus::Shared("a frame") do - let(:stream) {StringIO.new} - let(:frame) {subject.new} - - it "is a valid frame type" do - expect(frame).to be(:valid_type?) - end - - it "can write the frame" do - frame.write(stream) - - expect(stream.string).not.to be(:empty?) - end - - let(:framer) {Protocol::HTTP2::Framer.new(stream, {subject::TYPE => subject})} - - it "can read the frame using framer" do - frame.write(stream) - stream.seek(0) - - expect(framer.read_frame).to be == frame - end -end diff --git a/fixtures/protocol/http2/connection_context.rb b/fixtures/protocol/http2/connection_context.rb new file mode 100644 index 0000000..1768da7 --- /dev/null +++ b/fixtures/protocol/http2/connection_context.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +# Released under the MIT License. +# Copyright, 2019-2023, by Samuel Williams. + +require 'protocol/http2/client' +require 'protocol/http2/server' +require 'protocol/http2/stream' + +require 'socket' + +module Protocol + module HTTP2 + ConnectionContext = Sus::Shared("a connection") do + let(:sockets) {Socket.pair(Socket::PF_UNIX, Socket::SOCK_STREAM)} + + let(:client) {Protocol::HTTP2::Client.new(Protocol::HTTP2::Framer.new(sockets.first))} + let(:server) {Protocol::HTTP2::Server.new(Protocol::HTTP2::Framer.new(sockets.last))} + end + end +end diff --git a/fixtures/protocol/http2/frame_examples.rb b/fixtures/protocol/http2/frame_examples.rb new file mode 100644 index 0000000..a058ef8 --- /dev/null +++ b/fixtures/protocol/http2/frame_examples.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +# Released under the MIT License. +# Copyright, 2019-2023, by Samuel Williams. + +require 'protocol/http2/framer' + +module Protocol + module HTTP2 + AFrame = Sus::Shared("a frame") do + let(:pipe) {Socket.pair(:UNIX, :STREAM)} + let(:remote) {IO::Stream(pipe[0])} + let(:stream) {IO::Stream(pipe[1])} + + let(:framer) {Protocol::HTTP2::Framer.new(stream, {subject::TYPE => subject})} + + let(:frame) {subject.new} + + it "is a valid frame type" do + expect(frame).to be(:valid_type?) + end + + it "can write the frame" do + frame.write(stream) + + expect(stream.string).not.to be(:empty?) + end + + it "can read the frame using framer" do + frame.write(remote) + expect(framer.read_frame).to be == frame + end + end + end +end diff --git a/test/protocol/http2/client.rb b/test/protocol/http2/client.rb index 34cc5d3..1d46e50 100644 --- a/test/protocol/http2/client.rb +++ b/test/protocol/http2/client.rb @@ -3,10 +3,10 @@ # Released under the MIT License. # Copyright, 2019-2023, by Samuel Williams. -require 'connection_context' +require 'protocol/http2/connection_context' describe Protocol::HTTP2::Client do - include_context ConnectionContext + include_context Protocol::HTTP2::ConnectionContext let(:framer) {server.framer} diff --git a/test/protocol/http2/connection.rb b/test/protocol/http2/connection.rb index 4de8fd8..1c1cbbf 100644 --- a/test/protocol/http2/connection.rb +++ b/test/protocol/http2/connection.rb @@ -4,7 +4,7 @@ # Copyright, 2019-2024, by Samuel Williams. # Copyright, 2023, by Marco Concetto Rudilosso. -require 'connection_context' +require 'protocol/http2/connection_context' describe Protocol::HTTP2::Connection do let(:stream) {StringIO.new} diff --git a/test/protocol/http2/continuation_frame.rb b/test/protocol/http2/continuation_frame.rb index c7f4acf..c9cc346 100644 --- a/test/protocol/http2/continuation_frame.rb +++ b/test/protocol/http2/continuation_frame.rb @@ -4,13 +4,13 @@ # Copyright, 2019-2023, by Samuel Williams. require 'protocol/http2/continuation_frame' -require 'frame_examples' +require 'protocol/http2/a_frame' describe Protocol::HTTP2::ContinuationFrame do let(:data) {"Hello World!"} let(:frame) {subject.new} - it_behaves_like FrameExamples do + it_behaves_like Protocol::HTTP2::AFrame do def before frame.pack data diff --git a/test/protocol/http2/data_frame.rb b/test/protocol/http2/data_frame.rb index d17e792..d531b9a 100644 --- a/test/protocol/http2/data_frame.rb +++ b/test/protocol/http2/data_frame.rb @@ -4,12 +4,12 @@ # Copyright, 2019-2023, by Samuel Williams. require 'protocol/http2/data_frame' -require 'frame_examples' +require 'protocol/http2/a_frame' describe Protocol::HTTP2::DataFrame do let(:frame) {subject.new} - it_behaves_like FrameExamples do + it_behaves_like Protocol::HTTP2::AFrame do def before frame.pack "Hello World!" diff --git a/test/protocol/http2/dependency.rb b/test/protocol/http2/dependency.rb index 0e89dea..94e32a8 100644 --- a/test/protocol/http2/dependency.rb +++ b/test/protocol/http2/dependency.rb @@ -3,10 +3,10 @@ # Released under the MIT License. # Copyright, 2020-2023, by Samuel Williams. -require 'connection_context' +require 'protocol/http2/connection_context' describe Protocol::HTTP2::Stream do - include_context ConnectionContext + include_context Protocol::HTTP2::ConnectionContext def before client.open! diff --git a/test/protocol/http2/goaway_frame.rb b/test/protocol/http2/goaway_frame.rb index 99889ca..68e4b40 100644 --- a/test/protocol/http2/goaway_frame.rb +++ b/test/protocol/http2/goaway_frame.rb @@ -4,13 +4,13 @@ # Copyright, 2019-2024, by Samuel Williams. require 'protocol/http2/goaway_frame' -require 'frame_examples' +require 'protocol/http2/a_frame' describe Protocol::HTTP2::GoawayFrame do let(:data) {"Hikikomori desu!"} let(:frame) {subject.new} - it_behaves_like FrameExamples do + it_behaves_like Protocol::HTTP2::AFrame do def before frame.pack 1, 2, data diff --git a/test/protocol/http2/headers_frame.rb b/test/protocol/http2/headers_frame.rb index 5d947b6..401d0b9 100644 --- a/test/protocol/http2/headers_frame.rb +++ b/test/protocol/http2/headers_frame.rb @@ -5,15 +5,15 @@ require 'protocol/http2/headers_frame' -require 'connection_context' -require 'frame_examples' +require 'protocol/http2/connection_context' +require 'protocol/http2/a_frame' describe Protocol::HTTP2::HeadersFrame do let(:priority) {Protocol::HTTP2::Priority.new(true, 42, 7)} let(:data) {"Hello World!"} let(:frame) {subject.new} - it_behaves_like FrameExamples do + it_behaves_like Protocol::HTTP2::AFrame do def before frame.set_flags(Protocol::HTTP2::END_HEADERS) frame.pack priority, data @@ -47,7 +47,7 @@ def before end with '#continuation' do - let(:stream) {StringIO.new} + let(:stream) {IO::Stream(StringIO.new)} def before frame.pack nil, "Hello World", maximum_size: 8 @@ -103,7 +103,7 @@ def before end with "client/server connection" do - include_context ConnectionContext + include_context Protocol::HTTP2::ConnectionContext def before client.open! diff --git a/test/protocol/http2/ping_frame.rb b/test/protocol/http2/ping_frame.rb index 12027d1..d6d4699 100644 --- a/test/protocol/http2/ping_frame.rb +++ b/test/protocol/http2/ping_frame.rb @@ -4,13 +4,13 @@ # Copyright, 2019-2023, by Samuel Williams. require 'protocol/http2/ping_frame' -require 'frame_examples' +require 'protocol/http2/a_frame' describe Protocol::HTTP2::PingFrame do let(:data) {"PingPong"} let(:frame) {subject.new} - it_behaves_like FrameExamples do + it_behaves_like Protocol::HTTP2::AFrame do def before frame.pack data diff --git a/test/protocol/http2/priority_frame.rb b/test/protocol/http2/priority_frame.rb index 53f412d..e1eea8e 100644 --- a/test/protocol/http2/priority_frame.rb +++ b/test/protocol/http2/priority_frame.rb @@ -4,7 +4,7 @@ # Copyright, 2019-2023, by Samuel Williams. require 'protocol/http2/priority_frame' -require 'frame_examples' +require 'protocol/http2/a_frame' describe Protocol::HTTP2::Priority do let(:priority) {subject.new} @@ -45,7 +45,7 @@ let(:priority) {Protocol::HTTP2::Priority.new(true, 42, 7)} let(:frame) {subject.new} - it_behaves_like FrameExamples do + it_behaves_like Protocol::HTTP2::AFrame do def before frame.pack priority diff --git a/test/protocol/http2/push_promise_frame.rb b/test/protocol/http2/push_promise_frame.rb index 4049263..5303590 100644 --- a/test/protocol/http2/push_promise_frame.rb +++ b/test/protocol/http2/push_promise_frame.rb @@ -4,15 +4,15 @@ # Copyright, 2019-2023, by Samuel Williams. require 'protocol/http2/push_promise_frame' -require 'connection_context' -require 'frame_examples' +require 'protocol/http2/connection_context' +require 'protocol/http2/a_frame' describe Protocol::HTTP2::PushPromiseFrame do let(:stream_id) {5} let(:data) {"Hello World!"} let(:frame) {subject.new} - it_behaves_like FrameExamples do + it_behaves_like Protocol::HTTP2::AFrame do def before frame.set_flags(Protocol::HTTP2::END_HEADERS) frame.pack stream_id, data @@ -39,7 +39,7 @@ def before end with "client/server connection" do - include_context ConnectionContext + include_context Protocol::HTTP2::ConnectionContext def before client.open! diff --git a/test/protocol/http2/reset_stream_frame.rb b/test/protocol/http2/reset_stream_frame.rb index 820490b..86d9d18 100644 --- a/test/protocol/http2/reset_stream_frame.rb +++ b/test/protocol/http2/reset_stream_frame.rb @@ -4,13 +4,13 @@ # Copyright, 2019-2023, by Samuel Williams. require 'protocol/http2/reset_stream_frame' -require 'frame_examples' +require 'protocol/http2/a_frame' describe Protocol::HTTP2::ResetStreamFrame do let(:error) {Protocol::HTTP2::INTERNAL_ERROR} let(:frame) {subject.new} - it_behaves_like FrameExamples do + it_behaves_like Protocol::HTTP2::AFrame do def before frame.pack error diff --git a/test/protocol/http2/server.rb b/test/protocol/http2/server.rb index c9ab11f..31fcc9a 100644 --- a/test/protocol/http2/server.rb +++ b/test/protocol/http2/server.rb @@ -3,10 +3,10 @@ # Released under the MIT License. # Copyright, 2019-2024, by Samuel Williams. -require 'connection_context' +require 'protocol/http2/connection_context' describe Protocol::HTTP2::Client do - include_context ConnectionContext + include_context Protocol::HTTP2::ConnectionContext let(:framer) {client.framer} diff --git a/test/protocol/http2/settings_frame.rb b/test/protocol/http2/settings_frame.rb index e630fcf..7b4018f 100644 --- a/test/protocol/http2/settings_frame.rb +++ b/test/protocol/http2/settings_frame.rb @@ -4,7 +4,7 @@ # Copyright, 2019-2023, by Samuel Williams. require 'protocol/http2/settings_frame' -require 'frame_examples' +require 'protocol/http2/a_frame' describe Protocol::HTTP2::SettingsFrame do let(:settings) {[ @@ -12,7 +12,7 @@ ]} let(:frame) {subject.new} - it_behaves_like FrameExamples do + it_behaves_like Protocol::HTTP2::AFrame do def before frame.pack settings diff --git a/test/protocol/http2/stream.rb b/test/protocol/http2/stream.rb index 5fe9200..65b115a 100644 --- a/test/protocol/http2/stream.rb +++ b/test/protocol/http2/stream.rb @@ -3,10 +3,10 @@ # Released under the MIT License. # Copyright, 2019-2023, by Samuel Williams. -require 'connection_context' +require 'protocol/http2/connection_context' describe Protocol::HTTP2::Stream do - include_context ConnectionContext + include_context Protocol::HTTP2::ConnectionContext def before client.open! diff --git a/test/protocol/http2/window.rb b/test/protocol/http2/window.rb index 4456a9b..c1d0359 100644 --- a/test/protocol/http2/window.rb +++ b/test/protocol/http2/window.rb @@ -3,7 +3,7 @@ # Released under the MIT License. # Copyright, 2019-2023, by Samuel Williams. -require 'connection_context' +require 'protocol/http2/connection_context' describe Protocol::HTTP2::Window do let(:window) {subject.new} diff --git a/test/protocol/http2/window_update_frame.rb b/test/protocol/http2/window_update_frame.rb index a64c972..c48dfff 100644 --- a/test/protocol/http2/window_update_frame.rb +++ b/test/protocol/http2/window_update_frame.rb @@ -4,14 +4,14 @@ # Copyright, 2019-2023, by Samuel Williams. require 'protocol/http2/window_update_frame' -require 'connection_context' -require 'frame_examples' +require 'protocol/http2/connection_context' +require 'protocol/http2/a_frame' describe Protocol::HTTP2::WindowUpdateFrame do let(:window_size_increment) {1024} let(:frame) {subject.new} - it_behaves_like FrameExamples do + it_behaves_like Protocol::HTTP2::AFrame do def before frame.pack window_size_increment @@ -52,7 +52,7 @@ def before end with 'a connection' do - include_context ConnectionContext + include_context Protocol::HTTP2::ConnectionContext let(:framer) {client.framer}