forked from ManageIQ/manageiq-content
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR is based on on the issue below. ManageIQ/manageiq#12038
- Loading branch information
1 parent
2c1d828
commit 67e73c3
Showing
2 changed files
with
118 additions
and
9 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
76 changes: 76 additions & 0 deletions
76
...ontent/automate/ManageIQ/System/CommonMethods/QuotaMethods.class/__methods__/used_spec.rb
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,76 @@ | ||
require_domain_file | ||
|
||
describe ManageIQ::Automate::System::CommonMethods::QuotaMethods::Used do | ||
include Spec::Support::QuotaHelper | ||
|
||
let!(:model) { setup_model } | ||
let(:root_hash) do | ||
{ | ||
'miq_provision_request' => @miq_provision_request, | ||
'miq_request' => @miq_provision_request, | ||
'quota_source' => quota_source, | ||
'quota_source_type' => quota_source_type | ||
} | ||
end | ||
|
||
let(:counts_hash) do | ||
{:storage => 1_000_000, :cpu => 0, :vms => 4, :memory => 1_073_741_824} | ||
end | ||
|
||
let(:root_object) do | ||
Spec::Support::MiqAeMockObject.new(root_hash) | ||
end | ||
|
||
let(:ae_service) do | ||
Spec::Support::MiqAeMockService.new(root_object).tap do |service| | ||
current_object = Spec::Support::MiqAeMockObject.new | ||
current_object.parent = root_object | ||
service.object = current_object | ||
end | ||
end | ||
|
||
shared_examples_for "used" do | ||
it "check" do | ||
described_class.new(ae_service).main | ||
expect(ae_service.root['quota_used']).to include(counts_hash) | ||
end | ||
end | ||
|
||
context "returns ok for tenant counts" do | ||
let(:quota_source) { @tenant } | ||
let(:quota_source_type) { 'tenant' } | ||
let(:status_and_message) { [true, ""] } | ||
let(:ae_result) { "ok" } | ||
let(:errormsg) { 'ERROR - quota_source not found' } | ||
it_behaves_like "used" | ||
end | ||
|
||
context "returns ok for user counts" do | ||
let(:quota_source) { @tenant } | ||
let(:quota_source_type) { 'user' } | ||
let(:status_and_message) { [true, ""] } | ||
let(:ae_result) { "ok" } | ||
let(:errormsg) { 'ERROR - quota_source not found' } | ||
it_behaves_like "used" | ||
end | ||
|
||
context "returns ok for group counts" do | ||
let(:quota_source) { @tenant } | ||
let(:quota_source_type) { 'group' } | ||
let(:status_and_message) { [true, ""] } | ||
let(:ae_result) { "ok" } | ||
let(:errormsg) { 'ERROR - quota_source not found' } | ||
it_behaves_like "used" | ||
end | ||
|
||
context "returns error " do | ||
let(:quota_source_type) { nil } | ||
let(:quota_source) { nil } | ||
let(:status_and_message) { [true, ""] } | ||
let(:errormsg) { 'ERROR - quota_source not found' } | ||
it "when no quota source" do | ||
allow(ae_service).to receive(:used).and_return(status_and_message) | ||
expect { described_class.new(ae_service).main }.to raise_error(errormsg) | ||
end | ||
end | ||
end |