Sha256: b3615d72cf041af3e5fa22967d08c4b1a255f76d603018b78f0f336ac9651d55

Contents?: true

Size: 1.39 KB

Versions: 8

Compression:

Stored size: 1.39 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), '../../../test_helper'))

require 'einhorn'

class InterfaceTest < Test::Unit::TestCase
  include Einhorn::Command

  context "when a command is received" do
    should "call that command" do
      conn = stub(:log_debug => nil)
      conn.expects(:write).once.with do |message|
        # Remove trailing newline
        message = message[0...-1]
        parsed = YAML.load(URI.unescape(message))
        parsed['message'] =~ /Welcome gdb/
      end
      request = {
        'command' => 'ehlo',
        'user' => 'gdb'
      }
      Interface.process_command(conn, YAML.dump(request))
    end
  end

  context "when an unrecognized command is received" do
    should "call the unrecognized_command method" do
      conn = stub(:log_debug => nil)
      Interface.expects(:unrecognized_command).once
      request = {
        'command' => 'made-up',
      }
      Interface.process_command(conn, YAML.dump(request))
    end
  end

  context "when a worker ack is received" do
    should "register ack and close the connection" do
      conn = stub(:log_debug => nil)
      conn.expects(:close).once
      conn.expects(:write).never
      request = {
        'command' => 'worker:ack',
        'pid' => 1234
      }
      Einhorn::Command.expects(:register_manual_ack).once.with(1234)
      Interface.process_command(conn, YAML.dump(request))
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
einhorn-0.4.7 test/unit/einhorn/command/interface.rb
einhorn-0.4.6 test/unit/einhorn/command/interface.rb
einhorn-0.4.5 test/unit/einhorn/command/interface.rb
einhorn-0.4.4 test/unit/einhorn/command/interface.rb
einhorn-0.4.3 test/unit/einhorn/command/interface.rb
einhorn-0.4.2 test/unit/einhorn/command/interface.rb
einhorn-0.4.1 test/unit/einhorn/command/interface.rb
einhorn-0.4.0 test/unit/einhorn/command/interface.rb