Revision 70f06689
Added by Justin Sherrill about 10 years ago
test/actions/katello/repository_test.rb | ||
---|---|---|
|
||
require 'katello_test_helper'
|
||
|
||
module ::Actions::Katello::Repository
|
||
module Katello
|
||
|
||
class TestBase < ActiveSupport::TestCase
|
||
describe ::Actions::Katello::Repository do
|
||
include Dynflow::Testing
|
||
include Support::Actions::Fixtures
|
||
include FactoryGirl::Syntax::Methods
|
||
|
||
let(:action) { create_action action_class }
|
||
end
|
||
|
||
class CreateTest < TestBase
|
||
let(:action_class) { ::Actions::Katello::Repository::Create }
|
||
|
||
it 'plans' do
|
||
# TODO remove this mocking when action is broken down
|
||
cp = mock 'cp', update_cp_content: nil
|
||
organization = mock 'organization', default_content_view: cp, library: nil
|
||
product = mock 'product', organization: organization
|
||
repository = mock 'repository',
|
||
save!: true,
|
||
product: product,
|
||
generate_metadata: nil
|
||
|
||
action.expects(:action_subject).with(repository)
|
||
plan_action action, repository
|
||
end
|
||
end
|
||
describe "Create" do
|
||
let(:action_class) { ::Actions::Katello::Repository::Create }
|
||
|
||
class DestroyTest < TestBase
|
||
let(:action_class) { ::Actions::Katello::Repository::Destroy }
|
||
let(:repository) { build(:katello_repository, id: 123) }
|
||
|
||
it 'plans' do
|
||
repository = mock 'repository', destroy: true
|
||
action.stubs(:action_subject).with(repository)
|
||
plan_action action, repository
|
||
it 'plans' do
|
||
action = create_action action_class
|
||
repository.stubs(organization: build(:katello_organization))
|
||
repository.expects(:save!)
|
||
action.expects(:action_subject).with(repository)
|
||
action.execution_plan.stub_planned_action(::Actions::Katello::Product::ContentCreate) do |content_create|
|
||
content_create.stubs(input: { content_id: 123 })
|
||
end
|
||
plan_action action, repository
|
||
end
|
||
end
|
||
end
|
||
|
||
class DiscoverTest < TestBase
|
||
let(:action_class) { ::Actions::Katello::Repository::Discover }
|
||
let(:action_planned) { create_and_plan_action action_class, 'http://' }
|
||
|
||
it 'plans' do
|
||
assert_run_phase action_planned
|
||
describe 'Destroy' do
|
||
let(:action_class) { ::Actions::Katello::Repository::Destroy }
|
||
let(:pulp_action_class) { ::Actions::Pulp::Repository::Destroy }
|
||
|
||
it 'plans' do
|
||
repository = mock 'repository', pulp_id: 123, destroy: true
|
||
action = create_action action_class
|
||
action.stubs(:action_subject).with(repository)
|
||
plan_action action, repository
|
||
assert_action_planed_with action, pulp_action_class, pulp_id: 123
|
||
assert_action_planed_with action, ::Actions::Katello::Product::ContentDestroy, repository
|
||
end
|
||
end
|
||
|
||
it 'runs' do
|
||
::Katello::RepoDiscovery.
|
||
expects(:new).
|
||
returns(mock('discovery', run: nil))
|
||
describe 'Discover' do
|
||
let(:action_class) { ::Actions::Katello::Repository::Discover }
|
||
let(:action_planned) { create_and_plan_action action_class, url = 'http://' }
|
||
|
||
run_action action_planned
|
||
end
|
||
end
|
||
it 'plans' do
|
||
assert_run_phase action_planned
|
||
end
|
||
|
||
class SyncTest < TestBase
|
||
let(:action_class) { ::Actions::Katello::Repository::Sync }
|
||
let(:pulp_action_class) { ::Actions::Pulp::Repository::Sync }
|
||
it 'runs' do
|
||
::Katello::RepoDiscovery.
|
||
expects(:new).
|
||
returns(mock('discovery', run: nil))
|
||
|
||
let :action do
|
||
create_action(action_class).tap do |action|
|
||
action.stubs(planned_actions: [pulp_action])
|
||
run_action action_planned
|
||
end
|
||
end
|
||
let(:pulp_action) { fixture_action(pulp_action_class, output: fixture_variant) }
|
||
|
||
it 'plans' do
|
||
repository = mock 'repository', pulp_id: 'pulp-repo-1', id: 1
|
||
action = create_action action_class
|
||
action.stubs(:action_subject).with(repository)
|
||
plan_action action, repository
|
||
|
||
assert_action_planed_with action, pulp_action_class, pulp_id: 'pulp-repo-1'
|
||
assert_action_planed_with action, ::Actions::ElasticSearch::Repository::IndexContent, id: 1
|
||
assert_action_planed_with action, ::Actions::ElasticSearch::Reindex, repository
|
||
end
|
||
describe 'Sync' do
|
||
|
||
describe '#pulp_task_id' do
|
||
let(:fixture_variant) { :success }
|
||
let(:action_class) { ::Actions::Katello::Repository::Sync }
|
||
let(:pulp_action_class) { ::Actions::Pulp::Repository::Sync }
|
||
|
||
specify { action.pulp_task_id.must_equal "f723b378-b535-41a7-8440-8ab7851fda10" }
|
||
end
|
||
it 'plans' do
|
||
repository = mock 'repository', pulp_id: 'pulp-repo-1', id: 1
|
||
action = create_action action_class
|
||
action.stubs(:action_subject).with(repository)
|
||
plan_action action, repository
|
||
|
||
describe 'progress' do
|
||
describe 'successfully synchronized' do
|
||
let(:fixture_variant) { :success }
|
||
assert_action_planed_with action, pulp_action_class, pulp_id: 'pulp-repo-1'
|
||
assert_action_planed_with action, ::Actions::ElasticSearch::Repository::IndexContent, id: 1
|
||
assert_action_planed_with action, ::Actions::ElasticSearch::Reindex, repository
|
||
end
|
||
|
||
specify do
|
||
action.humanized_output.must_equal "New packages: 32 (76.7 KB)"
|
||
describe 'progress' do
|
||
let :action do
|
||
create_action(action_class).tap do |action|
|
||
action.stubs(planned_actions: [pulp_action])
|
||
end
|
||
end
|
||
end
|
||
|
||
describe 'successfully synchronized without new packages' do
|
||
let(:fixture_variant) { :success_no_packages }
|
||
let(:pulp_action) { fixture_action(pulp_action_class, output: fixture_variant) }
|
||
|
||
specify do
|
||
action.humanized_output.must_equal "No new packages"
|
||
describe 'successfully synchronized' do
|
||
let(:fixture_variant) { :success }
|
||
|
||
specify do
|
||
action.humanized_output.must_equal "New packages: 32 (76.7 KB)"
|
||
end
|
||
end
|
||
end
|
||
|
||
describe 'syncing packages in progress' do
|
||
let(:fixture_variant) { :progress_packages }
|
||
describe 'successfully synchronized without new packages' do
|
||
let(:fixture_variant) { :success_no_packages }
|
||
|
||
specify do
|
||
action.humanized_output.must_equal "New packages: 20/32 (48 KB/76.7 KB)"
|
||
specify do
|
||
action.humanized_output.must_equal "No new packages"
|
||
end
|
||
end
|
||
|
||
specify do
|
||
pulp_action.run_progress.must_be_within_delta 0.6256
|
||
describe 'syncing packages in progress' do
|
||
let(:fixture_variant) { :progress_packages }
|
||
|
||
specify do
|
||
action.humanized_output.must_equal "New packages: 20/32 (48 KB/76.7 KB)"
|
||
end
|
||
|
||
specify do
|
||
pulp_action.run_progress.must_be_within_delta 0.6256
|
||
end
|
||
end
|
||
end
|
||
|
||
describe 'downloading metadata in progress' do
|
||
let(:fixture_variant) { :progress_metadata }
|
||
describe 'downloading metadata in progress' do
|
||
let(:fixture_variant) { :progress_metadata }
|
||
|
||
specify do
|
||
action.humanized_output.must_equal "Processing metadata"
|
||
specify do
|
||
action.humanized_output.must_equal "Processing metadata"
|
||
end
|
||
end
|
||
end
|
||
end
|
Also available in: Unified diff
fixing errors from merge from cv-rework