Commit 3df56629 authored by Walmyr Lima e Silva Filho's avatar Walmyr Lima e Silva Filho

Merge branch 'tn/qa/new_test/maven_repository' into 'master'

Creating a maven package test

Closes gitlab-org/quality/testcases#219

See merge request gitlab-org/gitlab!18786
parents aaf45a8a 549e6c25
......@@ -407,6 +407,7 @@ module QA
module DockerRun
autoload :Base, 'qa/service/docker_run/base'
autoload :LDAP, 'qa/service/docker_run/ldap'
autoload :Maven, 'qa/service/docker_run/maven'
autoload :NodeJs, 'qa/service/docker_run/node_js'
autoload :GitlabRunner, 'qa/service/docker_run/gitlab_runner'
end
......
# frozen_string_literal: true
module QA
module Service
module DockerRun
class Maven < Base
def initialize(volume_host_path)
@image = 'maven:3.6.2-ibmjava-8-alpine'
@name = "qa-maven-#{SecureRandom.hex(8)}"
@volume_host_path = volume_host_path
super()
end
def publish!
# When we run the tests via gitlab-qa, we use docker-in-docker
# which means that host of a volume mount would be the host that
# started the gitlab-qa QA container (e.g., the CI runner),
# not the gitlab-qa container itself. That means we can't
# mount a volume from the file system inside the gitlab-qa
# container.
#
# Instead, we copy the files into the container.
shell <<~CMD.tr("\n", ' ')
docker run -d --rm
--network #{network}
--hostname #{host_name}
--name #{@name}
--volume #{@volume_host_path}:/home/maven
#{@image} sh -c "sleep 60"
CMD
shell "docker cp #{@volume_host_path}/. #{@name}:/home/maven"
shell "docker exec -t #{@name} sh -c 'cd /home/maven && mvn deploy -s settings.xml'"
end
end
end
end
end
# frozen_string_literal: true
module QA
context 'Package', :docker, :orchestrated, :packages do
describe 'Maven Repository' do
include Runtime::Fixtures
let(:group_id) { 'com.gitlab.qa' }
let(:artifact_id) { 'maven' }
let(:package_name) { "#{group_id}/#{artifact_id}".tr('.', '/') }
let(:auth_token) do
unless Page::Main::Menu.perform(&:signed_in?)
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform(&:sign_in_using_credentials)
end
Resource::PersonalAccessToken.fabricate!.access_token
end
let(:project) do
Resource::Project.fabricate_via_api! do |project|
project.name = 'maven-package-project'
end
end
it 'publishes a maven package and deletes it' do
uri = URI.parse(Runtime::Scenario.gitlab_address)
gitlab_address_with_port = "#{uri.scheme}://#{uri.host}:#{uri.port}"
pom_xml = {
file_path: 'pom.xml',
content: <<~XML
<project>
<groupId>#{group_id}</groupId>
<artifactId>#{artifact_id}</artifactId>
<version>1.0</version>
<modelVersion>4.0.0</modelVersion>
<repositories>
<repository>
<id>#{project.name}</id>
<url>#{gitlab_address_with_port}/api/v4/projects/#{project.id}/packages/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>#{project.name}</id>
<url>#{gitlab_address_with_port}/api/v4/projects/#{project.id}/packages/maven</url>
</repository>
<snapshotRepository>
<id>#{project.name}</id>
<url>#{gitlab_address_with_port}/api/v4/projects/#{project.id}/packages/maven</url>
</snapshotRepository>
</distributionManagement>
</project>
XML
}
settings_xml = {
file_path: 'settings.xml',
content: <<~XML
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<servers>
<server>
<id>#{project.name}</id>
<configuration>
<httpHeaders>
<property>
<name>Private-Token</name>
<value>#{auth_token}</value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
</settings>
XML
}
# Use a maven docker container to deploy the package
with_fixtures([pom_xml, settings_xml]) do |dir|
Service::DockerRun::Maven.new(dir).publish!
end
project.visit!
Page::Project::Menu.perform(&:click_packages_link)
EE::Page::Project::Packages::Index.perform do |index|
expect(index).to have_package(package_name)
index.click_package(package_name)
end
EE::Page::Project::Packages::Show.perform do |show|
expect(show).to have_package_info(package_name, "1.0")
show.click_delete
end
EE::Page::Project::Packages::Index.perform do |index|
expect(index).to have_content("Package was removed")
expect(index).to have_no_package(package_name)
end
end
end
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