1 require File.dirname(__FILE__) + '/../spec_helper'
3 describe Backends::SwiftiplyClient do
5 @backend = Backends::SwiftiplyClient.new('0.0.0.0', 3333)
6 @backend.server = mock('server', :null_object => true)
16 it "should disconnect" do
25 describe SwiftiplyConnection do
27 @connection = SwiftiplyConnection.new(nil)
28 @connection.backend = Backends::SwiftiplyClient.new('0.0.0.0', 3333)
29 @connection.backend.server = mock('server', :null_object => true)
33 @connection.should be_persistent
36 it "should send handshake on connection_completed" do
37 @connection.should_receive(:send_data).with('swiftclient000000000d0500')
38 @connection.connection_completed
41 it "should reconnect on unbind" do
42 @connection.backend.stub!(:running?).and_return(true)
43 @connection.stub!(:rand).and_return(0) # Make sure we don't wait
45 @connection.should_receive(:reconnect).with('0.0.0.0', 3333)
49 EventMachine.add_timer(0) { EventMachine.stop }
53 it "should not reconnect when not running" do
54 @connection.backend.stub!(:running?).and_return(false)
55 EventMachine.should_not_receive(:add_timer)
59 it "should have a host_ip" do
60 @connection.send(:host_ip).should == [0, 0, 0, 0]
63 it "should generate swiftiply_handshake based on key" do
64 @connection.send(:swiftiply_handshake, 'key').should == 'swiftclient000000000d0503key'