Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aw committed Sep 6, 2013
1 parent 7d3b557 commit 1d3246e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions spec/statsd_spec.rb
Expand Up @@ -47,6 +47,11 @@ class Statsd
@statsd.port = nil @statsd.port = nil
@statsd.port.must_equal 8125 @statsd.port.must_equal 8125
end end

it "should allow an IPv6 address" do
@statsd.host = '::1'
@statsd.host.must_equal '::1'
end
end end


describe "#increment" do describe "#increment" do
Expand Down Expand Up @@ -371,6 +376,7 @@ class Statsd::SomeClass; end
describe Statsd do describe Statsd do
describe "with a real UDP socket" do describe "with a real UDP socket" do
it "should actually send stuff over the socket" do it "should actually send stuff over the socket" do
Thread.current[:statsd_socket] = nil
socket = UDPSocket.new socket = UDPSocket.new
host, port = 'localhost', 12345 host, port = 'localhost', 12345
socket.bind(host, port) socket.bind(host, port)
Expand All @@ -380,5 +386,29 @@ class Statsd::SomeClass; end
message = socket.recvfrom(16).first message = socket.recvfrom(16).first
message.must_equal 'foobar:1|c' message.must_equal 'foobar:1|c'
end 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
end if ENV['LIVE'] end if ENV['LIVE']

0 comments on commit 1d3246e

Please sign in to comment.