|
6 | 6 | describe Prometheus::Middleware::Exporter do
|
7 | 7 | include Rack::Test::Methods
|
8 | 8 |
|
| 9 | + let(:options) { { registry: registry } } |
9 | 10 | let(:registry) do
|
10 | 11 | Prometheus::Client::Registry.new
|
11 | 12 | end
|
12 | 13 |
|
13 | 14 | let(:app) do
|
14 | 15 | app = ->(_) { [200, { 'Content-Type' => 'text/html' }, ['OK']] }
|
15 |
| - described_class.new(app, registry: registry) |
| 16 | + described_class.new(app, **options) |
16 | 17 | end
|
17 | 18 |
|
18 | 19 | context 'when requesting app endpoints' do
|
|
96 | 97 |
|
97 | 98 | include_examples 'ok', { 'HTTP_ACCEPT' => accept }, text
|
98 | 99 | end
|
| 100 | + |
| 101 | + context 'when a port is specified' do |
| 102 | + let(:options) { { registry: registry, port: 9999 } } |
| 103 | + |
| 104 | + context 'when a request is on the specified port' do |
| 105 | + it 'responds with 200 OK' do |
| 106 | + registry.counter(:foo, docstring: 'foo counter').increment(by: 9) |
| 107 | + |
| 108 | + get 'http://example.org:9999/metrics', nil, {} |
| 109 | + |
| 110 | + expect(last_response.status).to eql(200) |
| 111 | + expect(last_response.header['Content-Type']).to eql(text::CONTENT_TYPE) |
| 112 | + expect(last_response.body).to eql(text.marshal(registry)) |
| 113 | + end |
| 114 | + end |
| 115 | + |
| 116 | + context 'when a request is not on the specified port' do |
| 117 | + it 'returns the app response' do |
| 118 | + get 'http://example.org:8888/metrics', nil, {} |
| 119 | + |
| 120 | + expect(last_response).to be_ok |
| 121 | + expect(last_response.body).to eql('OK') |
| 122 | + end |
| 123 | + end |
| 124 | + end |
99 | 125 | end
|
100 | 126 | end
|
0 commit comments