Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec/lib/ci
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-04-19 21:00:14 +0300
committerKamil Trzcinski <ayufan@ayufan.eu>2016-04-19 21:00:14 +0300
commit27e0c7723ca1eb85222210a20fd3fee1d77733f7 (patch)
tree0b25b0122c7918382c22ab277df421585f9e58b1 /spec/lib/ci
parentee2dc0624093a0fe8665778fd0cc734754e7cdc9 (diff)
parent0063194ad6029915361d282392b6ab207ffd1520 (diff)
Merge remote-tracking branch 'origin/master' into ci-commit-as-pipeline
# Conflicts: # db/schema.rb
Diffstat (limited to 'spec/lib/ci')
-rw-r--r--spec/lib/ci/gitlab_ci_yaml_processor_spec.rb190
1 files changed, 171 insertions, 19 deletions
diff --git a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
index dcb8a3451bd..643acf0303c 100644
--- a/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+++ b/spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
@@ -286,6 +286,81 @@ module Ci
end
end
+
+ describe "Scripts handling" do
+ let(:config_data) { YAML.dump(config) }
+ let(:config_processor) { GitlabCiYamlProcessor.new(config_data, path) }
+
+ subject { config_processor.builds_for_stage_and_ref("test", "master").first }
+
+ describe "before_script" do
+ context "in global context" do
+ let(:config) do
+ {
+ before_script: ["global script"],
+ test: { script: ["script"] }
+ }
+ end
+
+ it "return commands with scripts concencaced" do
+ expect(subject[:commands]).to eq("global script\nscript")
+ end
+ end
+
+ context "overwritten in local context" do
+ let(:config) do
+ {
+ before_script: ["global script"],
+ test: { before_script: ["local script"], script: ["script"] }
+ }
+ end
+
+ it "return commands with scripts concencaced" do
+ expect(subject[:commands]).to eq("local script\nscript")
+ end
+ end
+ end
+
+ describe "script" do
+ let(:config) do
+ {
+ test: { script: ["script"] }
+ }
+ end
+
+ it "return commands with scripts concencaced" do
+ expect(subject[:commands]).to eq("script")
+ end
+ end
+
+ describe "after_script" do
+ context "in global context" do
+ let(:config) do
+ {
+ after_script: ["after_script"],
+ test: { script: ["script"] }
+ }
+ end
+
+ it "return after_script in options" do
+ expect(subject[:options][:after_script]).to eq(["after_script"])
+ end
+ end
+
+ context "overwritten in local context" do
+ let(:config) do
+ {
+ after_script: ["local after_script"],
+ test: { after_script: ["local after_script"], script: ["script"] }
+ }
+ end
+
+ it "return after_script in options" do
+ expect(subject[:options][:after_script]).to eq(["local after_script"])
+ end
+ end
+ end
+ end
describe "Image and service handling" do
it "returns image and service when defined" do
@@ -345,20 +420,76 @@ module Ci
end
end
- describe "Variables" do
- it "returns variables when defined" do
- variables = {
- var1: "value1",
- var2: "value2",
- }
- config = YAML.dump({
- variables: variables,
- before_script: ["pwd"],
- rspec: { script: "rspec" }
- })
+ describe 'Variables' do
+ context 'when global variables are defined' do
+ it 'returns global variables' do
+ variables = {
+ VAR1: 'value1',
+ VAR2: 'value2',
+ }
- config_processor = GitlabCiYamlProcessor.new(config, path)
- expect(config_processor.variables).to eq(variables)
+ config = YAML.dump({
+ variables: variables,
+ before_script: ['pwd'],
+ rspec: { script: 'rspec' }
+ })
+
+ config_processor = GitlabCiYamlProcessor.new(config, path)
+
+ expect(config_processor.global_variables).to eq(variables)
+ end
+ end
+
+ context 'when job variables are defined' do
+ context 'when syntax is correct' do
+ it 'returns job variables' do
+ variables = {
+ KEY1: 'value1',
+ SOME_KEY_2: 'value2'
+ }
+
+ config = YAML.dump(
+ { before_script: ['pwd'],
+ rspec: {
+ variables: variables,
+ script: 'rspec' }
+ })
+
+ config_processor = GitlabCiYamlProcessor.new(config, path)
+
+ expect(config_processor.job_variables(:rspec)).to eq variables
+ end
+ end
+
+ context 'when syntax is incorrect' do
+ it 'raises error' do
+ variables = [:KEY1, 'value1', :KEY2, 'value2']
+
+ config = YAML.dump(
+ { before_script: ['pwd'],
+ rspec: {
+ variables: variables,
+ script: 'rspec' }
+ })
+
+ expect { GitlabCiYamlProcessor.new(config, path) }
+ .to raise_error(GitlabCiYamlProcessor::ValidationError,
+ /job: variables should be a map/)
+ end
+ end
+ end
+
+ context 'when job variables are not defined' do
+ it 'returns empty array' do
+ config = YAML.dump({
+ before_script: ['pwd'],
+ rspec: { script: 'rspec' }
+ })
+
+ config_processor = GitlabCiYamlProcessor.new(config, path)
+
+ expect(config_processor.job_variables(:rspec)).to eq []
+ end
end
end
@@ -536,7 +667,7 @@ module Ci
stage_idx: 1,
name: :normal_job,
only: nil,
- commands: "\ntest",
+ commands: "test",
tag_list: [],
options: {},
when: "on_success",
@@ -563,7 +694,7 @@ EOT
stage_idx: 1,
name: :job1,
only: nil,
- commands: "\nexecute-script-for-job",
+ commands: "execute-script-for-job",
tag_list: [],
options: {},
when: "on_success",
@@ -575,7 +706,7 @@ EOT
stage_idx: 1,
name: :job2,
only: nil,
- commands: "\nexecute-script-for-job",
+ commands: "execute-script-for-job",
tag_list: [],
options: {},
when: "on_success",
@@ -607,6 +738,27 @@ EOT
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "before_script should be an array of strings")
end
+ it "returns errors if job before_script parameter is not an array of strings" do
+ config = YAML.dump({ rspec: { script: "test", before_script: [10, "test"] } })
+ expect do
+ GitlabCiYamlProcessor.new(config, path)
+ end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: before_script should be an array of strings")
+ end
+
+ it "returns errors if after_script parameter is invalid" do
+ config = YAML.dump({ after_script: "bundle update", rspec: { script: "test" } })
+ expect do
+ GitlabCiYamlProcessor.new(config, path)
+ end.to raise_error(GitlabCiYamlProcessor::ValidationError, "after_script should be an array of strings")
+ end
+
+ it "returns errors if job after_script parameter is not an array of strings" do
+ config = YAML.dump({ rspec: { script: "test", after_script: [10, "test"] } })
+ expect do
+ GitlabCiYamlProcessor.new(config, path)
+ end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: after_script should be an array of strings")
+ end
+
it "returns errors if image parameter is invalid" do
config = YAML.dump({ image: ["test"], rspec: { script: "test" } })
expect do
@@ -730,14 +882,14 @@ EOT
config = YAML.dump({ variables: "test", rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config, path)
- end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-valued strings")
+ end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-value strings")
end
- it "returns errors if variables is not a map of key-valued strings" do
+ it "returns errors if variables is not a map of key-value strings" do
config = YAML.dump({ variables: { test: false }, rspec: { script: "test" } })
expect do
GitlabCiYamlProcessor.new(config, path)
- end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-valued strings")
+ end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-value strings")
end
it "returns errors if job when is not on_success, on_failure or always" do