Skip to content

Commit 057b4c2

Browse files
Pawel Rutkowski (Work)Ruto8
authored andcommitted
Require the main prometheus_exporter module in client and server modules
The main module includes some consts and defaults, which both client and server require to work. In the README, it is suggested to treat client and server modules as entry-points, but without requiring the main module they won't work. In this commit, I'm adding a require and tests to show the problem.
1 parent 4bd3817 commit 057b4c2

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

lib/prometheus_exporter/client.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
require_relative "../prometheus_exporter"
34
require "socket"
45
require "logger"
56

lib/prometheus_exporter/server.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# frozen_string_literal: true
22

3+
require_relative "../prometheus_exporter"
34
require_relative "metric"
45
require_relative "server/type_collector"
56
require_relative "server/web_collector"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
# This test verifies that the client can be loaded independently
4+
# without requiring the main prometheus_exporter module first.
5+
#
6+
# DO NOT require test_helper here, as it pre-loads the main module.
7+
8+
require "minitest/autorun"
9+
10+
class ClientIndependentLoadingTest < Minitest::Test
11+
def test_client_has_constants_when_loaded_independently
12+
require_relative "../lib/prometheus_exporter/client"
13+
14+
assert_equal 9394, PrometheusExporter::DEFAULT_PORT
15+
assert_equal "localhost", PrometheusExporter::DEFAULT_BIND_ADDRESS
16+
assert_equal 2, PrometheusExporter::DEFAULT_TIMEOUT
17+
end
18+
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
# This test verifies that the server can be loaded independently
4+
# without requiring the main prometheus_exporter module first.
5+
#
6+
# DO NOT require test_helper here, as it pre-loads the main module.
7+
8+
require "minitest/autorun"
9+
10+
class ServerIndependentLoadingTest < Minitest::Test
11+
def test_server_has_constants_when_loaded_independently
12+
require_relative "../lib/prometheus_exporter/server"
13+
14+
assert_equal 9394, PrometheusExporter::DEFAULT_PORT
15+
assert_equal "localhost", PrometheusExporter::DEFAULT_BIND_ADDRESS
16+
assert_equal 2, PrometheusExporter::DEFAULT_TIMEOUT
17+
assert_equal "ruby_", PrometheusExporter::DEFAULT_PREFIX
18+
assert_equal "Prometheus Exporter", PrometheusExporter::DEFAULT_REALM
19+
end
20+
end

0 commit comments

Comments
 (0)