-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #37415 - Add CLI support for repository verify checksum
- Loading branch information
Showing
5 changed files
with
187 additions
and
14 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
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
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
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,31 @@ | ||
require File.join(File.dirname(__FILE__), '../test_helper') | ||
|
||
describe 'verify checksum on a product' do | ||
include ForemanTaskHelpers | ||
|
||
before do | ||
@cmd = %w(product verify-checksum) | ||
end | ||
|
||
let(:sync_response) do | ||
{ | ||
'id' => '1', | ||
'state' => 'planned' | ||
} | ||
end | ||
|
||
it 'verifies products ' do | ||
params = [ | ||
'--ids=1' | ||
] | ||
|
||
ex = api_expects(:products_bulk_actions, :verify_checksum_products, 'verify checksum') | ||
.with_params('ids' => [1]) | ||
ex.returns(sync_response) | ||
|
||
expect_foreman_task('3') | ||
|
||
result = run_cmd(@cmd + params) | ||
assert_equal(HammerCLI::EX_OK, result.exit_code) | ||
end | ||
end |
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,105 @@ | ||
require_relative '../test_helper' | ||
require_relative '../organization/organization_helpers' | ||
require 'hammer_cli_katello/repository' | ||
module HammerCLIKatello | ||
describe Repository::VerifyChecksum do | ||
include OrganizationHelpers | ||
it 'allows minimal options' do | ||
api_expects(:repositories, :verify_checksum) do |p| | ||
p['id'] == 1 | ||
end | ||
run_cmd(%w(repository verify-checksum --id 1)) | ||
end | ||
|
||
describe 'resolves repository ID' do | ||
it 'by requiring product' do | ||
api_expects_no_call | ||
result = run_cmd(%w(repository verify-checksum --name repo1)) | ||
assert(result.err[/--product, --product-id is required/], 'Incorrect error message') | ||
end | ||
|
||
it 'by product ID' do | ||
ex = api_expects(:repositories, :index) do |p| | ||
p['name'] == 'repo1' && p['product_id'] == 3 | ||
end | ||
ex.returns(index_response([{'id' => 1}])) | ||
|
||
api_expects(:repositories, :verify_checksum) do |p| | ||
p['id'] == 1 | ||
end | ||
|
||
run_cmd(%w(repository verify-checksum --name repo1 --product-id 3)) | ||
end | ||
end | ||
|
||
describe 'resolves product ID' do | ||
it 'by requiring organization options' do | ||
api_expects_no_call | ||
result = run_cmd(%w(repository verify-checksum --name repo1 --product prod1)) | ||
assert(result.err[/--organization-id, --organization, --organization-label is required/], | ||
"Organization option requirements must be validated") | ||
end | ||
|
||
it 'by organization ID' do | ||
ex = api_expects(:products, :index) do |p| | ||
p['name'] == 'prod3' && p['organization_id'] == '5' | ||
end | ||
ex.returns(index_response([{'id' => 3}])) | ||
|
||
ex = api_expects(:repositories, :index) do |p| | ||
p['name'] == 'repo1' && p['product_id'] == 3 | ||
end | ||
ex.returns(index_response([{'id' => 1}])) | ||
|
||
api_expects(:repositories, :verify_checksum) do |p| | ||
p['id'] == 1 | ||
end | ||
|
||
run_cmd(%w(repository verify-checksum --name repo1 --product prod3 --organization-id 5 | ||
)) | ||
end | ||
|
||
it 'by organization name' do | ||
expect_organization_search('org5', 5) | ||
|
||
ex = api_expects(:products, :index) do |p| | ||
p['name'] == 'prod3' && p['organization_id'] == 5 | ||
end | ||
ex.returns(index_response([{'id' => 3}])) | ||
|
||
ex = api_expects(:repositories, :index) do |p| | ||
p['name'] == 'repo1' && p['product_id'] == 3 | ||
end | ||
ex.returns(index_response([{'id' => 1}])) | ||
|
||
api_expects(:repositories, :verify_checksum) do |p| | ||
p['id'] == 1 | ||
end | ||
|
||
run_cmd(%w(repository verify-checksum --name repo1 --product prod3 --organization org5 | ||
)) | ||
end | ||
|
||
it 'by organization label' do | ||
expect_organization_search('org5', 5, field: 'label') | ||
|
||
ex = api_expects(:products, :index) do |p| | ||
p['name'] == 'prod3' && p['organization_id'] == 5 | ||
end | ||
ex.returns(index_response([{'id' => 3}])) | ||
|
||
ex = api_expects(:repositories, :index) do |p| | ||
p['name'] == 'repo1' && p['product_id'] == 3 | ||
end | ||
ex.returns(index_response([{'id' => 1}])) | ||
|
||
api_expects(:repositories, :verify_checksum) do |p| | ||
p['id'] == 1 | ||
end | ||
|
||
run_cmd(%w(repository verify-checksum --name repo1 --product prod3 --organization-label org5 | ||
)) | ||
end | ||
end | ||
end | ||
end |