spec/scooter/httpdispatchers/orchestratordispatcher_spec.rb in scooter-4.3.2 vs spec/scooter/httpdispatchers/orchestratordispatcher_spec.rb in scooter-4.4.0
- old
+ new
@@ -2,16 +2,22 @@
describe Scooter::HttpDispatchers::OrchestratorDispatcher do
let(:orchestrator_api) { Scooter::HttpDispatchers::OrchestratorDispatcher.new(host) }
let(:job_id) { random_string }
+ let(:schedule_task_payload) {
+ { 'task' => 'foo' }
+ }
+ let(:schedule_plan_payload) {
+ { 'plan' => 'foo' }
+ }
let(:environment) {random_string}
let(:logger) { double('logger')}
- unixhost = { roles: ['test_role'],
- 'platform' => 'debian-7-x86_64' }
+ unixhost = { roles: ['test_role'],
+ 'platform' => 'debian-7-x86_64' }
let(:host) { Beaker::Host.create('test.com', unixhost, {:logger => logger}) }
subject { orchestrator_api }
before do
@@ -37,16 +43,28 @@
it { is_expected.to respond_to(:list_jobs).with(0).arguments }
it { is_expected.to respond_to(:list_jobs).with(1).arguments }
it { is_expected.not_to respond_to(:list_jobs).with(2).arguments }
- it 'should take a job_id' do
+ it 'should accept a max jobs argument' do
expect(orchestrator_api.connection).to receive(:get).with('v1/jobs')
- expect{ orchestrator_api.list_jobs }.not_to raise_error
+ expect{ orchestrator_api.list_jobs(1) }.not_to raise_error
end
end
+ describe '.list_plan_jobs' do
+
+ it { is_expected.to respond_to(:list_jobs).with(0).arguments }
+ it { is_expected.to respond_to(:list_jobs).with(1).arguments }
+ it { is_expected.not_to respond_to(:list_jobs).with(2).arguments }
+
+ it 'should take accept a max plan_jobs argument' do
+ expect(orchestrator_api.connection).to receive(:get).with('v1/plan_jobs')
+ expect{ orchestrator_api.list_plan_jobs(1) }.not_to raise_error
+ end
+ end
+
describe '.list_job_details' do
it { is_expected.not_to respond_to(:list_job_details).with(0).arguments }
it { is_expected.to respond_to(:list_job_details).with(1).arguments }
@@ -70,11 +88,10 @@
describe '.get_job_report' do
it { is_expected.not_to respond_to(:get_job_report).with(0).arguments }
it { is_expected.to respond_to(:get_job_report).with(1).arguments }
-
it 'should take a job_id' do
expect(orchestrator_api.connection).to receive(:get).with("v1/jobs/#{job_id}/report")
expect{ orchestrator_api.get_job_report(job_id) }.not_to raise_error
end
end
@@ -170,14 +187,19 @@
describe '.create_scheduled_job' do
it { is_expected.not_to respond_to(:create_scheduled_job).with(0).arguments }
it { is_expected.to respond_to(:create_scheduled_job).with(1).arguments }
it { is_expected.not_to respond_to(:create_scheduled_job).with(2).arguments }
- it 'should take a job id' do
+ it 'should schedule a task' do
expect(orchestrator_api.connection).to receive(:post).with("v1/command/schedule_task")
- expect{ orchestrator_api.create_scheduled_job(job_id) }.not_to raise_error
+ expect{ orchestrator_api.create_scheduled_job(schedule_task_payload) }.not_to raise_error
end
+
+ it 'should schedule a plan' do
+ expect(orchestrator_api.connection).to receive(:post).with("v1/command/schedule_plan")
+ expect{ orchestrator_api.create_scheduled_job(schedule_plan_payload) }.not_to raise_error
+ end
end
describe '.get_inventory' do
let(:certname) {'thisismycertname'}
@@ -227,16 +249,12 @@
it {is_expected.to respond_to(:get_last_jobs).with(2).arguments }
it {is_expected.to respond_to(:get_last_jobs).with(3).arguments }
it {is_expected.to respond_to(:get_last_jobs).with(4).arguments }
before do
- # find the index of the default Faraday::Adapter::NetHttp handler
- # and replace it with the Test adapter
- index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
- subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
- stub.get('/orchestrator/v1/jobs') { [200, {}] }
- end
+ stub_request(:get, /orchestrator\/v1\/jobs/).
+ to_return(status: 200, body: {}.to_json, headers: {"Content-Type"=> "application/json"})
end
it 'should make a request with query params' do
expect { subject.get_last_jobs(1, 3, 'name', 'asc') }.not_to raise_error
response = subject.get_last_jobs(1, 3, 'name', 'asc')
@@ -274,15 +292,11 @@
it {is_expected.to respond_to(:list_scheduled_jobs).with(0).arguments }
it {is_expected.to respond_to(:list_scheduled_jobs).with(1).arguments }
it {is_expected.to respond_to(:list_scheduled_jobs).with(2).arguments }
before do
- # find the index of the default Faraday::Adapter::NetHttp handler
- # and replace it with the Test adapter
- index = subject.connection.builder.handlers.index(Faraday::Adapter::NetHttp)
- subject.connection.builder.swap(index, Faraday::Adapter::Test) do |stub|
- stub.get('/orchestrator/v1/scheduled_jobs') { [200, {}] }
- end
+ stub_request(:get, /orchestrator\/v1\/scheduled_jobs/).
+ to_return(status: 200, body: {}.to_json, headers: {"Content-Type"=> "application/json"})
end
it 'should make a request with query params' do
expect { subject.list_scheduled_jobs(50, 100) }.not_to raise_error
response = subject.list_scheduled_jobs(50, 100)