Commit 07d6cbfb authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'pl-spec-factories-go-module' into 'master'

Fix some remaining cop offenses for go module factories

See merge request gitlab-org/gitlab!55772
parents 48878e18 002dd7be
......@@ -7,7 +7,12 @@ FactoryBot.define do
transient do
files { { 'foo.txt' => 'content' } }
message { 'Message' }
# rubocop: disable FactoryBot/InlineAssociation
# We need a persisted project so we can create commits and tags
# in `commit` otherwise linting this factory with `build` strategy
# will fail.
project { create(:project, :repository) }
# rubocop: enable FactoryBot/InlineAssociation
service do
Files::MultiService.new(
......@@ -44,14 +49,13 @@ FactoryBot.define do
trait :files do
transient do
files { raise ArgumentError.new("files is required") }
message { 'Add files' }
end
end
trait :package do
transient do
path { raise ArgumentError.new("path is required") }
path { 'pkg' }
message { 'Add package' }
files { { "#{path}/b.go" => "package b\nfunc Bye() { println(\"Goodbye world!\") }\n" } }
end
......@@ -64,7 +68,7 @@ FactoryBot.define do
host_prefix { "#{::Gitlab.config.gitlab.host}/#{project.path_with_namespace}" }
url { name ? "#{host_prefix}/#{name}" : host_prefix }
path { name.to_s + '/' }
path { "#{name}/" }
files do
{
......
......@@ -8,12 +8,12 @@ FactoryBot.define do
p = attributes[:params]
s = Packages::SemVer.parse(p.semver, prefixed: true)
raise ArgumentError.new("invalid sematic version: '#{p.semver}''") if !s && p.semver
raise ArgumentError, "invalid sematic version: '#{p.semver}'" if !s && p.semver
new(p.mod, p.type, p.commit, name: p.name, semver: s, ref: p.ref)
end
mod { create :go_module }
mod { association(:go_module) }
type { :commit }
commit { mod.project.repository.head_commit }
name { nil }
......@@ -33,45 +33,11 @@ FactoryBot.define do
mod.project.repository.tags
.filter { |t| Packages::SemVer.match?(t.name, prefixed: true) }
.map { |t| Packages::SemVer.parse(t.name, prefixed: true) }
.max { |a, b| "#{a}" <=> "#{b}" }
.max_by(&:to_s)
.to_s
end
params { OpenStruct.new(mod: mod, type: :ref, commit: commit, semver: name, ref: ref) }
end
trait :pseudo do
transient do
prefix do
# This provides a sane default value, but in reality the caller should
# specify `prefix:`
# This does not take into account that `commit` may be before the
# latest tag.
# Find 'latest' semver tag (does not actually use semver precedence rules)
v = mod.project.repository.tags
.filter { |t| Packages::SemVer.match?(t.name, prefixed: true) }
.map { |t| Packages::SemVer.parse(t.name, prefixed: true) }
.max { |a, b| "#{a}" <=> "#{b}" }
# Default if no semver tags exist
next 'v0.0.0' unless v
# Valid pseudo-versions are:
# vX.0.0-yyyymmddhhmmss-sha1337beef0, when no earlier tagged commit exists for X
# vX.Y.Z-pre.0.yyyymmddhhmmss-sha1337beef0, when most recent prior tag is vX.Y.Z-pre
# vX.Y.(Z+1)-0.yyyymmddhhmmss-sha1337beef0, when most recent prior tag is vX.Y.Z
v = v.with(patch: v.patch + 1) unless v.prerelease
"#{v}.0"
end
end
type { :pseudo }
name { "#{prefix}#{commit.committed_date.strftime('%Y%m%d%H%M%S')}-#{commit.sha[0..11]}" }
params { OpenStruct.new(mod: mod, type: :pseudo, commit: commit, name: name, semver: name) }
end
end
end
......@@ -5,7 +5,7 @@ FactoryBot.define do
initialize_with { new(attributes[:project], attributes[:name], attributes[:path]) }
skip_create
project { create :project, :repository }
project { association(:project, :repository) }
path { '' }
name { "#{Settings.build_gitlab_go_url}/#{project.full_path}#{path.empty? ? '' : '/'}#{path}" }
......
......@@ -18,9 +18,6 @@ RSpec.describe 'factories' do
[:ci_job_artifact, :gzip],
[:ci_job_artifact, :correct_checksum],
[:environment, :non_playable],
[:go_module_commit, :files],
[:go_module_commit, :package],
[:go_module_version, :pseudo],
[:composer_cache_file, :object_storage],
[:debian_project_component_file, :object_storage],
[:debian_project_distribution, :object_storage],
......
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