sanford-protocol 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +1 -1
- data/lib/sanford-protocol/{test/fake_socket.rb → fake_socket.rb} +4 -1
- data/lib/sanford-protocol/request.rb +2 -2
- data/lib/sanford-protocol/response_status.rb +2 -0
- data/lib/sanford-protocol/{test/helpers.rb → test_helpers.rb} +10 -8
- data/lib/sanford-protocol/version.rb +1 -1
- data/sanford-protocol.gemspec +2 -2
- data/test/helper.rb +3 -3
- data/test/unit/connection_tests.rb +2 -2
- data/test/unit/fake_socket_tests.rb +8 -7
- data/test/unit/msg_data_tests.rb +2 -1
- data/test/unit/request_tests.rb +16 -6
- data/test/unit/response_status_tests.rb +2 -2
- data/test/unit/response_tests.rb +6 -6
- data/test/unit/{protocol_tests.rb → sanford-protocol_tests.rb} +6 -5
- data/test/unit/test_helpers_tests.rb +7 -5
- metadata +24 -52
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA512:
|
3
|
+
metadata.gz: 68b7b525fe9392a33da58986ca25635e1f7a5d3b85c3693d91c997e590454926b3f4dafdae56ba312c14abb303d71ba63b5b2696daea971ec27e7974d40e72ef
|
4
|
+
data.tar.gz: 463b28ddbf3a33f4e337c632bcd041c3bcbfcdd16c9f2bf2a4acd217c02fdb7befb0d620311c322b01e6b46e9be54a17d7f4f23e93eff1dfda99d3ee00f85961
|
5
|
+
SHA1:
|
6
|
+
metadata.gz: a74f6081b63378c6751e542f72f1567a2bac8b7e
|
7
|
+
data.tar.gz: d6883452581ee91aa26edc5fc6cddaa1d7ef30e7
|
data/README.md
CHANGED
@@ -144,7 +144,7 @@ incoming_response = Sanford::Protocol::Response.parse(data_hash)
|
|
144
144
|
|
145
145
|
## Test Helpers
|
146
146
|
|
147
|
-
A `FakeSocket` helper class and an associated `
|
147
|
+
A `FakeSocket` helper class and an associated `TestHelpers` module are provided to help test receiving and sending Sanford::Protocol messages without using real sockets.
|
148
148
|
|
149
149
|
```ruby
|
150
150
|
# fake a socket with some incoming binary
|
@@ -5,7 +5,9 @@ require 'sanford-protocol/request'
|
|
5
5
|
# environment. Instead of passing a real socket, pass an instance of this class.
|
6
6
|
# It mimics the socket API that sanford is concerned with.
|
7
7
|
|
8
|
-
module Sanford
|
8
|
+
module Sanford; end
|
9
|
+
module Sanford::Protocol
|
10
|
+
|
9
11
|
class FakeSocket
|
10
12
|
|
11
13
|
def self.with_request(*request_params)
|
@@ -64,4 +66,5 @@ module Sanford::Protocol::Test
|
|
64
66
|
end
|
65
67
|
|
66
68
|
end
|
69
|
+
|
67
70
|
end
|
@@ -17,7 +17,7 @@ module Sanford::Protocol
|
|
17
17
|
|
18
18
|
def initialize(name, params)
|
19
19
|
self.validate!(name, params)
|
20
|
-
@name, @params = name, params
|
20
|
+
@name, @params = name.to_s, params
|
21
21
|
end
|
22
22
|
|
23
23
|
def to_hash
|
@@ -40,7 +40,7 @@ module Sanford::Protocol
|
|
40
40
|
def validate!(name, params)
|
41
41
|
problem = if !name
|
42
42
|
"The request doesn't contain a name."
|
43
|
-
elsif !params.kind_of?(Hash)
|
43
|
+
elsif !params.kind_of?(::Hash)
|
44
44
|
"The request's params are not a valid BSON document."
|
45
45
|
end
|
46
46
|
raise(BadRequestError, problem) if problem
|
@@ -1,25 +1,27 @@
|
|
1
|
-
require 'sanford-protocol/
|
1
|
+
require 'sanford-protocol/fake_socket'
|
2
|
+
require 'sanford-protocol/connection'
|
2
3
|
require 'sanford-protocol/response'
|
3
4
|
|
4
|
-
module
|
5
|
+
module Sandord; end
|
6
|
+
module Sanford::Protocol
|
5
7
|
|
6
|
-
module
|
8
|
+
module TestHelpers
|
7
9
|
extend self
|
8
10
|
|
9
11
|
def fake_socket_with_request(*args)
|
10
|
-
FakeSocket.with_request(*args)
|
12
|
+
Sanford::Protocol::FakeSocket.with_request(*args)
|
11
13
|
end
|
12
14
|
|
13
15
|
def fake_socket_with_msg_body(*args)
|
14
|
-
FakeSocket.with_msg_body(*args)
|
16
|
+
Sanford::Protocol::FakeSocket.with_msg_body(*args)
|
15
17
|
end
|
16
18
|
|
17
19
|
def fake_socket_with_encoded_msg_body(*args)
|
18
|
-
FakeSocket.with_encoded_msg_body(*args)
|
20
|
+
Sanford::Protocol::FakeSocket.with_encoded_msg_body(*args)
|
19
21
|
end
|
20
22
|
|
21
23
|
def fake_socket_with(*args)
|
22
|
-
FakeSocket.new(*args)
|
24
|
+
Sanford::Protocol::FakeSocket.new(*args)
|
23
25
|
end
|
24
26
|
|
25
27
|
def read_response_from_fake_socket(from_fake_socket)
|
@@ -28,7 +30,7 @@ module Sanford::Protocol::Test
|
|
28
30
|
end
|
29
31
|
|
30
32
|
def read_written_response_from_fake_socket(from_fake_socket)
|
31
|
-
read_response_from_fake_socket(FakeSocket.new(from_fake_socket.out))
|
33
|
+
read_response_from_fake_socket(Sanford::Protocol::FakeSocket.new(from_fake_socket.out))
|
32
34
|
end
|
33
35
|
|
34
36
|
end
|
data/sanford-protocol.gemspec
CHANGED
@@ -19,6 +19,6 @@ Gem::Specification.new do |gem|
|
|
19
19
|
|
20
20
|
gem.add_dependency("bson", ["~> 1.7"])
|
21
21
|
|
22
|
-
gem.add_development_dependency("assert", ["~> 2.
|
23
|
-
gem.add_development_dependency("assert-mocha", ["~> 1.
|
22
|
+
gem.add_development_dependency("assert", ["~> 2.10"])
|
23
|
+
gem.add_development_dependency("assert-mocha", ["~> 1.1"])
|
24
24
|
end
|
data/test/helper.rb
CHANGED
@@ -9,14 +9,14 @@ require 'pry'
|
|
9
9
|
|
10
10
|
ENV['SANFORD_PROTOCOL_DEBUG'] = 'yes'
|
11
11
|
|
12
|
-
require 'sanford-protocol/
|
13
|
-
FakeSocket = Sanford::Protocol::
|
12
|
+
require 'sanford-protocol/fake_socket'
|
13
|
+
FakeSocket = Sanford::Protocol::FakeSocket
|
14
14
|
|
15
15
|
require 'assert-mocha' if defined?(Assert)
|
16
16
|
|
17
17
|
class Assert::Context
|
18
18
|
|
19
|
-
def setup_some_msg_data(data=nil)
|
19
|
+
def setup_some_msg_data(data = nil)
|
20
20
|
@data = data || { 'something' => true }
|
21
21
|
@encoded_body = Sanford::Protocol.msg_body.encode(@data)
|
22
22
|
@encoded_size = Sanford::Protocol.msg_size.encode(@encoded_body.bytesize)
|
@@ -3,7 +3,7 @@ require 'sanford-protocol/connection'
|
|
3
3
|
|
4
4
|
class Sanford::Protocol::Connection
|
5
5
|
|
6
|
-
class
|
6
|
+
class UnitTests < Assert::Context
|
7
7
|
desc "Sanford::Protocol::Connection"
|
8
8
|
setup do
|
9
9
|
setup_some_msg_data
|
@@ -39,7 +39,7 @@ class Sanford::Protocol::Connection
|
|
39
39
|
|
40
40
|
end
|
41
41
|
|
42
|
-
class RealConnectionTests <
|
42
|
+
class RealConnectionTests < UnitTests
|
43
43
|
|
44
44
|
def start_server(options, &block)
|
45
45
|
begin
|
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'assert'
|
2
|
-
require 'sanford-protocol/
|
2
|
+
require 'sanford-protocol/fake_socket'
|
3
|
+
|
3
4
|
require 'sanford-protocol/request'
|
4
5
|
|
5
|
-
class Sanford::Protocol::
|
6
|
+
class Sanford::Protocol::FakeSocket
|
6
7
|
|
7
|
-
class
|
8
|
-
desc "
|
8
|
+
class UnitTests < Assert::Context
|
9
|
+
desc "Sanford::Protocol::FakeSocket"
|
9
10
|
setup do
|
10
11
|
@fs = FakeSocket.new
|
11
12
|
end
|
@@ -27,7 +28,7 @@ class Sanford::Protocol::Test::FakeSocket
|
|
27
28
|
|
28
29
|
end
|
29
30
|
|
30
|
-
class WithInDataTests <
|
31
|
+
class WithInDataTests < UnitTests
|
31
32
|
desc "created given some data"
|
32
33
|
setup do
|
33
34
|
@in_data = 'some in data'
|
@@ -51,7 +52,7 @@ class Sanford::Protocol::Test::FakeSocket
|
|
51
52
|
|
52
53
|
end
|
53
54
|
|
54
|
-
class EncodedMessageTests <
|
55
|
+
class EncodedMessageTests < UnitTests
|
55
56
|
desc "with encoded msg data"
|
56
57
|
setup do
|
57
58
|
setup_some_msg_data
|
@@ -69,7 +70,7 @@ class Sanford::Protocol::Test::FakeSocket
|
|
69
70
|
|
70
71
|
end
|
71
72
|
|
72
|
-
class RequestTests <
|
73
|
+
class RequestTests < UnitTests
|
73
74
|
desc "that is a request"
|
74
75
|
setup do
|
75
76
|
setup_some_request_data
|
data/test/unit/msg_data_tests.rb
CHANGED
data/test/unit/request_tests.rb
CHANGED
@@ -3,21 +3,31 @@ require 'sanford-protocol/request'
|
|
3
3
|
|
4
4
|
class Sanford::Protocol::Request
|
5
5
|
|
6
|
-
class
|
6
|
+
class UnitTests < Assert::Context
|
7
7
|
desc "Sanford::Protocol::Request"
|
8
8
|
setup do
|
9
9
|
@request = Sanford::Protocol::Request.new('some_service', { 'key' => 'value' })
|
10
10
|
end
|
11
11
|
subject{ @request }
|
12
12
|
|
13
|
-
should
|
14
|
-
should
|
13
|
+
should have_imeths :name, :params, :to_hash
|
14
|
+
should have_cmeths :parse
|
15
|
+
|
16
|
+
should "know its name and params" do
|
17
|
+
assert_equal 'some_service', subject.name
|
18
|
+
assert_equal({ 'key' => 'value' }, subject.params)
|
19
|
+
end
|
20
|
+
|
21
|
+
should "force string request names" do
|
22
|
+
request = Sanford::Protocol::Request.new(:symbol_service_name, {})
|
23
|
+
assert_equal 'symbol_service_name', request.name
|
24
|
+
end
|
15
25
|
|
16
26
|
should "return it's name with #to_s" do
|
17
27
|
assert_equal subject.name, subject.to_s
|
18
28
|
end
|
19
29
|
|
20
|
-
should "
|
30
|
+
should "parse requests given a body hash" do
|
21
31
|
# using BSON messages are hashes
|
22
32
|
hash = {
|
23
33
|
'name' => 'service_name',
|
@@ -33,7 +43,7 @@ class Sanford::Protocol::Request
|
|
33
43
|
should "return the request as a hash with stringified params with #to_hash" do
|
34
44
|
# using BSON, messages are hashes
|
35
45
|
request = Sanford::Protocol::Request.new('service', {
|
36
|
-
1
|
46
|
+
1 => 1,
|
37
47
|
:symbol => :symbol
|
38
48
|
})
|
39
49
|
expected = {
|
@@ -45,7 +55,7 @@ class Sanford::Protocol::Request
|
|
45
55
|
|
46
56
|
end
|
47
57
|
|
48
|
-
class ValidTests <
|
58
|
+
class ValidTests < UnitTests
|
49
59
|
|
50
60
|
should "not raise an exception with valid request args" do
|
51
61
|
assert_nothing_raised do
|
@@ -3,7 +3,7 @@ require 'sanford-protocol/response_status'
|
|
3
3
|
|
4
4
|
class Sanford::Protocol::ResponseStatus
|
5
5
|
|
6
|
-
class
|
6
|
+
class UnitTests < Assert::Context
|
7
7
|
desc "Sanford::Protocol::ResponseStatus"
|
8
8
|
setup do
|
9
9
|
@status = Sanford::Protocol::ResponseStatus.new(200, "OK")
|
@@ -11,7 +11,7 @@ class Sanford::Protocol::ResponseStatus
|
|
11
11
|
subject{ @status }
|
12
12
|
|
13
13
|
should have_readers :code_obj, :message
|
14
|
-
should
|
14
|
+
should have_imeths :code, :name, :to_i
|
15
15
|
|
16
16
|
should "know it's code name" do
|
17
17
|
named = Sanford::Protocol::ResponseStatus.new(200)
|
data/test/unit/response_tests.rb
CHANGED
@@ -3,15 +3,15 @@ require 'sanford-protocol/response'
|
|
3
3
|
|
4
4
|
class Sanford::Protocol::Response
|
5
5
|
|
6
|
-
class
|
6
|
+
class UnitTests < Assert::Context
|
7
7
|
desc "Sanford::Protocol::Response"
|
8
8
|
setup do
|
9
9
|
@response = Sanford::Protocol::Response.new([ 672, 'YAR!' ], { 'something' => true })
|
10
10
|
end
|
11
11
|
subject{ @response }
|
12
12
|
|
13
|
-
should
|
14
|
-
should
|
13
|
+
should have_imeths :status, :code, :data, :to_hash, :to_s
|
14
|
+
should have_cmeths :parse
|
15
15
|
|
16
16
|
should "return its status#code with #code" do
|
17
17
|
assert_equal subject.status.code, subject.code
|
@@ -49,7 +49,7 @@ class Sanford::Protocol::Response
|
|
49
49
|
|
50
50
|
# Somewhat of a system test, want to make sure if Response is passed some
|
51
51
|
# "fuzzy" args that it will build it's status object as expected
|
52
|
-
class StatusBuildingTests <
|
52
|
+
class StatusBuildingTests < UnitTests
|
53
53
|
|
54
54
|
should "build a status with it's code set, given an integer" do
|
55
55
|
response = Sanford::Protocol::Response.new(574)
|
@@ -75,8 +75,8 @@ class Sanford::Protocol::Response
|
|
75
75
|
should "build a status with a code and message set, when given both" do
|
76
76
|
response = Sanford::Protocol::Response.new([ 348, "my message" ])
|
77
77
|
|
78
|
-
assert_equal 348,
|
79
|
-
assert_equal "my message",
|
78
|
+
assert_equal 348, response.status.code
|
79
|
+
assert_equal "my message", response.status.message
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
@@ -1,16 +1,17 @@
|
|
1
|
+
require 'assert'
|
2
|
+
require 'sanford-protocol'
|
3
|
+
|
1
4
|
# These tests are intended to be brittle and make sure the protocol conforms to
|
2
5
|
# an expected spec. If any of these tests fail, you probably need to modify the
|
3
6
|
# protocol's version constant.
|
4
7
|
|
5
|
-
require 'assert'
|
6
|
-
require 'sanford-protocol'
|
7
|
-
|
8
8
|
module Sanford::Protocol
|
9
|
-
|
9
|
+
|
10
|
+
class UnitTests < Assert::Context
|
10
11
|
desc "Sanford::Protocol"
|
11
12
|
subject{ Sanford::Protocol }
|
12
13
|
|
13
|
-
should
|
14
|
+
should have_imeths :msg_version, :msg_size, :msg_body
|
14
15
|
|
15
16
|
should "define the protocol version" do
|
16
17
|
assert_equal 2, subject::VERSION
|
@@ -1,11 +1,13 @@
|
|
1
1
|
require 'assert'
|
2
|
-
require 'sanford-protocol/
|
2
|
+
require 'sanford-protocol/test_helpers'
|
3
3
|
|
4
|
-
|
4
|
+
require 'sanford-protocol/response'
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
module Sanford::Protocol::TestHelpers
|
7
|
+
|
8
|
+
class UnitTests < Assert::Context
|
9
|
+
desc "Sanford::Protocol::TestHelpers"
|
10
|
+
subject { Sanford::Protocol::TestHelpers }
|
9
11
|
|
10
12
|
should have_imeths :fake_socket_with_request, :fake_socket_with_msg_body
|
11
13
|
should have_imeths :fake_socket_with_encoded_msg_body, :fake_socket_with
|
metadata
CHANGED
@@ -1,13 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sanford-protocol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 6
|
9
|
-
- 0
|
10
|
-
version: 0.6.0
|
4
|
+
version: 0.7.0
|
11
5
|
platform: ruby
|
12
6
|
authors:
|
13
7
|
- Collin Redding
|
@@ -16,53 +10,38 @@ autorequire:
|
|
16
10
|
bindir: bin
|
17
11
|
cert_chain: []
|
18
12
|
|
19
|
-
date:
|
13
|
+
date: 2014-06-06 00:00:00 Z
|
20
14
|
dependencies:
|
21
15
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
23
|
-
none: false
|
16
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
17
|
requirements:
|
25
18
|
- - ~>
|
26
19
|
- !ruby/object:Gem::Version
|
27
|
-
hash: 1
|
28
|
-
segments:
|
29
|
-
- 1
|
30
|
-
- 7
|
31
20
|
version: "1.7"
|
32
21
|
type: :runtime
|
33
|
-
|
34
|
-
prerelease: false
|
22
|
+
version_requirements: *id001
|
35
23
|
name: bson
|
24
|
+
prerelease: false
|
36
25
|
- !ruby/object:Gem::Dependency
|
37
|
-
|
38
|
-
none: false
|
26
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
27
|
requirements:
|
40
28
|
- - ~>
|
41
29
|
- !ruby/object:Gem::Version
|
42
|
-
|
43
|
-
segments:
|
44
|
-
- 2
|
45
|
-
- 3
|
46
|
-
version: "2.3"
|
30
|
+
version: "2.10"
|
47
31
|
type: :development
|
48
|
-
|
49
|
-
prerelease: false
|
32
|
+
version_requirements: *id002
|
50
33
|
name: assert
|
34
|
+
prerelease: false
|
51
35
|
- !ruby/object:Gem::Dependency
|
52
|
-
|
53
|
-
none: false
|
36
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
37
|
requirements:
|
55
38
|
- - ~>
|
56
39
|
- !ruby/object:Gem::Version
|
57
|
-
|
58
|
-
segments:
|
59
|
-
- 1
|
60
|
-
- 0
|
61
|
-
version: "1.0"
|
40
|
+
version: "1.1"
|
62
41
|
type: :development
|
63
|
-
|
64
|
-
prerelease: false
|
42
|
+
version_requirements: *id003
|
65
43
|
name: assert-mocha
|
44
|
+
prerelease: false
|
66
45
|
description: Ruby implementation of the Sanford TCP communication protocol.
|
67
46
|
email:
|
68
47
|
- collin.redding@me.com
|
@@ -81,63 +60,56 @@ files:
|
|
81
60
|
- Rakefile
|
82
61
|
- lib/sanford-protocol.rb
|
83
62
|
- lib/sanford-protocol/connection.rb
|
63
|
+
- lib/sanford-protocol/fake_socket.rb
|
84
64
|
- lib/sanford-protocol/msg_data.rb
|
85
65
|
- lib/sanford-protocol/request.rb
|
86
66
|
- lib/sanford-protocol/response.rb
|
87
67
|
- lib/sanford-protocol/response_status.rb
|
88
|
-
- lib/sanford-protocol/
|
89
|
-
- lib/sanford-protocol/test/helpers.rb
|
68
|
+
- lib/sanford-protocol/test_helpers.rb
|
90
69
|
- lib/sanford-protocol/version.rb
|
91
70
|
- sanford-protocol.gemspec
|
92
71
|
- test/helper.rb
|
93
72
|
- test/unit/connection_tests.rb
|
94
73
|
- test/unit/fake_socket_tests.rb
|
95
74
|
- test/unit/msg_data_tests.rb
|
96
|
-
- test/unit/protocol_tests.rb
|
97
75
|
- test/unit/request_tests.rb
|
98
76
|
- test/unit/response_status_tests.rb
|
99
77
|
- test/unit/response_tests.rb
|
78
|
+
- test/unit/sanford-protocol_tests.rb
|
100
79
|
- test/unit/test_helpers_tests.rb
|
101
80
|
homepage: https://github.com/redding/sanford-protocol
|
102
81
|
licenses: []
|
103
82
|
|
83
|
+
metadata: {}
|
84
|
+
|
104
85
|
post_install_message:
|
105
86
|
rdoc_options: []
|
106
87
|
|
107
88
|
require_paths:
|
108
89
|
- lib
|
109
90
|
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
-
none: false
|
111
91
|
requirements:
|
112
|
-
-
|
92
|
+
- &id004
|
93
|
+
- ">="
|
113
94
|
- !ruby/object:Gem::Version
|
114
|
-
hash: 3
|
115
|
-
segments:
|
116
|
-
- 0
|
117
95
|
version: "0"
|
118
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
|
-
none: false
|
120
97
|
requirements:
|
121
|
-
-
|
122
|
-
- !ruby/object:Gem::Version
|
123
|
-
hash: 3
|
124
|
-
segments:
|
125
|
-
- 0
|
126
|
-
version: "0"
|
98
|
+
- *id004
|
127
99
|
requirements: []
|
128
100
|
|
129
101
|
rubyforge_project:
|
130
|
-
rubygems_version:
|
102
|
+
rubygems_version: 2.2.2
|
131
103
|
signing_key:
|
132
|
-
specification_version:
|
104
|
+
specification_version: 4
|
133
105
|
summary: Ruby implementation of the Sanford TCP communication protocol.
|
134
106
|
test_files:
|
135
107
|
- test/helper.rb
|
136
108
|
- test/unit/connection_tests.rb
|
137
109
|
- test/unit/fake_socket_tests.rb
|
138
110
|
- test/unit/msg_data_tests.rb
|
139
|
-
- test/unit/protocol_tests.rb
|
140
111
|
- test/unit/request_tests.rb
|
141
112
|
- test/unit/response_status_tests.rb
|
142
113
|
- test/unit/response_tests.rb
|
114
|
+
- test/unit/sanford-protocol_tests.rb
|
143
115
|
- test/unit/test_helpers_tests.rb
|