Browse files

Add tests

  • Loading branch information...
1 parent 7d3b557 commit 1d3246e8d3e6f94e37d73fe4428ab3e58bc91bcf @aw aw committed Sep 6, 2013
Showing with 30 additions and 0 deletions.
  1. +30 −0 spec/statsd_spec.rb
View
30 spec/statsd_spec.rb
@@ -47,6 +47,11 @@ class Statsd
@statsd.port = nil
@statsd.port.must_equal 8125
end
+
+ it "should allow an IPv6 address" do
+ @statsd.host = '::1'
+ @statsd.host.must_equal '::1'
+ end
end
describe "#increment" do
@@ -371,6 +376,7 @@ class Statsd::SomeClass; end
describe Statsd do
describe "with a real UDP socket" do
it "should actually send stuff over the socket" do
+ Thread.current[:statsd_socket] = nil
socket = UDPSocket.new
host, port = 'localhost', 12345
socket.bind(host, port)
@@ -380,5 +386,29 @@ class Statsd::SomeClass; end
message = socket.recvfrom(16).first
message.must_equal 'foobar:1|c'
end
+
+ it "should send stuff over an IPv4 socket" do
+ Thread.current[:statsd_socket] = nil
+ socket = UDPSocket.new Socket::AF_INET
+ host, port = '127.0.0.1', 12346
+ socket.bind(host, port)
+
+ statsd = Statsd.new(host, port)
+ statsd.increment('foobar')
+ message = socket.recvfrom(16).first
+ message.must_equal 'foobar:1|c'
+ end
+
+ it "should send stuff over an IPv6 socket" do
+ Thread.current[:statsd_socket] = nil
+ socket = UDPSocket.new Socket::AF_INET6
+ host, port = '::1', 12347
+ socket.bind(host, port)
+
+ statsd = Statsd.new(host, port)
+ statsd.increment('foobar')
+ message = socket.recvfrom(16).first
+ message.must_equal 'foobar:1|c'
+ end
end
end if ENV['LIVE']

0 comments on commit 1d3246e

Please sign in to comment.