Commit 16eec6cc authored by Stan Hu's avatar Stan Hu

Merge branch '213342-introduce-feature-tests-for-uploads' into 'master'

Add feature tests for uploads

See merge request gitlab-org/gitlab!39941
parents 77e1d308 0be703e3
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Upload ci artifact', :api, :js do
include_context 'file upload requests helpers'
let_it_be(:user) { create(:user, :admin) }
let_it_be(:project) { create(:project) }
let_it_be(:pipeline) { create(:ci_pipeline, project: project, ref: 'master') }
let_it_be(:runner) { create(:ci_runner, :project, projects: [project]) }
let_it_be(:job) { create(:ci_build, :running, user: user, project: project, pipeline: pipeline, runner_id: runner.id) }
let(:api_path) { "/jobs/#{job.id}/artifacts?token=#{job.token}" }
let(:url) { capybara_url(api(api_path)) }
let(:file) { fixture_file_upload('spec/fixtures/ci_build_artifacts.zip') }
subject do
HTTParty.post(url, body: { file: file })
end
RSpec.shared_examples 'for ci artifact' do
it { expect { subject }.to change { ::Ci::JobArtifact.count }.by(2) }
it { expect(subject.code).to eq(201) }
end
it_behaves_like 'handling file uploads', 'for ci artifact'
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Upload a git lfs object', :js do
include_context 'file upload requests helpers'
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user, :admin) }
let_it_be(:personal_access_token) { create(:personal_access_token, user: user) }
let(:file) { fixture_file_upload('spec/fixtures/banana_sample.gif') }
let(:oid) { Digest::SHA256.hexdigest(File.read(file.path)) }
let(:size) { file.size }
let(:url) { capybara_url("/#{project.namespace.path}/#{project.path}.git/gitlab-lfs/objects/#{oid}/#{size}") }
let(:headers) { { 'Content-Type' => 'application/octet-stream' } }
subject do
HTTParty.put(
url,
headers: headers,
basic_auth: { user: user.username, password: personal_access_token.token },
body: file.read
)
end
before do
stub_lfs_setting(enabled: true)
end
RSpec.shared_examples 'for a git lfs object' do
it { expect { subject }.to change { LfsObject.count }.by(1) }
it { expect(subject.code).to eq(200) }
end
it_behaves_like 'handling file uploads', 'for a git lfs object'
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Upload a design through graphQL', :js do
include_context 'file upload requests helpers'
let_it_be(:query) do
"
mutation uploadDesign($files: [Upload!]!, $projectPath: ID!, $iid: ID!) {
designManagementUpload(input: { projectPath: $projectPath, iid: $iid, files: $files}) {
clientMutationId,
errors
}
}
"
end
let_it_be(:user) { create(:user, :admin) }
let_it_be(:personal_access_token) { create(:personal_access_token, user: user) }
let_it_be(:design) { create(:design) }
let_it_be(:operations) { { "operationName": "uploadDesign", "variables": { "files": [], "projectPath": design.project.full_path, "iid": design.issue.iid }, "query": query }.to_json }
let_it_be(:map) { { "1": ["variables.files.0"] }.to_json }
let(:url) { capybara_url("/api/graphql?private_token=#{personal_access_token.token}") }
let(:file) { fixture_file_upload('spec/fixtures/dk.png') }
subject do
HTTParty.post(
url,
body: {
operations: operations,
map: map,
"1": file
}
)
end
before do
stub_lfs_setting(enabled: true)
end
RSpec.shared_examples 'for a design upload through graphQL' do
it 'creates proper objects' do
expect { subject }
.to change { ::DesignManagement::Design.count }.by(1)
.and change { ::LfsObject.count }.by(1)
end
it { expect(subject.code).to eq(200) }
end
it_behaves_like 'handling file uploads', 'for a design upload through graphQL'
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Upload a group export archive', :api, :js do
include_context 'file upload requests helpers'
let_it_be(:user) { create(:user, :admin) }
let_it_be(:personal_access_token) { create(:personal_access_token, user: user) }
let(:api_path) { '/groups/import' }
let(:url) { capybara_url(api(api_path, personal_access_token: personal_access_token)) }
let(:file) { fixture_file_upload('spec/fixtures/group_export.tar.gz') }
subject do
HTTParty.post(
url,
body: {
path: 'test-import-group',
name: 'test-import-group',
file: file
}
)
end
RSpec.shared_examples 'for a group export archive' do
it { expect { subject }.to change { Group.count }.by(1) }
it { expect(subject.code).to eq(202) }
end
it_behaves_like 'handling file uploads', 'for a group export archive'
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Upload a maven package', :api, :js do
include_context 'file upload requests helpers'
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user, :admin) }
let_it_be(:personal_access_token) { create(:personal_access_token, user: user) }
let(:api_path) { "/projects/#{project.id}/packages/maven/com/example/my-app/1.0/my-app-1.0-20180724.124855-1.jar" }
let(:url) { capybara_url(api(api_path, personal_access_token: personal_access_token)) }
let(:file) { fixture_file_upload('spec/fixtures/dk.png') }
subject { HTTParty.put(url, body: file.read) }
RSpec.shared_examples 'for a maven package' do
it 'creates package files' do
expect { subject }
.to change { Packages::Package.maven.count }.by(1)
.and change { Packages::PackageFile.count }.by(1)
end
it { expect(subject.code).to eq(200) }
end
it_behaves_like 'handling file uploads', 'for a maven package'
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Upload a nuget package', :api, :js do
include_context 'file upload requests helpers'
let_it_be(:project) { create(:project) }
let_it_be(:user) { create(:user, :admin) }
let_it_be(:personal_access_token) { create(:personal_access_token, user: user) }
let(:api_path) { "/projects/#{project.id}/packages/nuget/" }
let(:url) { capybara_url(api(api_path)) }
let(:file) { fixture_file_upload('spec/fixtures/dk.png') }
subject do
HTTParty.put(
url,
basic_auth: { user: user.username, password: personal_access_token.token },
body: { package: file }
)
end
RSpec.shared_examples 'for a nuget package' do
it 'creates package files' do
expect { subject }
.to change { Packages::Package.nuget.count }.by(1)
.and change { Packages::PackageFile.count }.by(1)
end
it { expect(subject.code).to eq(201) }
end
it_behaves_like 'handling file uploads', 'for a nuget package'
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Upload a project export archive', :api, :js do
include_context 'file upload requests helpers'
let_it_be(:user) { create(:user, :admin) }
let_it_be(:personal_access_token) { create(:personal_access_token, user: user) }
let(:api_path) { '/projects/import' }
let(:url) { capybara_url(api(api_path, personal_access_token: personal_access_token)) }
let(:file) { fixture_file_upload('spec/features/projects/import_export/test_project_export.tar.gz') }
subject do
HTTParty.post(
url,
body: {
path: 'test-import',
file: file
}
)
end
RSpec.shared_examples 'for a project export archive' do
it { expect { subject }.to change { Project.count }.by(1) }
it { expect(subject.code).to eq(201) }
end
it_behaves_like 'handling file uploads', 'for a project export archive'
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Upload a user avatar', :js do
let_it_be(:user, reload: true) { create(:user) }
let(:file) { fixture_file_upload('spec/fixtures/banana_sample.gif') }
before do
sign_in(user)
visit(profile_path)
attach_file('user_avatar-trigger', file.path, make_visible: true)
click_button 'Set new profile picture'
end
subject do
click_button 'Update profile settings'
end
RSpec.shared_examples 'for a user avatar' do
it 'uploads successfully' do
expect(user.avatar.file).to eq nil
subject
expect(page).to have_content 'Profile was successfully updated'
expect(user.reload.avatar.file).to be_present
expect(user.avatar).to be_instance_of AvatarUploader
expect(current_path).to eq(profile_path)
end
end
it_behaves_like 'handling file uploads', 'for a user avatar'
end
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe 'Raw artifact', :js do
RSpec.describe 'Raw artifact' do
let(:project) { create(:project, :public) }
let(:pipeline) { create(:ci_empty_pipeline, project: project) }
let(:job) { create(:ci_build, :artifacts, pipeline: pipeline) }
......
......@@ -260,6 +260,7 @@ module TestEnv
listen_addr = [host, port].join(':')
workhorse_pid = spawn(
{ 'PATH' => "#{ENV['PATH']}:#{workhorse_dir}" },
File.join(workhorse_dir, 'gitlab-workhorse'),
'-authSocket', upstream,
'-documentRoot', Rails.root.join('public').to_s,
......
# frozen_string_literal: true
RSpec.shared_context 'file upload requests helpers' do
def capybara_url(path)
"http://#{Capybara.current_session.server.host}:#{Capybara.current_session.server.port}#{path}"
end
end
# frozen_string_literal: true
RSpec.shared_examples 'handling file uploads' do |shared_examples_name|
context 'with object storage disabled' do
it_behaves_like shared_examples_name
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment