Skip to content

Commit

Permalink
Raise ArgumentError in push.rb if job is nil
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Sinjakli <chris@sinjakli.co.uk>
  • Loading branch information
Sinjo committed Mar 27, 2021
1 parent 165b4c6 commit 100b55e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/prometheus/client/push.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class Push
attr_reader :job, :instance, :gateway, :path

def initialize(job, instance = nil, gateway = nil)
unless job
raise ArgumentError, "job cannot be nil"
end

@mutex = Mutex.new
@job = job
@instance = instance
Expand Down
6 changes: 6 additions & 0 deletions spec/prometheus/client/push_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
expect(push.gateway).to eql('http://pu.sh:1234')
end

it 'raises an ArgumentError if the job is not provided' do
expect do
Prometheus::Client::Push.new(nil)
end.to raise_error ArgumentError
end

it 'raises an ArgumentError if the given gateway URL is invalid' do
['inva.lid:1233', 'http://[invalid]'].each do |url|
expect do
Expand Down

0 comments on commit 100b55e

Please sign in to comment.