Sha256: 9d03c8c72b06b7ab42dc2abc697f721e2ea90f26a6f715847faad8ccef18e1f3

Contents?: true

Size: 1.68 KB

Versions: 11

Compression:

Stored size: 1.68 KB

Contents

require 'spec_helper'
require 'spec/support/test/resource_service'

describe 'Functional Socket Client' do
  before(:all) do
    load "protobuf/socket.rb"
    @options = OpenStruct.new(:host => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100)
    @runner = ::Protobuf::Rpc::SocketRunner.new(@options)
    @server_thread = Thread.new(@runner) { |runner| runner.run }
    Thread.pass until @runner.running?
  end

  after(:all) do
    @runner.stop
    @server_thread.join
  end

  it 'runs fine when required fields are set' do
    expect {
      client = ::Test::ResourceService.client

      client.find(:name => 'Test Name', :active => true) do |c|
        c.on_success do |succ|
          expect(succ.name).to eq("Test Name")
          expect(succ.status).to eq(::Test::StatusType::ENABLED)
        end

        c.on_failure do |err|
          raise err.inspect
        end
      end
    }.to_not raise_error
  end

  it 'calls the on_failure callback when a message is malformed' do
    error = nil
    request = ::Test::ResourceFindRequest.new(:active => true)
    client = ::Test::ResourceService.client

    client.find(request) do |c|
      c.on_success { raise "shouldn't pass"}
      c.on_failure {|e| error = e}
    end

    expect(error.message).to match(/name.*required/)
  end

  it 'calls the on_failure callback when the request type is wrong' do
    error = nil
    request = ::Test::Resource.new(:name => 'Test Name')
    client = ::Test::ResourceService.client

    client.find(request) do |c|
      c.on_success { raise "shouldn't pass"}
      c.on_failure {|e| error = e}
    end
    expect(error.message).to match(/expected request.*ResourceFindRequest.*Resource instead/i)
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
protobuf-3.3.6 spec/functional/socket_server_spec.rb
protobuf-3.3.5 spec/functional/socket_server_spec.rb
protobuf-3.3.4 spec/functional/socket_server_spec.rb
protobuf-3.3.3 spec/functional/socket_server_spec.rb
protobuf-3.3.2 spec/functional/socket_server_spec.rb
protobuf-3.3.1 spec/functional/socket_server_spec.rb
protobuf-3.3.0 spec/functional/socket_server_spec.rb
protobuf-3.2.1 spec/functional/socket_server_spec.rb
protobuf-3.2.0 spec/functional/socket_server_spec.rb
protobuf-3.1.0 spec/functional/socket_server_spec.rb
protobuf-3.0.5 spec/functional/socket_server_spec.rb