Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
94bc7284
Commit
94bc7284
authored
Oct 02, 2019
by
Kamil Trzciński
Committed by
Aleksei Lipniagov
Oct 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Project Restore
Improves where we store test JSONs.
parent
eafd98ec
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
61 additions
and
50 deletions
+61
-50
ee/spec/fixtures/lib/gitlab/import_export/designs/project.json
...ec/fixtures/lib/gitlab/import_export/designs/project.json
+0
-0
ee/spec/lib/ee/gitlab/import_export/project_tree_restorer_spec.rb
...lib/ee/gitlab/import_export/project_tree_restorer_spec.rb
+1
-2
spec/fixtures/lib/gitlab/import_export/complex/project.json
spec/fixtures/lib/gitlab/import_export/complex/project.json
+0
-0
spec/fixtures/lib/gitlab/import_export/group/project.json
spec/fixtures/lib/gitlab/import_export/group/project.json
+0
-0
spec/fixtures/lib/gitlab/import_export/light/project.json
spec/fixtures/lib/gitlab/import_export/light/project.json
+0
-0
spec/fixtures/lib/gitlab/import_export/milestone-iid/project.json
...tures/lib/gitlab/import_export/milestone-iid/project.json
+0
-0
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
+47
-44
spec/lib/gitlab/import_export/relation_rename_service_spec.rb
.../lib/gitlab/import_export/relation_rename_service_spec.rb
+6
-4
spec/support/import_export/common_util.rb
spec/support/import_export/common_util.rb
+7
-0
No files found.
ee/spec/fixtures/lib/gitlab/import_export/
project.designs
.json
→
ee/spec/fixtures/lib/gitlab/import_export/
designs/project
.json
View file @
94bc7284
File moved
ee/spec/lib/ee/gitlab/import_export/project_tree_restorer_spec.rb
View file @
94bc7284
...
...
@@ -12,8 +12,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
let
(
:restored_project_json
)
{
project_tree_restorer
.
restore
}
before
do
allow
(
shared
).
to
receive
(
:export_path
).
and_return
(
'spec/fixtures/lib/gitlab/import_export/'
)
project_tree_restorer
.
instance_variable_set
(
:@path
,
'ee/spec/fixtures/lib/gitlab/import_export/project.designs.json'
)
setup_import_export_config
(
'designs'
,
'ee'
)
end
describe
'restoring design management data'
do
...
...
spec/fixtures/lib/gitlab/import_export/project.json
→
spec/fixtures/lib/gitlab/import_export/
complex/
project.json
View file @
94bc7284
File moved
spec/fixtures/lib/gitlab/import_export/
project.group
.json
→
spec/fixtures/lib/gitlab/import_export/
group/project
.json
View file @
94bc7284
File moved
spec/fixtures/lib/gitlab/import_export/
project.ligh
t.json
→
spec/fixtures/lib/gitlab/import_export/
light/projec
t.json
View file @
94bc7284
File moved
spec/fixtures/lib/gitlab/import_export/
project.milestone-iid
.json
→
spec/fixtures/lib/gitlab/import_export/
milestone-iid/project
.json
View file @
94bc7284
File moved
spec/lib/gitlab/import_export/project_tree_restorer_spec.rb
View file @
94bc7284
...
...
@@ -2,6 +2,8 @@ require 'spec_helper'
include
ImportExport
::
CommonUtil
describe
Gitlab
::
ImportExport
::
ProjectTreeRestorer
do
include
ImportExport
::
CommonUtil
let
(
:shared
)
{
project
.
import_export_shared
}
describe
'restore project tree'
do
...
...
@@ -16,7 +18,8 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
RSpec
::
Mocks
.
with_temporary_scope
do
@project
=
create
(
:project
,
:builds_enabled
,
:issues_disabled
,
name:
'project'
,
path:
'project'
)
@shared
=
@project
.
import_export_shared
allow
(
@shared
).
to
receive
(
:export_path
).
and_return
(
'spec/fixtures/lib/gitlab/import_export/'
)
setup_import_export_config
(
'complex'
)
allow_any_instance_of
(
Repository
).
to
receive
(
:fetch_source_branch!
).
and_return
(
true
)
allow_any_instance_of
(
Gitlab
::
Git
::
Repository
).
to
receive
(
:branch_exists?
).
and_return
(
false
)
...
...
@@ -314,21 +317,33 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
end
end
context
'
Light JSON
'
do
context
'
project.json file access check
'
do
let
(
:user
)
{
create
(
:user
)
}
let!
(
:project
)
{
create
(
:project
,
:builds_disabled
,
:issues_disabled
,
name:
'project'
,
path:
'project'
)
}
let
(
:project_tree_restorer
)
{
described_class
.
new
(
user:
user
,
shared:
shared
,
project:
project
)
}
let
(
:restored_project_json
)
{
project_tree_restorer
.
restore
}
before
do
allow
(
shared
).
to
receive
(
:export_path
).
and_return
(
'spec/fixtures/lib/gitlab/import_export/'
)
it
'does not read a symlink'
do
Dir
.
mktmpdir
do
|
tmpdir
|
setup_symlink
(
tmpdir
,
'project.json'
)
allow
(
shared
).
to
receive
(
:export_path
).
and_call_original
expect
(
project_tree_restorer
.
restore
).
to
eq
(
false
)
expect
(
shared
.
errors
).
to
include
(
'Incorrect JSON format'
)
end
end
end
context
'Light JSON'
do
let
(
:user
)
{
create
(
:user
)
}
let!
(
:project
)
{
create
(
:project
,
:builds_disabled
,
:issues_disabled
,
name:
'project'
,
path:
'project'
)
}
let
(
:project_tree_restorer
)
{
described_class
.
new
(
user:
user
,
shared:
shared
,
project:
project
)
}
let
(
:restored_project_json
)
{
project_tree_restorer
.
restore
}
context
'with a simple project'
do
before
do
project_tree_restorer
.
instance_variable_set
(
:@path
,
"spec/fixtures/lib/gitlab/import_export/project.light.json"
)
restored_project_json
setup_import_export_config
(
'light'
)
expect
(
restored_project_json
).
to
eq
(
true
)
end
it_behaves_like
'restores project correctly'
,
...
...
@@ -339,19 +354,6 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
first_issue_labels:
1
,
services:
1
context
'project.json file access check'
do
it
'does not read a symlink'
do
Dir
.
mktmpdir
do
|
tmpdir
|
setup_symlink
(
tmpdir
,
'project.json'
)
allow
(
shared
).
to
receive
(
:export_path
).
and_call_original
restored_project_json
expect
(
shared
.
errors
).
to
be_empty
end
end
end
context
'when there is an existing build with build token'
do
before
do
create
(
:ci_build
,
token:
'abcd'
)
...
...
@@ -367,6 +369,10 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
end
context
'when the project has overridden params in import data'
do
before
do
setup_import_export_config
(
'light'
)
end
it
'handles string versions of visibility_level'
do
# Project needs to be in a group for visibility level comparison
# to happen
...
...
@@ -375,24 +381,21 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
project
.
create_import_data
(
data:
{
override_params:
{
visibility_level:
Gitlab
::
VisibilityLevel
::
INTERNAL
.
to_s
}
})
restored_project_json
expect
(
restored_project_json
).
to
eq
(
true
)
expect
(
project
.
visibility_level
).
to
eq
(
Gitlab
::
VisibilityLevel
::
INTERNAL
)
end
it
'overwrites the params stored in the JSON'
do
project
.
create_import_data
(
data:
{
override_params:
{
description:
"Overridden"
}
})
restored_project_json
expect
(
restored_project_json
).
to
eq
(
true
)
expect
(
project
.
description
).
to
eq
(
"Overridden"
)
end
it
'does not allow setting params that are excluded from import_export settings'
do
project
.
create_import_data
(
data:
{
override_params:
{
lfs_enabled:
true
}
})
restored_project_json
expect
(
restored_project_json
).
to
eq
(
true
)
expect
(
project
.
lfs_enabled
).
to
be_falsey
end
...
...
@@ -408,7 +411,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
project
.
create_import_data
(
data:
{
override_params:
disabled_access_levels
})
restored_project_json
expect
(
restored_project_json
).
to
eq
(
true
)
aggregate_failures
do
access_level_keys
.
each
do
|
key
|
...
...
@@ -429,9 +432,8 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
end
before
do
project_tree_restorer
.
instance_variable_set
(
:@path
,
"spec/fixtures/lib/gitlab/import_export/project.group.json"
)
restored_project_json
setup_import_export_config
(
'group'
)
expect
(
restored_project_json
).
to
eq
(
true
)
end
it_behaves_like
'restores project correctly'
,
...
...
@@ -463,11 +465,11 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
end
before
do
project_tree_restorer
.
instance_variable_set
(
:@path
,
"spec/fixtures/lib/gitlab/import_export/project.light.json"
)
setup_import_export_config
(
'light'
)
end
it
'does not import any templated services'
do
restored_project_json
expect
(
restored_project_json
).
to
eq
(
true
)
expect
(
project
.
services
.
where
(
template:
true
).
count
).
to
eq
(
0
)
end
...
...
@@ -477,8 +479,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
expect_any_instance_of
(
Gitlab
::
ImportExport
::
Shared
).
not_to
receive
(
:error
)
restored_project_json
expect
(
restored_project_json
).
to
eq
(
true
)
expect
(
project
.
labels
.
count
).
to
eq
(
1
)
end
...
...
@@ -487,8 +488,7 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
expect_any_instance_of
(
Gitlab
::
ImportExport
::
Shared
).
not_to
receive
(
:error
)
restored_project_json
expect
(
restored_project_json
).
to
eq
(
true
)
expect
(
project
.
group
.
milestones
.
count
).
to
eq
(
1
)
expect
(
project
.
milestones
.
count
).
to
eq
(
0
)
end
...
...
@@ -504,13 +504,14 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
group:
create
(
:group
))
end
it
'preserves the project milestone IID'
do
project_tree_restorer
.
instance_variable_set
(
:@path
,
"spec/fixtures/lib/gitlab/import_export/project.milestone-iid.json"
)
before
do
setup_import_export_config
(
'milestone-iid'
)
end
it
'preserves the project milestone IID'
do
expect_any_instance_of
(
Gitlab
::
ImportExport
::
Shared
).
not_to
receive
(
:error
)
restored_project_json
expect
(
restored_project_json
).
to
eq
(
true
)
expect
(
project
.
milestones
.
count
).
to
eq
(
2
)
expect
(
Milestone
.
find_by_title
(
'Another milestone'
).
iid
).
to
eq
(
1
)
expect
(
Milestone
.
find_by_title
(
'Group-level milestone'
).
iid
).
to
eq
(
2
)
...
...
@@ -518,19 +519,21 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do
end
context
'with external authorization classification labels'
do
before
do
setup_import_export_config
(
'light'
)
end
it
'converts empty external classification authorization labels to nil'
do
project
.
create_import_data
(
data:
{
override_params:
{
external_authorization_classification_label:
""
}
})
restored_project_json
expect
(
restored_project_json
).
to
eq
(
true
)
expect
(
project
.
external_authorization_classification_label
).
to
be_nil
end
it
'preserves valid external classification authorization labels'
do
project
.
create_import_data
(
data:
{
override_params:
{
external_authorization_classification_label:
"foobar"
}
})
restored_project_json
expect
(
restored_project_json
).
to
eq
(
true
)
expect
(
project
.
external_authorization_classification_label
).
to
eq
(
"foobar"
)
end
end
...
...
spec/lib/gitlab/import_export/relation_rename_service_spec.rb
View file @
94bc7284
...
...
@@ -3,6 +3,8 @@
require
'spec_helper'
describe
Gitlab
::
ImportExport
::
RelationRenameService
do
include
ImportExport
::
CommonUtil
let
(
:renames
)
do
{
'example_relation1'
=>
'new_example_relation1'
,
...
...
@@ -21,12 +23,12 @@ describe Gitlab::ImportExport::RelationRenameService do
context
'when importing'
do
let
(
:project_tree_restorer
)
{
Gitlab
::
ImportExport
::
ProjectTreeRestorer
.
new
(
user:
user
,
shared:
shared
,
project:
project
)
}
let
(
:import_path
)
{
'spec/fixtures/lib/gitlab/import_export'
}
let
(
:file_content
)
{
IO
.
read
(
"
#{
import_path
}
/project.json"
)
}
let!
(
:json_file
)
{
ActiveSupport
::
JSON
.
decode
(
file_content
)
}
let
(
:file_content
)
{
IO
.
read
(
File
.
join
(
shared
.
export_path
,
'project.json'
))
}
let
(
:json_file
)
{
ActiveSupport
::
JSON
.
decode
(
file_content
)
}
before
do
allow
(
shared
).
to
receive
(
:export_path
).
and_return
(
import_path
)
setup_import_export_config
(
'complex'
)
allow
(
ActiveSupport
::
JSON
).
to
receive
(
:decode
).
and_call_original
allow
(
ActiveSupport
::
JSON
).
to
receive
(
:decode
).
with
(
file_content
).
and_return
(
json_file
)
end
...
...
spec/support/import_export/common_util.rb
View file @
94bc7284
...
...
@@ -8,5 +8,12 @@ module ImportExport
File
.
open
(
"
#{
tmpdir
}
/test"
,
'w'
)
{
|
file
|
file
.
write
(
"test"
)
}
FileUtils
.
ln_s
(
"
#{
tmpdir
}
/test"
,
"
#{
tmpdir
}
/
#{
symlink_name
}
"
)
end
def
setup_import_export_config
(
name
,
prefix
=
nil
)
export_path
=
[
prefix
,
'spec'
,
'fixtures'
,
'lib'
,
'gitlab'
,
'import_export'
,
name
].
compact
export_path
=
File
.
join
(
*
export_path
)
allow_any_instance_of
(
Gitlab
::
ImportExport
).
to
receive
(
:export_path
)
{
export_path
}
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment