-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test for check-marathon-task.rb
- Loading branch information
André Laszlo
committed
Jul 21, 2016
1 parent
7c3cc84
commit a2f0364
Showing
3 changed files
with
211 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
require_relative './spec_helper.rb' | ||
require_relative '../bin/check-marathon-task.rb' | ||
require_relative './fixtures.rb' | ||
|
||
# rubocop:disable Style/ClassVars | ||
class MarathonTaskCheck | ||
at_exit do | ||
@@autorun = false | ||
end | ||
|
||
def critical(*); end | ||
|
||
def warning(*); end | ||
|
||
def ok(*); end | ||
|
||
def unknown(*); end | ||
end | ||
|
||
def check_results(parameters) | ||
check = MarathonTaskCheck.new parameters.split(' ') | ||
check.check_tasks marathon_response | ||
end | ||
|
||
describe 'MarathonTaskCheck' do | ||
before do | ||
@default_parameters = '--server localhost --task foo/bar --instances 1' | ||
@check = MarathonTaskCheck.new @default_parameters.split(' ') | ||
end | ||
|
||
describe '#run' do | ||
it 'tests that a single running task is ok' do | ||
tasks_ok, unhealthy = check_results @default_parameters | ||
expect(tasks_ok).to be 1 | ||
expect(unhealthy).to be == [] | ||
end | ||
|
||
it 'counts tasks correctly' do | ||
tasks_running, unhealthy = check_results '--server s --task non/existing --instances 1' | ||
expect(tasks_running).to be 0 | ||
expect(unhealthy).to be == [] | ||
end | ||
|
||
it 'does not count unhealthy tasks' do | ||
tasks_running, unhealthy = check_results '--server s --task broken/app --instances 1' | ||
expect(tasks_running).to be 2 | ||
expect(unhealthy.count).to eq 2 | ||
end | ||
|
||
it 'tests that an empty server response raises an error' do | ||
expect { @check.check_tasks '{}' }.to raise_error(/No tasks/) | ||
expect { @check.check_tasks '' }.to raise_error(/Could not parse JSON/) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
def marathon_response | ||
<<-EOF | ||
{ | ||
"tasks": [ | ||
{ | ||
"healthCheckResults": [ | ||
{ | ||
"taskId": "foo_bar.0", | ||
"lastFailureCause": null, | ||
"lastSuccess": "2016-07-14T15:27:48.286Z", | ||
"lastFailure": null, | ||
"firstSuccess": "2016-07-14T14:10:57.583Z", | ||
"consecutiveFailures": 0, | ||
"alive": true | ||
} | ||
], | ||
"servicePorts": [ | ||
1234 | ||
], | ||
"appId": "/foo/bar", | ||
"ipAddresses": [ | ||
{ | ||
"protocol": "IPv4", | ||
"ipAddress": "123.123.123.123" | ||
} | ||
], | ||
"id": "foo_bar.0", | ||
"slaveId": "0-S0", | ||
"host": "host.example.com", | ||
"state": "TASK_RUNNING", | ||
"startedAt": "2016-07-14T14:09:43.350Z", | ||
"stagedAt": "2016-07-14T14:09:41.953Z", | ||
"ports": [ | ||
123450 | ||
], | ||
"version": "2016-07-14T14:09:41.270Z" | ||
}, | ||
{ | ||
"healthCheckResults": [ | ||
{ | ||
"taskId": "broken_app.0", | ||
"lastFailureCause": null, | ||
"lastSuccess": null, | ||
"lastFailure": null, | ||
"firstSuccess": null, | ||
"consecutiveFailures": 0, | ||
"alive": false | ||
}, | ||
{ | ||
"taskId": "broken_app.1", | ||
"lastFailureCause": null, | ||
"lastSuccess": "2016-07-14T15:27:48.286Z", | ||
"lastFailure": null, | ||
"firstSuccess": "2016-07-14T14:10:57.583Z", | ||
"consecutiveFailures": 0, | ||
"alive": true | ||
} | ||
], | ||
"servicePorts": [ | ||
1234 | ||
], | ||
"appId": "/broken/app", | ||
"ipAddresses": [ | ||
{ | ||
"protocol": "IPv4", | ||
"ipAddress": "123.123.123.123" | ||
} | ||
], | ||
"id": "broken_app.0", | ||
"slaveId": "0-S0", | ||
"host": "host.example.com", | ||
"state": "TASK_RUNNING", | ||
"startedAt": "2016-07-14T14:09:43.350Z", | ||
"stagedAt": "2016-07-14T14:09:41.953Z", | ||
"ports": [ | ||
123450 | ||
], | ||
"version": "2016-07-14T14:09:41.270Z" | ||
}, | ||
{ | ||
"healthCheckResults": [ | ||
{ | ||
"taskId": "broken_app.1", | ||
"lastFailureCause": "I broke", | ||
"lastSuccess": null, | ||
"lastFailure": "2016-07-14T14:09:41.270Z", | ||
"firstSuccess": null, | ||
"consecutiveFailures": 1, | ||
"alive": false | ||
} | ||
], | ||
"servicePorts": [ | ||
1234 | ||
], | ||
"appId": "/broken/app", | ||
"ipAddresses": [ | ||
{ | ||
"protocol": "IPv4", | ||
"ipAddress": "123.123.123.123" | ||
} | ||
], | ||
"id": "broken_app.0", | ||
"slaveId": "0-S0", | ||
"host": "host.example.com", | ||
"state": "TASK_RUNNING", | ||
"startedAt": "2016-07-14T14:09:43.350Z", | ||
"stagedAt": "2016-07-14T14:09:41.953Z", | ||
"ports": [ | ||
123450 | ||
], | ||
"version": "2016-07-14T14:09:41.270Z" | ||
} | ||
] | ||
} | ||
EOF | ||
end |