From 08389fd45ac51747a1b27d6edcd0891f2681b0ba Mon Sep 17 00:00:00 2001 From: Athishpranav2003 Date: Thu, 1 Aug 2024 19:02:51 +0530 Subject: [PATCH] Added UTs Signed-off-by: Athishpranav2003 --- spec/fluent/plugin/in_prometheus_spec.rb | 52 ++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/spec/fluent/plugin/in_prometheus_spec.rb b/spec/fluent/plugin/in_prometheus_spec.rb index 387ffe3..0e73b9b 100644 --- a/spec/fluent/plugin/in_prometheus_spec.rb +++ b/spec/fluent/plugin/in_prometheus_spec.rb @@ -45,6 +45,24 @@ expect(driver.instance.metrics_path).to eq('/_test') end end + + describe 'content_encoding_identity' do + let(:config) { CONFIG + %[ + content_encoding identity +] } + it 'should be configurable' do + expect(driver.instance.content_encoding).to eq(:identity) + end + end + + describe 'content_encoding_gzip' do + let(:config) { CONFIG + %[ + content_encoding gzip +] } + it 'should be configurable' do + expect(driver.instance.content_encoding).to eq(:gzip) + end + end end describe '#start' do @@ -197,6 +215,40 @@ end end end + + context 'response content_encoding identity' do + let(:config) { LOCAL_CONFIG + %[ + content_encoding identity + ] } + it 'exposes metric' do + driver.run(timeout: 1) do + registry = driver.instance.instance_variable_get(:@registry) + registry.counter(:test,docstring: "Testing metrics") unless registry.exist?(:test) + Net::HTTP.start("127.0.0.1", port) do |http| + req = Net::HTTP::Get.new("/metrics") + res = http.request(req) + expect(res.body).to include("test Testing metrics") + end + end + end + end + + context 'response content_encoding gzip' do + let(:config) { LOCAL_CONFIG + %[ + content_encoding gzip + ] } + it 'exposes metric' do + driver.run(timeout: 1) do + registry = driver.instance.instance_variable_get(:@registry) + registry.counter(:test,docstring: "Testing metrics") unless registry.exist?(:test) + Net::HTTP.start("127.0.0.1", port) do |http| + req = Net::HTTP::Get.new("/metrics") + res = http.request(req) + expect(res.body).to include("test Testing metrics") + end + end + end + end end describe '#run_multi_workers' do