Skip to content

Commit

Permalink
Move test fixtures into proper namespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Jun 23, 2024
1 parent ee0a558 commit 4438b87
Show file tree
Hide file tree
Showing 20 changed files with 93 additions and 84 deletions.
17 changes: 0 additions & 17 deletions fixtures/connection_context.rb

This file was deleted.

30 changes: 0 additions & 30 deletions fixtures/frame_examples.rb

This file was deleted.

21 changes: 21 additions & 0 deletions fixtures/protocol/http2/connection_context.rb
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions fixtures/protocol/http2/frame_examples.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions test/protocol/http2/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
2 changes: 1 addition & 1 deletion test/protocol/http2/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions test/protocol/http2/continuation_frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions test/protocol/http2/data_frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!"

Expand Down
4 changes: 2 additions & 2 deletions test/protocol/http2/dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
4 changes: 2 additions & 2 deletions test/protocol/http2/goaway_frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions test/protocol/http2/headers_frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -103,7 +103,7 @@ def before
end

with "client/server connection" do
include_context ConnectionContext
include_context Protocol::HTTP2::ConnectionContext

def before
client.open!
Expand Down
4 changes: 2 additions & 2 deletions test/protocol/http2/ping_frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions test/protocol/http2/priority_frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions test/protocol/http2/push_promise_frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,7 +39,7 @@ def before
end

with "client/server connection" do
include_context ConnectionContext
include_context Protocol::HTTP2::ConnectionContext

def before
client.open!
Expand Down
4 changes: 2 additions & 2 deletions test/protocol/http2/reset_stream_frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions test/protocol/http2/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
4 changes: 2 additions & 2 deletions test/protocol/http2/settings_frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
# 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) {[
[3, 10], [5, 1048576], [4, 2147483647], [8, 1]
]}
let(:frame) {subject.new}

it_behaves_like FrameExamples do
it_behaves_like Protocol::HTTP2::AFrame do
def before
frame.pack settings

Expand Down
4 changes: 2 additions & 2 deletions test/protocol/http2/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
2 changes: 1 addition & 1 deletion test/protocol/http2/window.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
8 changes: 4 additions & 4 deletions test/protocol/http2/window_update_frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -52,7 +52,7 @@ def before
end

with 'a connection' do
include_context ConnectionContext
include_context Protocol::HTTP2::ConnectionContext

let(:framer) {client.framer}

Expand Down

0 comments on commit 4438b87

Please sign in to comment.