Commit 1501940e authored by Kamil Trzcinski's avatar Kamil Trzcinski Committed by Phil Hughes

Validate artifacts:expire_in in yaml processor

parent ee7c5539
...@@ -282,6 +282,10 @@ module Ci ...@@ -282,6 +282,10 @@ module Ci
if job[:artifacts][:when] && !job[:artifacts][:when].in?(%w(on_success on_failure always)) if job[:artifacts][:when] && !job[:artifacts][:when].in?(%w(on_success on_failure always))
raise ValidationError, "#{name} job: artifacts:when parameter should be on_success, on_failure or always" raise ValidationError, "#{name} job: artifacts:when parameter should be on_success, on_failure or always"
end end
if job[:artifacts][:expire_in] && !validate_duration(job[:artifacts][:expire_in])
raise ValidationError, "#{name} job: artifacts:expire_in parameter should be a duration"
end
end end
def validate_job_dependencies!(name, job) def validate_job_dependencies!(name, job)
...@@ -300,6 +304,12 @@ module Ci ...@@ -300,6 +304,12 @@ module Ci
end end
end end
def validate_duration(value)
value.is_a?(String) && ChronicDuration.parse(value)
rescue ChronicDuration::DurationParseError
false
end
def validate_array_of_strings(values) def validate_array_of_strings(values)
values.is_a?(Array) && values.all? { |value| validate_string(value) } values.is_a?(Array) && values.all? { |value| validate_string(value) }
end end
......
...@@ -572,7 +572,12 @@ module Ci ...@@ -572,7 +572,12 @@ module Ci
services: ["mysql"], services: ["mysql"],
before_script: ["pwd"], before_script: ["pwd"],
rspec: { rspec: {
artifacts: { paths: ["logs/", "binaries/"], untracked: true, name: "custom_name" }, artifacts: {
paths: ["logs/", "binaries/"],
untracked: true,
name: "custom_name",
expire_in: "7d"
},
script: "rspec" script: "rspec"
} }
}) })
...@@ -594,7 +599,8 @@ module Ci ...@@ -594,7 +599,8 @@ module Ci
artifacts: { artifacts: {
name: "custom_name", name: "custom_name",
paths: ["logs/", "binaries/"], paths: ["logs/", "binaries/"],
untracked: true untracked: true,
expire_in: "7d"
} }
}, },
when: "on_success", when: "on_success",
...@@ -990,6 +996,20 @@ EOT ...@@ -990,6 +996,20 @@ EOT
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: artifacts:when parameter should be on_success, on_failure or always") end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: artifacts:when parameter should be on_success, on_failure or always")
end end
it "returns errors if job artifacts:expire_in is not an a string" do
config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", artifacts: { expire_in: 1 } } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: artifacts:expire_in parameter should be a duration")
end
it "returns errors if job artifacts:expire_in is not an a valid duration" do
config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", artifacts: { expire_in: "7 elephants" } } })
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: artifacts:expire_in parameter should be a duration")
end
it "returns errors if job artifacts:untracked is not an array of strings" do it "returns errors if job artifacts:untracked is not an array of strings" do
config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", artifacts: { untracked: "string" } } }) config = YAML.dump({ types: ["build", "test"], rspec: { script: "test", artifacts: { untracked: "string" } } })
expect do expect do
......
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