go-mqtt 0.0.1

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.
@@ -0,0 +1,23 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ require 'spec_helper'
4
+ require 'mqtt'
5
+
6
+ describe MQTT do
7
+
8
+ describe "version number" do
9
+ it "should be defined as a constant" do
10
+ expect(defined?(MQTT::VERSION)).to eq('constant')
11
+ end
12
+
13
+ it "should be a string" do
14
+ expect(MQTT::VERSION).to be_a(String)
15
+ end
16
+
17
+ it "should be in the format x.y.z" do
18
+ expect(MQTT::VERSION).to match(/^\d{1,2}\.\d{1,2}\.\d{1,2}$/)
19
+ end
20
+
21
+ end
22
+
23
+ end
@@ -0,0 +1,177 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ require 'spec_helper'
4
+ require 'mqtt'
5
+ require 'fake_server'
6
+
7
+ describe "a client talking to a server" do
8
+
9
+ before(:each) do
10
+ @error_log = StringIO.new
11
+ @server = MQTT::FakeServer.new
12
+ @server.just_one_connection = true
13
+ @server.respond_to_pings = true
14
+ @server.logger = Logger.new(@error_log)
15
+ @server.logger.level = Logger::WARN
16
+ @server.start
17
+
18
+ @client = MQTT::Client.new(@server.address, @server.port)
19
+ end
20
+
21
+ after(:each) do
22
+ @client.disconnect
23
+ @server.stop
24
+ end
25
+
26
+ context "connecting and publishing a packet" do
27
+ def connect_and_publish(options = {})
28
+ @client.connect
29
+
30
+ retain = options.fetch(:retain) { false }
31
+ qos = options.fetch(:qos) { 0 }
32
+
33
+ @client.publish('test', 'foobar', retain, qos)
34
+ @client.disconnect
35
+ @server.thread.join(1)
36
+ end
37
+
38
+ it "the server should have received a packet" do
39
+ connect_and_publish
40
+ expect(@server.last_publish).not_to be_nil
41
+ end
42
+
43
+ it "the server should have received the correct topic" do
44
+ connect_and_publish
45
+ expect(@server.last_publish.topic).to eq('test')
46
+ end
47
+
48
+ it "the server should have received the correct payload" do
49
+ connect_and_publish
50
+ expect(@server.last_publish.payload).to eq('foobar')
51
+ end
52
+
53
+ it "the server should not report any errors" do
54
+ connect_and_publish
55
+ expect(@error_log.string).to be_empty
56
+ end
57
+
58
+ context "with qos > 0" do
59
+ it "the server should have received a packet without timeout" do
60
+ connect_and_publish(:qos => 1)
61
+ expect(@server.last_publish).not_to be_nil
62
+ end
63
+ end
64
+ end
65
+
66
+ context "connecting, subscribing to a topic and getting a message" do
67
+ def connect_and_subscribe
68
+ @client.connect
69
+ @client.subscribe('test')
70
+ @topic, @message = @client.get
71
+ @client.disconnect
72
+ end
73
+
74
+ it "the client should have received the right topic name" do
75
+ connect_and_subscribe
76
+ expect(@topic).to eq('test')
77
+ end
78
+
79
+ it "the client should have received the right message" do
80
+ connect_and_subscribe
81
+ expect(@message).to eq('hello test')
82
+ end
83
+
84
+ it "the server should not report any errors" do
85
+ connect_and_subscribe
86
+ expect(@error_log.string).to be_empty
87
+ end
88
+ end
89
+
90
+ context "connecting, subscribing to a topic and getting a packet" do
91
+ def connect_and_subscribe
92
+ @client.connect
93
+ @client.subscribe('test', 'foobar')
94
+ @packet = @client.get_packet
95
+ @client.disconnect
96
+ end
97
+
98
+ it "the client should have received a packet" do
99
+ connect_and_subscribe
100
+ expect(@packet).not_to be_nil
101
+ end
102
+
103
+ it "the client should have received the correct topic" do
104
+ connect_and_subscribe
105
+ expect(@packet.topic).to eq('test')
106
+ end
107
+
108
+ it "the client should have received the correct payload" do
109
+ connect_and_subscribe
110
+ expect(@packet.payload).to eq('hello test')
111
+ end
112
+
113
+ it "the client should have received a retained packet" do
114
+ connect_and_subscribe
115
+ expect(@packet.retain).to be_truthy
116
+ end
117
+
118
+ it "the server should not report any errors" do
119
+ connect_and_subscribe
120
+ expect(@error_log.string).to be_empty
121
+ end
122
+ end
123
+
124
+ context "sends pings when idle" do
125
+ def connect_and_ping(keep_alive)
126
+ @client.keep_alive = keep_alive
127
+ @client.connect
128
+ @server.thread.join(2)
129
+ @client.disconnect
130
+ end
131
+
132
+ context "when keep-alive=1" do
133
+ it "the server should have received at least one ping" do
134
+ connect_and_ping(1)
135
+ expect(@server.pings_received).to be >= 1
136
+ end
137
+
138
+ it "the server should not report any errors" do
139
+ connect_and_ping(1)
140
+ expect(@error_log.string).to be_empty
141
+ end
142
+ end
143
+
144
+ context "when keep-alive=0" do
145
+ it "the server should not receive any pings" do
146
+ connect_and_ping(0)
147
+ expect(@server.pings_received).to eq(0)
148
+ end
149
+
150
+ it "the server should not report any errors" do
151
+ connect_and_ping(0)
152
+ expect(@error_log.string).to be_empty
153
+ end
154
+ end
155
+ end
156
+
157
+ context "detects server not sending ping responses" do
158
+ def connect_and_timeout(keep_alive)
159
+ @server.respond_to_pings = false
160
+ @client.keep_alive = keep_alive
161
+ @client.connect
162
+ sleep(keep_alive * 3)
163
+ end
164
+
165
+ context "when keep-alive=1" do
166
+ it "the server should have received at least one ping" do
167
+ expect {
168
+ connect_and_timeout(1)
169
+ }.to raise_error(
170
+ MQTT::ProtocolException,
171
+ 'No Ping Response received for 2 seconds'
172
+ )
173
+ end
174
+ end
175
+ end
176
+
177
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: go-mqtt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Nicholas J Humfrey
8
+ - Ahmed Abdelhamid
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2025-05-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 1.11.2
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: 1.11.2
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 10.2.2
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: 10.2.2
42
+ - !ruby/object:Gem::Dependency
43
+ name: yard
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 0.9.11
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 0.9.11
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 3.5.0
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 3.5.0
70
+ - !ruby/object:Gem::Dependency
71
+ name: simplecov
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 0.9.2
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 0.9.2
84
+ - !ruby/object:Gem::Dependency
85
+ name: rubocop
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '1.45'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '1.45'
98
+ description: Pure Ruby gem that implements the MQTT protocol, a lightweight protocol
99
+ for publish/subscribe messaging.
100
+ email:
101
+ - njh@aelius.com
102
+ - ahmed.abdelhamid@illa.com.eg
103
+ executables: []
104
+ extensions: []
105
+ extra_rdoc_files: []
106
+ files:
107
+ - LICENSE.md
108
+ - NEWS.md
109
+ - README.md
110
+ - lib/mqtt.rb
111
+ - lib/mqtt/client.rb
112
+ - lib/mqtt/openssl_fix.rb
113
+ - lib/mqtt/packet.rb
114
+ - lib/mqtt/proxy.rb
115
+ - lib/mqtt/sn/packet.rb
116
+ - lib/mqtt/version.rb
117
+ - spec/mqtt_client_spec.rb
118
+ - spec/mqtt_packet_spec.rb
119
+ - spec/mqtt_proxy_spec.rb
120
+ - spec/mqtt_sn_packet_spec.rb
121
+ - spec/mqtt_version_spec.rb
122
+ - spec/zz_client_integration_spec.rb
123
+ homepage: https://github.com/go-illa/go-mqtt
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubygems_version: 3.5.19
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Implementation of the MQTT protocol
146
+ test_files:
147
+ - spec/mqtt_client_spec.rb
148
+ - spec/mqtt_packet_spec.rb
149
+ - spec/mqtt_proxy_spec.rb
150
+ - spec/mqtt_sn_packet_spec.rb
151
+ - spec/mqtt_version_spec.rb
152
+ - spec/zz_client_integration_spec.rb