2019-09-04 21:01:54 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
require 'fast_spec_helper'
|
|
|
|
require 'rspec-parameterized'
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Gitlab::ImportExport::Config do
|
2019-09-04 21:01:54 +05:30
|
|
|
let(:yaml_file) { described_class.new }
|
|
|
|
|
|
|
|
describe '#to_h' do
|
2019-12-04 20:38:33 +05:30
|
|
|
subject { yaml_file.to_h }
|
|
|
|
|
|
|
|
context 'when using default config' do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
where(:ee) do
|
|
|
|
[true, false]
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
with_them do
|
|
|
|
before do
|
|
|
|
allow(Gitlab).to receive(:ee?) { ee }
|
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it 'parses default config' do
|
|
|
|
expect { subject }.not_to raise_error
|
|
|
|
expect(subject).to be_a(Hash)
|
|
|
|
expect(subject.keys).to contain_exactly(
|
2021-06-08 01:23:25 +05:30
|
|
|
:tree, :excluded_attributes, :included_attributes, :methods, :preloads, :export_reorders)
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
context 'when using custom config' do
|
|
|
|
let(:config) do
|
|
|
|
<<-EOF.strip_heredoc
|
|
|
|
tree:
|
|
|
|
project:
|
|
|
|
- labels:
|
|
|
|
- :priorities
|
|
|
|
- milestones:
|
|
|
|
- events:
|
|
|
|
- :push_event_payload
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
included_attributes:
|
|
|
|
user:
|
|
|
|
- :id
|
2019-09-04 21:01:54 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
excluded_attributes:
|
|
|
|
project:
|
|
|
|
- :name
|
|
|
|
|
|
|
|
methods:
|
|
|
|
labels:
|
|
|
|
- :type
|
|
|
|
events:
|
|
|
|
- :action
|
|
|
|
|
|
|
|
preloads:
|
|
|
|
statuses:
|
|
|
|
project:
|
|
|
|
|
|
|
|
ee:
|
|
|
|
tree:
|
|
|
|
project:
|
|
|
|
protected_branches:
|
|
|
|
- :unprotect_access_levels
|
|
|
|
included_attributes:
|
|
|
|
user:
|
|
|
|
- :name_ee
|
|
|
|
excluded_attributes:
|
|
|
|
project:
|
|
|
|
- :name_without_ee
|
|
|
|
methods:
|
|
|
|
labels:
|
|
|
|
- :type_ee
|
|
|
|
events_ee:
|
|
|
|
- :action_ee
|
|
|
|
preloads:
|
|
|
|
statuses:
|
|
|
|
bridge_ee:
|
|
|
|
EOF
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
let(:config_hash) { YAML.safe_load(config, [Symbol]) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(described_class).to receive(:parse_yaml) do
|
|
|
|
config_hash.deep_dup
|
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
context 'when using CE' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab).to receive(:ee?) { false }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'just returns the normalized Hash' do
|
|
|
|
is_expected.to eq(
|
|
|
|
{
|
|
|
|
tree: {
|
|
|
|
project: {
|
|
|
|
labels: {
|
|
|
|
priorities: {}
|
|
|
|
},
|
|
|
|
milestones: {
|
|
|
|
events: {
|
|
|
|
push_event_payload: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
included_attributes: {
|
|
|
|
user: [:id]
|
|
|
|
},
|
|
|
|
excluded_attributes: {
|
|
|
|
project: [:name]
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
labels: [:type],
|
|
|
|
events: [:action]
|
|
|
|
},
|
|
|
|
preloads: {
|
|
|
|
statuses: {
|
|
|
|
project: nil
|
|
|
|
}
|
2019-09-04 21:01:54 +05:30
|
|
|
}
|
|
|
|
}
|
2019-12-04 20:38:33 +05:30
|
|
|
)
|
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
context 'when using EE' do
|
|
|
|
before do
|
|
|
|
allow(Gitlab).to receive(:ee?) { true }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'just returns the normalized Hash' do
|
|
|
|
is_expected.to eq(
|
|
|
|
{
|
|
|
|
tree: {
|
|
|
|
project: {
|
|
|
|
labels: {
|
|
|
|
priorities: {}
|
|
|
|
},
|
|
|
|
milestones: {
|
|
|
|
events: {
|
|
|
|
push_event_payload: {}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
protected_branches: {
|
|
|
|
unprotect_access_levels: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
included_attributes: {
|
|
|
|
user: [:id, :name_ee]
|
|
|
|
},
|
|
|
|
excluded_attributes: {
|
|
|
|
project: [:name, :name_without_ee]
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
labels: [:type, :type_ee],
|
|
|
|
events: [:action],
|
|
|
|
events_ee: [:action_ee]
|
|
|
|
},
|
|
|
|
preloads: {
|
|
|
|
statuses: {
|
|
|
|
project: nil,
|
|
|
|
bridge_ee: nil
|
|
|
|
}
|
2019-09-04 21:01:54 +05:30
|
|
|
}
|
|
|
|
}
|
2019-12-04 20:38:33 +05:30
|
|
|
)
|
|
|
|
end
|
2019-09-04 21:01:54 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|