Skip to content

Commit

Permalink
Merge pull request #1245 from agrare/fix_vm_scan_support
Browse files Browse the repository at this point in the history
Add stub_supports/supports_not for VM Scan specs
  • Loading branch information
Fryguy authored Jan 5, 2024
2 parents 3e15b0c + 71f18ff commit d909619
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions spec/requests/vms_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# REST API Request Tests - /api/vms
#
describe "Vms API" do
include Spec::Support::SupportsHelper

let(:zone) { FactoryBot.create(:zone, :name => "api_zone") }
let(:ems) { FactoryBot.create(:ems_vmware, :zone => zone) }
let(:host) { FactoryBot.create(:host) }
Expand Down Expand Up @@ -1210,19 +1212,48 @@ def query_match_regexp(*tables)
it "scan a Vm" do
api_basic_authorize action_identifier(:vms, :scan)

stub_supports(vm, :smartstate_analysis)

post(vm_url, :params => gen_request(:scan))

expect_single_action_result(:success => true, :message => /Scanning/i, :href => api_vm_url(nil, vm), :task => true)
end

it "scan a Vm that doesn't support smartstate_analysis" do
api_basic_authorize action_identifier(:vms, :scan)

stub_supports_not(vm, :smartstate_analysis)

post(vm_url, :params => gen_request(:scan))

expect_bad_request(/Feature not available\/supported/)
end

it "scan multiple Vms" do
api_basic_authorize action_identifier(:vms, :scan)

stub_supports(vm1, :smartstate_analysis)
stub_supports(vm2, :smartstate_analysis)

post(api_vms_url, :params => gen_request(:scan, nil, vm1_url, vm2_url))

expect_multiple_action_result(2, :task => true)
expect_result_resources_to_include_hrefs("results", [api_vm_url(nil, vm1), api_vm_url(nil, vm2)])
end

it "scan multiple Vms where at least one doesn't support smartstate_analysis" do
api_basic_authorize action_identifier(:vms, :scan)

stub_supports(vm1, :smartstate_analysis)
stub_supports_not(vm_openstack, :smartstate_analysis)

post(api_vms_url, :params => gen_request(:scan, nil, vm1_url, vm_openstack_url))

expect(response).to have_http_status(:ok)

expect(response.parsed_body["results"].first["message"]).to match(/Scanning Vm id: #{vm1.id} name: '#{vm1.name}'/)
expect(response.parsed_body["results"].last["message"]).to match(/Feature not available\/supported/)
end
end

context "Vm add_event action" do
Expand Down

0 comments on commit d909619

Please sign in to comment.