File: instructions_fetcher_spec.rb

package info (click to toggle)
ruby-jaeger-client 1.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 624 kB
  • sloc: ruby: 3,381; makefile: 6; sh: 4
file content (34 lines) | stat: -rw-r--r-- 1,229 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require 'spec_helper'

RSpec.describe Jaeger::Samplers::RemoteControlled::InstructionsFetcher do
  let(:fetcher) { described_class.new(host: host, port: port, service_name: service_name) }
  let(:host) { 'some-host' }
  let(:port) { 1234 }
  let(:service_name) { 'test-service' }

  it 'returns parsed response on success' do
    body = { 'foo' => 'bar' }
    serialized_body = body.to_json

    stub_request(:get, "http://#{host}:#{port}/sampling?service=#{service_name}")
      .to_return(status: 200, body: serialized_body, headers: {})

    expect(fetcher.fetch).to eq(body)
  end

  it 'raises FetchFailed when http code is not 2xx' do
    stub_request(:get, "http://#{host}:#{port}/sampling?service=#{service_name}")
      .to_return(status: 400, body: 'Bad Request', headers: {})

    expect { fetcher.fetch }
      .to raise_error(described_class::FetchFailed, 'Unsuccessful response (code=400)')
  end

  it 'raises FetchFailed when request throws an exception' do
    stub_request(:get, "http://#{host}:#{port}/sampling?service=#{service_name}")
      .to_raise(StandardError.new('some error'))

    expect { fetcher.fetch }
      .to raise_error(described_class::FetchFailed, '#<StandardError: some error>')
  end
end