-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'webmock/rspec' | ||
require_relative '../../tasks/provision_service' | ||
|
||
describe 'provision::provision_service' do | ||
Check failure on line 7 in spec/tasks/provision_service_spec.rb GitHub Actions / spec (ruby 2.7) / spec
|
||
describe '.run' do | ||
context 'invalid inputs' do | ||
Check failure on line 9 in spec/tasks/provision_service_spec.rb GitHub Actions / spec (ruby 2.7) / spec
|
||
it 'with no action' do | ||
json_input = '{}' | ||
expect($stdin).to receive(:read).and_return(json_input) | ||
Check failure on line 12 in spec/tasks/provision_service_spec.rb GitHub Actions / spec (ruby 2.7) / spec
|
||
|
||
expect { ProvisionService.run }.to( | ||
raise_error(SystemExit) { |e| | ||
expect(e.status).to eq(0) | ||
}.and( | ||
output(%r{Unknown action}).to_stdout, | ||
), | ||
) | ||
end | ||
|
||
it 'with invalid action' do | ||
json_input = '{"action":"foo","platform":"bar"}' | ||
expect($stdin).to receive(:read).and_return(json_input) | ||
Check failure on line 25 in spec/tasks/provision_service_spec.rb GitHub Actions / spec (ruby 2.7) / spec
|
||
|
||
expect { ProvisionService.run }.to( | ||
raise_error(SystemExit) { |e| | ||
expect(e.status).to eq(0) | ||
}.and( | ||
output(%r{Unknown action 'foo'}).to_stdout, | ||
), | ||
) | ||
end | ||
|
||
it 'provision action without platform' do | ||
json_input = '{"action":"provision"}' | ||
expect($stdin).to receive(:read).and_return(json_input) | ||
Check failure on line 38 in spec/tasks/provision_service_spec.rb GitHub Actions / spec (ruby 2.7) / spec
|
||
|
||
expect { ProvisionService.run }.to( | ||
raise_error(SystemExit) { |e| | ||
expect(e.status).to eq(1) | ||
}.and( | ||
output(%r{specify a platform when provisioning}).to_stdout, | ||
), | ||
) | ||
end | ||
|
||
it 'tear_down action without node_name' do | ||
json_input = '{"action":"tear_down"}' | ||
expect($stdin).to receive(:read).and_return(json_input) | ||
Check failure on line 51 in spec/tasks/provision_service_spec.rb GitHub Actions / spec (ruby 2.7) / spec
|
||
|
||
expect { ProvisionService.run }.to( | ||
raise_error(SystemExit) { |e| | ||
expect(e.status).to eq(1) | ||
}.and( | ||
output(%r{specify a node_name when tearing down}).to_stdout, | ||
), | ||
) | ||
end | ||
end | ||
end | ||
|
||
describe '#provision' do | ||
let(:inventory_location) { "#{Dir.pwd}/litmus_inventory.yaml" } | ||
let(:vars) { nil } | ||
let(:platform) { 'centos-8' } | ||
let(:retry_attempts) { 8 } | ||
let(:response_body) do | ||
{ | ||
'groups' => [ | ||
'targets'=> { | ||
Check failure on line 72 in spec/tasks/provision_service_spec.rb GitHub Actions / spec (ruby 2.7) / spec
Check failure on line 72 in spec/tasks/provision_service_spec.rb GitHub Actions / spec (ruby 2.7) / spec
Check failure on line 72 in spec/tasks/provision_service_spec.rb GitHub Actions / spec (ruby 3.2) / spec
|
||
'uri' => '127.0.0.1' | ||
} | ||
Check failure on line 74 in spec/tasks/provision_service_spec.rb GitHub Actions / spec (ruby 2.7) / spec
|
||
] | ||
} | ||
end | ||
let(:provision_service) { ProvisionService.new } | ||
|
||
it 'action provision with the platform and return empty response' do | ||
stub_request(:post, "https://facade-release-6f3kfepqcq-ew.a.run.app/v1/provision"). | ||
Check failure on line 81 in spec/tasks/provision_service_spec.rb GitHub Actions / spec (ruby 2.7) / spec
|
||
with( | ||
body: "{\"url\":\"https://github.com/repos/puppetlabs/puppetlabs-iis/actions/runs/5575363758\",\"VMs\":[{\"cloud\":null,\"region\":null,\"zone\":null,\"images\":[\"centos-8\"]}]}", | ||
headers: { | ||
'Accept'=>'application/json', | ||
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', | ||
'Content-Type'=>'application/json', | ||
'Host'=>'facade-release-6f3kfepqcq-ew.a.run.app', | ||
'User-Agent'=>'Ruby' | ||
}). | ||
to_return(status: 200, body: "", headers: {}) | ||
expect { provision_service.provision(platform, inventory_location, vars, retry_attempts) }.to raise_error(NoMethodError) | ||
end | ||
|
||
it 'action provision with the platform and return valid response' do | ||
stub_request(:post, "https://facade-release-6f3kfepqcq-ew.a.run.app/v1/provision"). | ||
with( | ||
body: "{\"url\":\"https://github.com/repos/puppetlabs/puppetlabs-iis/actions/runs/5575363758\",\"VMs\":[{\"cloud\":null,\"region\":null,\"zone\":null,\"images\":[\"centos-8\"]}]}", | ||
headers: { | ||
'Accept'=>'application/json', | ||
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', | ||
'Content-Type'=>'application/json', | ||
'Host'=>'facade-release-6f3kfepqcq-ew.a.run.app', | ||
'User-Agent'=>'Ruby' | ||
}). | ||
to_return(status: 200, body: response_body.to_json, headers: {}) | ||
|
||
allow(File).to receive(:open) | ||
expect(provision_service.provision(platform, inventory_location, vars, retry_attempts)[:status]).to eq('ok') | ||
end | ||
end | ||
end |