Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ Style/Documentation:

Metrics:
Enabled: false

FileName:
Enabled: false
1 change: 1 addition & 0 deletions sensu-plugins-trello.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.7'
spec.add_development_dependency 'rubocop', '~> 0.54'
spec.add_development_dependency 'webmock', '~> 3.3'
end
44 changes: 44 additions & 0 deletions test/check-trello-incidents_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require 'json'
require 'webmock/rspec'

require_relative './plugin_stub.rb'
require_relative '../bin/check-trello-incidents.rb'

describe CheckTrelloIncidents do
before(:each) do
@api = stub_request(
:get,
'https://api.trello.com//1/lists/abcde/cards/?key=12345&token=12345'
)

@check = CheckTrelloIncidents.new
@check.config[:api_key] = '12345'
@check.config[:api_token] = '12345'
@check.config[:list] = 'abcde'

allow(@check).to receive(:output)
end

it 'should run' do
@api.to_return(body: '[]', status: 200)

expect { @check.run }.to raise_error do |error|
expect(error).to be_a SystemExit
expect(error.status).to eq 0
end
expect(@check).to have_received(:output).with('No new incidents')
expect(@api).to have_been_requested
end

it 'should be critical if trello cards' do
cards = [{ id: '1a2b3c', name: 'foo' }, { id: '1x2y3z', name: 'bar' }]
@api.to_return(body: JSON.generate(cards), status: 200)

expect { @check.run }.to raise_error do |error|
expect(error).to be_a SystemExit
expect(error.status).to eq 2
end
expect(@check).to have_received(:output).with('foo; bar')
expect(@api).to have_been_requested
end
end
24 changes: 24 additions & 0 deletions test/plugin_stub.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
RSpec.configure do |c|
c.before { allow($stdout).to receive(:puts) }
c.before { allow($stderr).to receive(:puts) }

# XXX: Sensu plugins run in the context of an at_exit handler. This prevents
# XXX: code-under-test from being run at the end of the rspec suite.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robbl-as die ganze Veranstaltung hier ist Cargo-Code at its best. Ohne den Zirkus machen die Test-Runs komisches Zeug, aber ich hab nicht im Ansatz begriffen, was hier passiert. Das ist zum einen sowieso schlecht, zum anderen würde ich gern die Gelegenheit nutzen und lernen. Weißt du, was hier abgeht? Kannst du es mir erklären?

c.before(:each) do
Sensu::Plugin::CLI.class_eval do
# PluginStub
class PluginStub
def run; end

def ok(*); end

def warning(*); end

def critical(*); end

def unknown(*); end
end
class_variable_set(:@@autorun, PluginStub)
end
end
end