Skip to content

Commit

Permalink
Fixes #34879 - Support mocha 2.1 (#618)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofedoren authored Aug 7, 2023
1 parent 4b733ad commit c4e4247
Show file tree
Hide file tree
Showing 48 changed files with 438 additions and 440 deletions.
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ group :test do
gem 'rake'
gem 'thor'
gem 'minitest', '~> 5.18'
gem 'minitest-spec-context'
gem 'simplecov'
gem 'mocha', "< 1.14.0"
gem 'mocha', "~> 2.1.0"
gem 'ci_reporter_minitest', "~> 1.0.0", :require => false

end
Expand Down
4 changes: 2 additions & 2 deletions test/functional/associating_commands_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'hammer_cli_foreman/operating_system'

describe HammerCLIForeman::OperatingSystem do
context 'AddProvisioningTemplateCommand' do
describe 'AddProvisioningTemplateCommand' do
before do
@cmd = ['os', 'add-provisioning-template']
@os_before_update = {
Expand Down Expand Up @@ -106,7 +106,7 @@

end

context 'RemoveProvisioningTemplateCommand' do
describe 'RemoveProvisioningTemplateCommand' do
before do
@cmd = ['os', 'remove-provisioning-template']
@os_before_update = {
Expand Down
8 changes: 4 additions & 4 deletions test/functional/commands/list_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def expect_paged_call(page, per_page, item_cnt, response_metadata={})
HammerCLI::Settings.clear
end

context 'help' do
describe 'help' do
let(:cmd) { ['host', 'list'] }
let(:params) { ['--help'] }

Expand All @@ -49,7 +49,7 @@ def expect_paged_call(page, per_page, item_cnt, response_metadata={})
end

describe "api interaction" do
context "without per_page in settings" do
describe "without per_page in settings" do
it "fetches only first page when there's not enough records" do
expect_paged_call(1, 1000, 10)
result = run_cmd([], {}, TestList)
Expand Down Expand Up @@ -86,7 +86,7 @@ def expect_paged_call(page, per_page, item_cnt, response_metadata={})
end
end

context "with per_page in settings" do
describe "with per_page in settings" do
let(:per_page_in_settings) { 30 }
before do
HammerCLI::Settings.load({ :ui => { :per_page => per_page_in_settings } })
Expand Down Expand Up @@ -139,7 +139,7 @@ def expect_paged_call(page, per_page, item_cnt, response_metadata={})
assert_cmd(expected_result, result)
end

context 'with per_page in settings' do
describe 'with per_page in settings' do
before do
HammerCLI::Settings.load({ :ui => { :per_page => '1' } })
end
Expand Down
8 changes: 4 additions & 4 deletions test/functional/report_template_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@

it 'invokes editor in interactive mode' do
params = ['--name=test', '--default=yes', "--interactive", '--locked=no', '--snippet=no']
HammerCLI.expects(:open_in_editor).with("", {:content_type => "report_template", :suffix => ".erb"}).returns('Template content')
HammerCLI.expects(:open_in_editor).with("", content_type: "report_template", suffix: ".erb").returns('Template content')
api_expects(:report_templates, :create, 'Create template').with_params(
'report_template' => {
'name' => 'test',
Expand Down Expand Up @@ -181,7 +181,7 @@
it 'invokes editor in interactive mode' do
params = ['--id=3', '--new-name=test', '--default=yes', "--interactive", '--locked=no', '--snippet=no']
HammerCLI.expects(:open_in_editor).with(
"Template Content", {:content_type => "report_template", :suffix => ".erb"}).returns('Template content')
"Template Content", content_type: "report_template", suffix: ".erb").returns('Template content')
api_expects(:report_templates, :show, 'Show').with_params('id' => '3').returns(third_report)
api_expects(:report_templates, :update, 'Update template').with_params(
'report_template' => {
Expand Down Expand Up @@ -307,7 +307,7 @@
{ 'job_id' => job_id, 'data_url' => "/report_data/#{job_id}" }
end

context 'without --wait' do
describe 'without --wait' do
it 'schedule report and prints out data for getting the result' do
params = ['--id=3', '--inputs=Host filter=filter']
api_expects(:report_templates, :schedule_report, 'Schedule').with_params(
Expand All @@ -320,7 +320,7 @@
end
end

context 'with --wait' do
describe 'with --wait' do
it 'generates the report to the file' do
params = ['--id=3', '--inputs=Host filter=filter', '--wait', '--path=/tmp']
api_expects(:report_templates, :schedule_report, 'Schedule').with_params(
Expand Down
8 changes: 4 additions & 4 deletions test/functional/virtual_machine_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

describe HammerCLIForeman::VirtualMachine do

context "InfoCommand" do
describe "InfoCommand" do
before do
@cmd = ["compute-resource", "virtual-machine", "info"]
@vm = {
Expand Down Expand Up @@ -43,7 +43,7 @@

end

context "ListCommand" do
describe "ListCommand" do
before do
@cmd = ["compute-resource", "virtual-machines"]
@available_virtual_machines = [
Expand All @@ -68,7 +68,7 @@
end
end

context "PowerCommand" do
describe "PowerCommand" do
before do
@cmd = ["compute-resource", "virtual-machine", "power"]
end
Expand Down Expand Up @@ -97,7 +97,7 @@
end
end

context "DeleteCommand" do
describe "DeleteCommand" do
before do
@cmd = ["compute-resource", "virtual-machine", "delete"]
end
Expand Down
1 change: 0 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

require 'minitest/autorun'
require 'minitest/spec'
require "minitest-spec-context"
require "mocha/minitest"

require 'hammer_cli'
Expand Down
4 changes: 2 additions & 2 deletions test/unit/api/interactive_basic_auth_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
let(:request) { mock() }
let(:args) { {} }

context "interactive mode" do
describe "interactive mode" do
before :each do
HammerCLI.stubs(:interactive?).returns true
end
Expand Down Expand Up @@ -42,7 +42,7 @@
end
end

context "non-interactive mode" do
describe "non-interactive mode" do
it "doesn't ask for credentials when they're not provided" do
HammerCLI.stubs(:interactive?).returns false
auth = HammerCLIForeman::Api::InteractiveBasicAuth.new(nil, nil)
Expand Down
4 changes: 2 additions & 2 deletions test/unit/api/oauth/oauth_authentication_code_grant_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require File.join(File.dirname(__FILE__), '../../test_helper')

describe HammerCLIForeman::Api::Oauth::AuthenticationCodeGrant do
let(:request) { mock().stubs({}) }
let(:request) { {} }
let(:args) { {} }
let(:params) {{
oidc_redirect_uri: 'urn:ietf:wg:oauth:2.0:oob',
Expand Down Expand Up @@ -33,7 +33,7 @@
end
end

context "interactive mode" do
describe "interactive mode" do
before :each do
HammerCLI.stubs(:interactive?).returns true
end
Expand Down
4 changes: 2 additions & 2 deletions test/unit/api/oauth/oauth_password_grant_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require File.join(File.dirname(__FILE__), '../../test_helper')

describe HammerCLIForeman::Api::Oauth::PasswordGrant do
let(:request) { mock().stubs({}) }
let(:request) { {} }
let(:args) { {} }
let(:params) {{
username: 'user1',
Expand Down Expand Up @@ -31,7 +31,7 @@
end
end

context "interactive mode" do
describe "interactive mode" do
before :each do
HammerCLI.stubs(:interactive?).returns true
end
Expand Down
12 changes: 6 additions & 6 deletions test/unit/api/session_authenticator_wrapper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def prepare_session_storage(options = {}, &block)
end

describe '#authenticate' do
context "when there's saved session" do
describe "when there's saved session" do
it 'sets session id in cookies for basic auth' do
session_params = {
session_id: 'SOME_SESSION_ID', auth_type: 'Basic_Auth'
Expand Down Expand Up @@ -139,7 +139,7 @@ def prepare_session_storage(options = {}, &block)
end
end

context "when the session file is corrupted" do
describe "when the session file is corrupted" do
it 'reports error' do
_dir, _out, err = prepare_session_storage :session_id => 'SOME_SESSION_ID' do |auth, dir|
write_session(dir, '{not a valid: json')
Expand All @@ -152,7 +152,7 @@ def prepare_session_storage(options = {}, &block)
end
end

context "when no session is saved" do
describe "when no session is saved" do
it 'passes to wrapped authenticator' do
prepare_session_storage do |auth, dir|
wrapped_auth.expects(:authenticate).with(request, args)
Expand All @@ -164,7 +164,7 @@ def prepare_session_storage(options = {}, &block)
end

describe '#error' do
context 'when there is existing session' do
describe 'when there is existing session' do
it 'sets session id to nil on unauthorized exception' do
prepare_session_storage :session_id => 'SOME_SESSION_ID' do |auth, dir|
ex = RestClient::Unauthorized.new
Expand Down Expand Up @@ -204,7 +204,7 @@ def prepare_session_storage(options = {}, &block)
end
end

context 'when user has changed' do
describe 'when user has changed' do
it 'sets a special error message' do
prepare_session_storage :session_id => 'SOME_SESSION_ID' do |auth, dir|
auth.force_user_change
Expand All @@ -227,7 +227,7 @@ def prepare_session_storage(options = {}, &block)
end
end

context 'when there is no existing session' do
describe 'when there is no existing session' do
it 'passes exception to wrapped authenticator on unauthorized exception' do
prepare_session_storage do |auth, dir|
ex = RestClient::Unauthorized.new
Expand Down
24 changes: 12 additions & 12 deletions test/unit/architecture_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@

include CommandTestHelper

context "ListCommand" do
describe "ListCommand" do
before do
ResourceMocks.mock_action_call(:architectures, :index, [])
end

let(:cmd) { HammerCLIForeman::Architecture::ListCommand.new("", ctx) }

context "parameters" do
describe "parameters" do
it_should_accept "no arguments"
it_should_accept_search_params
it_should_accept 'organization', ['--organization-id=1']
it_should_accept 'location', ['--location-id=1']
end

context "output" do
describe "output" do
let(:expected_record_count) { count_records(cmd.resource.call(:index)) }

it_should_print_n_records
Expand All @@ -32,19 +32,19 @@
end


context "InfoCommand" do
describe "InfoCommand" do

let(:cmd) { HammerCLIForeman::Architecture::InfoCommand.new("", ctx) }

context "parameters" do
describe "parameters" do
it_should_accept "id", ["--id=1"]
it_should_accept "name", ["--name=arch"]
it_should_accept 'organization', %w[--id=1 --organization-id=1]
it_should_accept 'location', %w[--id=1 --location-id=1]
# it_should_fail_with "no arguments" # TODO: temporarily disabled, parameters are checked in the id resolver
end

context "output" do
describe "output" do
with_params ["--id=1"] do
it_should_print_n_records 1
it_should_print_column "Name"
Expand All @@ -55,11 +55,11 @@
end


context "CreateCommand" do
describe "CreateCommand" do

let(:cmd) { HammerCLIForeman::Architecture::CreateCommand.new("", ctx) }

context "parameters" do
describe "parameters" do
it_should_accept "name", ["--name=arch"]
it_should_accept 'organization', %w[--name=arch --organization-id=1]
it_should_accept 'location', %w[--name=arch --location-id=1]
Expand All @@ -70,11 +70,11 @@
end


context "DeleteCommand" do
describe "DeleteCommand" do

let(:cmd) { HammerCLIForeman::Architecture::DeleteCommand.new("", ctx) }

context "parameters" do
describe "parameters" do
it_should_accept "name", ["--name=arch"]
it_should_accept "id", ["--id=1"]
it_should_accept 'organization', %w[--id=1 --organization-id=1]
Expand All @@ -85,11 +85,11 @@
end


context "UpdateCommand" do
describe "UpdateCommand" do

let(:cmd) { HammerCLIForeman::Architecture::UpdateCommand.new("", ctx) }

context "parameters" do
describe "parameters" do
it_should_accept "name", ["--name=arch", "--new-name=arch2"]
it_should_accept "id", ["--id=1", "--new-name=arch2"]
it_should_accept 'organization', %w[--id=1 --new-name=arch2 --organization-id=1]
Expand Down
12 changes: 6 additions & 6 deletions test/unit/audit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
describe HammerCLIForeman::Audit do
include CommandTestHelper

context "ListCommand" do
describe "ListCommand" do
before do
ResourceMocks.mock_action_call(:audits, :index, [])
end

let(:cmd) { HammerCLIForeman::Audit::ListCommand.new("", ctx) }

context "parameters" do
describe "parameters" do
it_should_accept "no arguments"
it_should_accept_search_params
end

context "output" do
describe "output" do
let(:expected_record_count) { count_records(cmd.resource.call(:index)) }

it_should_print_n_records
Expand All @@ -32,18 +32,18 @@
end
end

context "InfoCommand" do
describe "InfoCommand" do
before do
cmd.stubs(:extend_data)
end

let(:cmd) { HammerCLIForeman::Audit::InfoCommand.new("", ctx) }

context "parameters" do
describe "parameters" do
it_should_accept "id", ["--id=1"]
end

context "output" do
describe "output" do
with_params ["--id=1"] do
it_should_print_n_records 1
it_should_print_column "Id"
Expand Down
Loading

0 comments on commit c4e4247

Please sign in to comment.