Skip to content

Commit

Permalink
test target_service_params from update service command
Browse files Browse the repository at this point in the history
  • Loading branch information
eguzki committed Oct 24, 2018
1 parent 3da7ae8 commit 933f89a
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 22 deletions.
18 changes: 18 additions & 0 deletions spec/shared_contexts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ def random_lowercase_name
end
end

RSpec.shared_context :source_service_data do
include_context :random_name

let(:source_service_params) do
%w[
name backend_version deployment_option description
system_name end_user_registration_required
support_email tech_support_email admin_support_email
]
end

let(:source_service_obj) do
source_service_params.each_with_object({}) do |key, target|
target[key] = random_lowercase_name
end
end
end

RSpec.shared_context :temp_dir do
around(:each) do |example|
Dir.mktmpdir('3scale_toolbox_rspec-') do |dir|
Expand Down
30 changes: 8 additions & 22 deletions spec/unit/copy_service_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require '3scale_toolbox/cli'

RSpec.describe ThreeScaleToolbox::Commands::CopyCommand::CopyServiceSubcommand do
include_context :random_name
include_context :source_service_data

context '#run' do
it 'with insecure flag' do
Expand Down Expand Up @@ -35,24 +35,10 @@
end

context '#copy_service_params' do
let(:params) do
%w[
name backend_version deployment_option description
system_name end_user_registration_required
support_email tech_support_email admin_support_email
]
end

let(:source_service_params) do
params.each_with_object({}) do |key, target|
target[key] = random_lowercase_name
end
end

it 'all expected params are copied' do
new_service_params = described_class.copy_service_params(source_service_params, nil)
new_service_params = described_class.copy_service_params(source_service_obj, nil)

expect(new_service_params).to include(*params)
expect(new_service_params).to include(*source_service_params)
end

it 'extra params are not copied' do
Expand All @@ -61,19 +47,19 @@
'some_other_weird_param' => 'value1'
}
new_service_params = described_class.copy_service_params(
source_service_params.merge(extra_params), nil
source_service_obj.merge(extra_params), nil
)
expect(new_service_params).to include(*params)
expect(new_service_params).to include(*source_service_params)
expect(new_service_params).not_to include(*extra_params)
end

it 'missing params are not copied' do
missing_params = %w[description backend_version]
missing_params.each do |key|
source_service_params.delete(key)
source_service_obj.delete(key)
end
new_service_params = described_class.copy_service_params(source_service_params, nil)
expect(new_service_params).to include(*source_service_params.keys)
new_service_params = described_class.copy_service_params(source_service_obj, nil)
expect(new_service_params).to include(*source_service_obj.keys)
expect(new_service_params).not_to include(*missing_params)
end
end
Expand Down
41 changes: 41 additions & 0 deletions spec/unit/update_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,44 @@
end
end
end

RSpec.describe ThreeScaleToolbox::Commands::UpdateCommand::UpdateServiceSubcommand::ServiceUpdater do
include_context :source_service_data

subject do
described_class.new(
'https://[email protected]',
'source_service_id',
'https://[email protected]',
'destination_service_id',
true
)
end

context '#target_service_params' do
it 'all expected params are copied' do
target_service_obj = subject.target_service_params(source_service_obj)
expect(target_service_obj).to include(*source_service_params)
end
it 'extra params are not copied' do
extra_params = {
'some_weird_param' => 'value0',
'some_other_weird_param' => 'value1'
}
target_service_obj = subject.target_service_params(
source_service_obj.merge(extra_params)
)
expect(target_service_obj).to include(*source_service_params)
expect(target_service_obj).not_to include(*extra_params)
end
it 'missing params are not copied' do
missing_params = %w[description backend_version]
missing_params.each do |key|
source_service_obj.delete(key)
end
target_service_obj = subject.target_service_params(source_service_obj)
expect(target_service_obj).to include(*source_service_obj.keys)
expect(target_service_obj).not_to include(*missing_params)
end
end
end

0 comments on commit 933f89a

Please sign in to comment.