Skip to content
This repository has been archived by the owner on Jan 1, 2020. It is now read-only.

Commit

Permalink
[daemonize] add api tests for checks/check
Browse files Browse the repository at this point in the history
  • Loading branch information
portertech committed Dec 22, 2011
1 parent 234bd4b commit 07084db
Showing 1 changed file with 49 additions and 15 deletions.
64 changes: 49 additions & 15 deletions test/sensu_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,29 @@ def setup
Sensu::API.test(@options)
end

def test_get_events
EM.add_timer(1) do
http = EM::HttpRequest.new(@api + '/events').get
http.callback do
assert_equal(200, http.response_header.status)
events = JSON.parse(http.response)
assert(events.is_a?(Hash))
assert_block "Response didn't contain the test event" do
contains_test_event = false
events.each do |client, events|
if client == @settings.client.name
events.each do |check, event|
contains_test_event = true if check == 'test'
end
end
end
contains_test_event
end
done
end
end
end

def test_get_clients
EM.add_timer(1) do
http = EM::HttpRequest.new(@api + '/clients').get
Expand All @@ -29,24 +52,14 @@ def test_get_clients
end
end

def test_get_events
def test_get_checks
EM.add_timer(1) do
http = EM::HttpRequest.new(@api + '/events').get
http = EM::HttpRequest.new(@api + '/checks').get
http.callback do
assert_equal(200, http.response_header.status)
events = JSON.parse(http.response)
assert(events.is_a?(Hash))
assert_block "Response didn't contain the test event" do
contains_test_event = false
events.each do |client, events|
if client == @settings.client.name
events.each do |check, event|
contains_test_event = true if check == 'test'
end
end
end
contains_test_event
end
checks = JSON.parse(http.response)
assert(checks.is_a?(Hash))
assert_equal(checks, @settings.checks.to_hash)
done
end
end
Expand Down Expand Up @@ -149,6 +162,27 @@ def test_delete_nonexistent_client
end
end

def test_get_check
EM.add_timer(1) do
http = EM::HttpRequest.new(@api + '/check/a').get
http.callback do
assert_equal(200, http.response_header.status)
assert_equal(@settings.checks.a.to_hash, JSON.parse(http.response))
done
end
end
end

def test_get_nonexistent_check
EM.add_timer(1) do
http = EM::HttpRequest.new(@api + '/check/nonexistent').get
http.callback do
assert_equal(404, http.response_header.status)
done
end
end
end

def test_create_stash
EM.add_timer(1) do
options = {
Expand Down

0 comments on commit 07084db

Please sign in to comment.