Skip to content

Commit

Permalink
Merge pull request #556 from uroesch/monitoring_with_name
Browse files Browse the repository at this point in the history
Adding with_name matcher to be_monitored_by
  • Loading branch information
mizzy committed Feb 27, 2016
2 parents f35cbcf + db9367c commit 75cb0f7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/serverspec/matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# service
require 'serverspec/matcher/be_enabled'
require 'serverspec/matcher/be_running'
require 'serverspec/matcher/be_monitored_by'

# user
require 'serverspec/matcher/belong_to_group'
Expand Down
17 changes: 17 additions & 0 deletions lib/serverspec/matcher/be_monitored_by.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
RSpec::Matchers.define :be_monitored_by do |monitor|
match do |service|
service.monitored_by?(monitor, @monitor_name)
end
description do
if @monitor_name
"be monitored by #{monitor} with name #{@monitor_name}"
else
"be monitored by #{monitor}"
end
end

chain :with_name do |name|
@monitor_name = (name ? name : nil)
end

end
6 changes: 4 additions & 2 deletions lib/serverspec/type/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ def running?(under)
end
end

def monitored_by?(monitor)
def monitored_by?(monitor, monitor_name)
check_method = "check_service_is_monitored_by_#{monitor}".to_sym
res = @runner.send(check_method, @name)
# use the with_name value if set instead of the service name
monitor_name = (monitor_name ? monitor_name : @name)
res = @runner.send(check_method, monitor_name)
end

def has_property?(property)
Expand Down
5 changes: 5 additions & 0 deletions spec/type/base/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
it { should be_monitored_by(:monit) }
end

describe service('tinc') do
let(:stdout) { "Process 'tinc-myvpn'\r\n status running\r\n monitoring status monitored" }
it { should be_monitored_by(:monit).with_name('tinc-myvpn') }
end

describe service('unicorn') do
it { should be_monitored_by(:god) }
end
Expand Down

0 comments on commit 75cb0f7

Please sign in to comment.