Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix tests for snapshots and alerts.

  • Loading branch information...
commit a3ee9335997cea175bc6d0a30cb1626a1bef1fac 1 parent 2c8fe53
@mheffner mheffner authored
View
2  lib/librato-services/helpers/alert_helpers.rb
@@ -4,7 +4,7 @@ module Librato
module Services
module Helpers
module AlertHelpers
- def self.sample_payload
+ def self.sample_alert_payload
{
:alert => {
:id => 12345
View
19 lib/librato-services/helpers/snapshot_helpers.rb
@@ -0,0 +1,19 @@
+require 'tilt'
+
+module Librato
+ module Services
+ module Helpers
+ module SnapshotHelpers
+ def self.sample_snapshot_payload
+ {
+ :snapshot => {
+ :entity_name => "App API Requests",
+ :entity_url => "https://metrics.librato.com/instruments/1234?duration=3600",
+ :image_url => "http://snapshots.librato.com/instruments/12345abcd.png"
+ }
+ }.with_indifferent_access
+ end
+ end
+ end
+ end
+end
View
6 lib/librato-services/service.rb
@@ -1,3 +1,9 @@
+
+
+Dir[File.join(File.dirname(__FILE__), 'helpers/*helpers*')].each { |helper|
+ require helper
+}
+
require 'helpers/alert_helpers'
module Librato
View
13 test/campfire_test.rb
@@ -35,7 +35,7 @@ def find_room_by_name(name)
end
def test_alerts
- svc = service(:alert, {"token" => "t", "subdomain" => "s", "room" => "r"}.with_indifferent_access, payload)
+ svc = service(:alert, {"token" => "t", "subdomain" => "s", "room" => "r"}.with_indifferent_access, alert_payload)
svc.campfire = MockCampfire.new
svc.receive_alert
@@ -45,6 +45,17 @@ def test_alerts
#assert_equal 1, svc.campfire.rooms.first.pastes.size # logs
end
+ def test_snapshots
+ svc = service(:snapshot, {"token" => "t", "subdomain" => "s", "room" => "r"}.with_indifferent_access, snapshot_payload)
+ svc.campfire = MockCampfire.new
+ svc.receive_snapshot
+
+ assert_equal 1, svc.campfire.rooms.size
+ assert_equal 'r', svc.campfire.rooms.first.name
+ assert_equal 2, svc.campfire.rooms.first.lines.size # summary
+ #assert_equal 1, svc.campfire.rooms.first.pastes.size # logs
+ end
+
def service(*args)
super Service::Campfire, *args
end
View
8 test/helper.rb
@@ -33,8 +33,12 @@ def basic_auth(user, pass)
"Basic " + ["#{user}:#{pass}"].pack("m*").strip
end
- def payload
- Librato::Services::Helpers::AlertHelpers.sample_payload
+ def alert_payload
+ Librato::Services::Helpers::AlertHelpers.sample_alert_payload
+ end
+
+ def snapshot_payload
+ Librato::Services::Helpers::SnapshotHelpers.sample_snapshot_payload
end
end
View
22 test/hipchat_test.rb
@@ -18,7 +18,7 @@ def test_receive_validate
errors = {}
stub_message_call(@test_message, 200)
- service = service(:alert, @settings, payload)
+ service = service(:alert, @settings, alert_payload)
result = service.receive_validate(errors)
assert result
@@ -28,7 +28,7 @@ def test_receive_validate
def test_receive_validate_missing_arguments
errors = {}
opts = {}
- service = service(:alert, {}, payload)
+ service = service(:alert, {}, alert_payload)
result = service.receive_validate(errors)
assert !result
@@ -41,7 +41,7 @@ def test_receive_validate_missing_arguments
# message = URI.escape("Test message from Librato Hipchat integration")
# stub_message_call(@test_message, 401)
- # service = service(:alert, @settings, payload)
+ # service = service(:alert, @settings, alert_payload)
# result = service.receive_validate(errors)
# assert !result
@@ -53,7 +53,7 @@ def test_receive_validate_missing_arguments
# opts = {}
# stub_message_call(@test_message, 404)
- # service = service(:alert, @settings, payload)
+ # service = service(:alert, @settings, alert_payload)
# result = service.receive_validate(errors)
# assert !result
@@ -61,15 +61,25 @@ def test_receive_validate_missing_arguments
# end
def test_alert
- service = service(:alert, @settings, payload)
+ service = service(:alert, @settings, alert_payload)
stub_message_call(@test_message, 200)
- alert_message = service.generate_message(payload)
+ alert_message = service.alert_message
stub_message_call(alert_message, 200)
service.receive_alert
end
+ def test_snapshot
+ service = service(:snapshot, @settings, snapshot_payload)
+
+ stub_message_call(@test_message, 200)
+ snapshot_message = service.snapshot_message
+ stub_message_call(snapshot_message, 200)
+
+ service.receive_snapshot
+ end
+
def service(*args)
super Service::Hipchat, *args
end
View
14 test/mail_test.rb
@@ -6,18 +6,18 @@ def setup
end
def test_validations
- svc = service(:alert, { :addresses => 'fred@barn.com' }, payload)
+ svc = service(:alert, { :addresses => 'fred@barn.com' }, alert_payload)
errors = {}
assert(svc.receive_validate(errors))
assert_equal(0, errors.length)
- svc = service(:alert, {}, payload)
+ svc = service(:alert, {}, alert_payload)
errors = {}
assert(!svc.receive_validate(errors))
assert_equal(1, errors.length)
assert(errors[:addresses])
- svc = service(:alert, { :addresses => ['fred@barn.com'] }, payload)
+ svc = service(:alert, { :addresses => ['fred@barn.com'] }, alert_payload)
errors = {}
assert(!svc.receive_validate(errors))
assert_equal(1, errors.length)
@@ -25,7 +25,7 @@ def test_validations
end
def test_alert
- svc = service(:alert, { :addresses => 'fred@barn.com' }, payload)
+ svc = service(:alert, { :addresses => 'fred@barn.com' }, alert_payload)
svc.mail_message.perform_deliveries = false
@@ -33,7 +33,7 @@ def test_alert
end
def test_mail_message
- svc = service(:alert, { :addresses => 'fred@barn.com' }, payload)
+ svc = service(:alert, { :addresses => 'fred@barn.com' }, alert_payload)
message = svc.mail_message
@@ -41,7 +41,7 @@ def test_mail_message
end
def test_html
- svc = service(:alert, { }, payload)
+ svc = service(:alert, { }, alert_payload)
html = svc.html_email
@@ -49,7 +49,7 @@ def test_html
end
def test_text
- svc = service(:alert, { }, payload)
+ svc = service(:alert, { }, alert_payload)
text = svc.text_email
View
4 test/pagerduty_test.rb
@@ -13,7 +13,7 @@ def test_validations
0.upto(i) do |j|
opts[params.keys[j]] = params[params.keys[j]]
end
- svc = service(:alert, opts, payload)
+ svc = service(:alert, opts, alert_payload)
errors = {}
ret = svc.receive_validate(errors)
success = i == params.keys.length - 1
@@ -27,7 +27,7 @@ def test_alerts
:service_key => 'k',
:event_type => 't',
:description => 'd'
- }, payload)
+ }, alert_payload)
@stubs.post '/generic/2010-04-15/create_event.json' do |env|
[200, {}, '']
View
8 test/webhook_test.rb
@@ -6,18 +6,18 @@ def setup
end
def test_validations
- svc = service(:alert, {:url => "http://foobar.com/push"}, payload)
+ svc = service(:alert, {:url => "http://foobar.com/push"}, alert_payload)
errors = {}
assert(svc.receive_validate(errors))
assert_equal(0, errors.length)
- svc = service(:alert, {}, payload)
+ svc = service(:alert, {}, alert_payload)
errors = {}
assert(!svc.receive_validate(errors))
assert_equal(1, errors.length)
assert(!errors[:url].nil?)
- svc = service(:alert, {:url => "http://user@@foobar.com:/blah"}, payload)
+ svc = service(:alert, {:url => "http://user@@foobar.com:/blah"}, alert_payload)
errors = {}
assert(!svc.receive_validate(errors))
assert_equal(1, errors.length)
@@ -27,7 +27,7 @@ def test_validations
def test_alerts
path = "/post_path.json"
url = "http://localhost#{path}"
- svc = service(:alert, { :url => url }, payload)
+ svc = service(:alert, { :url => url }, alert_payload)
@stubs.post "#{path}" do |env|
[200, {}, '']
Please sign in to comment.
Something went wrong with that request. Please try again.