diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2018-06-04 20:43:36 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2018-06-04 20:44:41 +0200 |
commit | 9728b52ba40be139a670f4d359e86d5edc544e9e (patch) | |
tree | 8fc9f0866d9d8860d2ef0b7a4253f4a26403ce5f /spec/lib/gitlab/github_import/importer/repository_importer_spec.rb | |
parent | 3571b97effd81f9a84f238f918544c6e5c625b76 (diff) | |
download | gitlab-ce-9728b52ba40be139a670f4d359e86d5edc544e9e.tar.gz |
Limit the size of imported GitHub repositorygh-importer-size-limit
This adds a limit on the size of repositories to import from GitHub.
This allows us to prevent users from importing very large repositories,
as doing so could have a negative impact on availability.
Diffstat (limited to 'spec/lib/gitlab/github_import/importer/repository_importer_spec.rb')
-rw-r--r-- | spec/lib/gitlab/github_import/importer/repository_importer_spec.rb | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/spec/lib/gitlab/github_import/importer/repository_importer_spec.rb b/spec/lib/gitlab/github_import/importer/repository_importer_spec.rb index cc9e4b67e72..ed5ab36abff 100644 --- a/spec/lib/gitlab/github_import/importer/repository_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/repository_importer_spec.rb @@ -14,7 +14,8 @@ describe Gitlab::GithubImport::Importer::RepositoryImporter do disk_path: 'foo', repository: repository, create_wiki: true, - import_state: import_state + import_state: import_state, + size: 50 ) end @@ -82,6 +83,10 @@ describe Gitlab::GithubImport::Importer::RepositoryImporter do .and_return(true) expect(importer) + .to receive(:repository_too_large?) + .and_return(false) + + expect(importer) .to receive(:import_wiki?) .and_return(true) @@ -105,6 +110,10 @@ describe Gitlab::GithubImport::Importer::RepositoryImporter do .and_return(false) expect(importer) + .to receive(:repository_too_large?) + .and_return(false) + + expect(importer) .to receive(:import_wiki?) .and_return(true) @@ -127,6 +136,10 @@ describe Gitlab::GithubImport::Importer::RepositoryImporter do .and_return(true) expect(importer) + .to receive(:repository_too_large?) + .and_return(false) + + expect(importer) .to receive(:import_wiki?) .and_return(false) @@ -149,6 +162,10 @@ describe Gitlab::GithubImport::Importer::RepositoryImporter do .and_return(true) expect(importer) + .to receive(:repository_too_large?) + .and_return(false) + + expect(importer) .to receive(:import_wiki?) .and_return(true) @@ -164,6 +181,55 @@ describe Gitlab::GithubImport::Importer::RepositoryImporter do expect(importer.execute).to eq(false) end + + context 'when the repository is too large' do + it 'does not import the repository' do + expect(importer) + .to receive(:repository_too_large?) + .and_return(true) + + expect(importer) + .not_to receive(:import_repository) + + expect(importer) + .to receive(:fail_import) + .and_return(false) + + expect(importer.execute).to eq(false) + end + end + end + + describe '#repository_size' do + it 'returns the size of the repository as a Float' do + expect(importer) + .to receive(:github_repository) + .and_return(repository) + + expect(repository) + .to receive(:size) + .and_return(10) + + expect(importer.repository_size).to eq(10.0) + end + end + + describe '#repository_too_large?' do + it 'returns true when the repository is too large' do + expect(importer) + .to receive(:repository_size) + .and_return(10_485_7600.0) + + expect(importer.repository_too_large?).to eq(true) + end + + it 'returns false when the repository is not too large' do + expect(importer) + .to receive(:repository_size) + .and_return(10.0) + + expect(importer.repository_too_large?).to eq(false) + end end describe '#import_repository' do |