diff options
author | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-07-10 14:56:09 +0200 |
---|---|---|
committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2015-07-10 16:04:35 +0200 |
commit | efdf54f25a83462a750cacd4ea7919c7d38e67d1 (patch) | |
tree | e1823788941ac74352446c065a26b79eb22f985d /spec/lib | |
parent | d841ed56d39db1b33947b9b9c0291beaa7dcdd43 (diff) | |
download | gitlab-ci-efdf54f25a83462a750cacd4ea7919c7d38e67d1.tar.gz |
Allow to specify flexible list of types in yaml
```
types:
- test
- deploy
- notify
rspec:
script: "rspec"
rubocop:
script: "rubocop"
staging:
type: deploy
script: "echo deploy"
only:
- master
production:
type: deploy
script: "echo production"
only:
- tags
dockerhub:
type: notify
script: "curl http://docker/hub/web/hook"
downstream:
type: notify
script: "curl http://build/downstream/jobs"
```
This will trigger two test jobs in parallel, when finished it will trigged either staging or production, when finished it will trigger dockerhub and downstream in parallel.
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab_ci_yaml_processor_spec.rb | 128 |
1 files changed, 65 insertions, 63 deletions
diff --git a/spec/lib/gitlab_ci_yaml_processor_spec.rb b/spec/lib/gitlab_ci_yaml_processor_spec.rb index 5f202b2..72f86aa 100644 --- a/spec/lib/gitlab_ci_yaml_processor_spec.rb +++ b/spec/lib/gitlab_ci_yaml_processor_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' describe GitlabCiYamlProcessor do describe "#builds_for_ref" do + let (:type) { 'test' } + it "returns builds if no branch specified" do config = YAML.dump({ before_script: ["pwd"], @@ -11,8 +13,9 @@ describe GitlabCiYamlProcessor do config_processor = GitlabCiYamlProcessor.new(config) - config_processor.builds_for_ref("master").size.should == 1 - config_processor.builds_for_ref("master").first.should == { + config_processor.builds_for_type_and_ref(type, "master").size.should == 1 + config_processor.builds_for_type_and_ref(type, "master").first.should == { + type: "test", except: nil, name: :rspec, only: nil, @@ -31,7 +34,7 @@ describe GitlabCiYamlProcessor do config_processor = GitlabCiYamlProcessor.new(config) - config_processor.builds_for_ref("master").size.should == 0 + config_processor.builds_for_type_and_ref(type, "master").size.should == 0 end it "does not return builds if only has regexp with another branch" do @@ -42,7 +45,7 @@ describe GitlabCiYamlProcessor do config_processor = GitlabCiYamlProcessor.new(config) - config_processor.builds_for_ref("master").size.should == 0 + config_processor.builds_for_type_and_ref(type, "master").size.should == 0 end it "returns builds if only has specified this branch" do @@ -53,7 +56,7 @@ describe GitlabCiYamlProcessor do config_processor = GitlabCiYamlProcessor.new(config) - config_processor.builds_for_ref("master").size.should == 1 + config_processor.builds_for_type_and_ref(type, "master").size.should == 1 end it "does not build tags" do @@ -64,73 +67,35 @@ describe GitlabCiYamlProcessor do config_processor = GitlabCiYamlProcessor.new(config) - config_processor.builds_for_ref("0-1", true).size.should == 0 + config_processor.builds_for_type_and_ref(type, "0-1", true).size.should == 0 end - end - - describe "#deploy_builds_for_ref" do - it "returns builds if no branch specified" do - config = YAML.dump({ - before_script: ["pwd"], - rspec: {script: "rspec", type: "deploy", allow_failure: true} - }) - - config_processor = GitlabCiYamlProcessor.new(config) - config_processor.deploy_builds_for_ref("master").size.should == 1 - config_processor.deploy_builds_for_ref("master").first.should == { - except: nil, - name: :rspec, - only: nil, - script: "pwd\nrspec", - tags: [], - options: {}, - allow_failure: true - } - end - - it "does not return builds if only has another branch" do - config = YAML.dump({ - before_script: ["pwd"], - rspec: {script: "rspec", type: "deploy", only: ["deploy"]} - }) - - config_processor = GitlabCiYamlProcessor.new(config) - - config_processor.deploy_builds_for_ref("master").size.should == 0 - end - - it "does not return builds if only has regexp with another branch" do + it "returns builds if only has a list of branches including specified" do config = YAML.dump({ - before_script: ["pwd"], - rspec: {script: "rspec", type: "deploy", only: ["/^deploy$/"]} - }) + before_script: ["pwd"], + rspec: {script: "rspec", type: type, only: ["master", "deploy"]} + }) config_processor = GitlabCiYamlProcessor.new(config) - config_processor.deploy_builds_for_ref("master").size.should == 0 + config_processor.builds_for_type_and_ref(type, "deploy").size.should == 1 end - it "returns builds if only has specified this branch" do - config = YAML.dump({ - before_script: ["pwd"], - rspec: {script: "rspec", type: "deploy", only: ["master"]} - }) + it "returns build only for specified type" do - config_processor = GitlabCiYamlProcessor.new(config) - - config_processor.deploy_builds_for_ref("master").size.should == 1 - end - - it "returns builds if only has a list of branches including specified" do config = YAML.dump({ - before_script: ["pwd"], - rspec: {script: "rspec", type: "deploy", only: ["master", "deploy"]} - }) + before_script: ["pwd"], + build: {script: "build", type: "build", only: ["master", "deploy"]}, + rspec: {script: "rspec", type: type, only: ["master", "deploy"]}, + staging: {script: "deploy", type: "deploy", only: ["master", "deploy"]}, + production: {script: "deploy", type: "deploy", only: ["master", "deploy"]}, + }) config_processor = GitlabCiYamlProcessor.new(config) - config_processor.deploy_builds_for_ref("deploy").size.should == 1 + config_processor.builds_for_type_and_ref("production", "deploy").size.should == 0 + config_processor.builds_for_type_and_ref(type, "deploy").size.should == 1 + config_processor.builds_for_type_and_ref("deploy", "deploy").size.should == 2 end end @@ -145,9 +110,10 @@ describe GitlabCiYamlProcessor do config_processor = GitlabCiYamlProcessor.new(config) - config_processor.builds_for_ref("master").size.should == 1 - config_processor.builds_for_ref("master").first.should == { + config_processor.builds_for_type_and_ref("test", "master").size.should == 1 + config_processor.builds_for_type_and_ref("test", "master").first.should == { except: nil, + type: "test", name: :rspec, only: nil, script: "pwd\nrspec", @@ -170,9 +136,10 @@ describe GitlabCiYamlProcessor do config_processor = GitlabCiYamlProcessor.new(config) - config_processor.builds_for_ref("master").size.should == 1 - config_processor.builds_for_ref("master").first.should == { + config_processor.builds_for_type_and_ref("test", "master").size.should == 1 + config_processor.builds_for_type_and_ref("test", "master").first.should == { except: nil, + type: "test", name: :rspec, only: nil, script: "pwd\nrspec", @@ -267,5 +234,40 @@ describe GitlabCiYamlProcessor do GitlabCiYamlProcessor.new(config) end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: allow_failure parameter should be an boolean") end + + it "returns errors if job type is not a string" do + config = YAML.dump({rspec: {script: "test", type: false, allow_failure: "string"}}) + expect do + GitlabCiYamlProcessor.new(config) + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: type should be a string") + end + + it "returns errors if job type is not a pre-defined type" do + config = YAML.dump({rspec: {script: "test", type: "acceptance", allow_failure: "string"}}) + expect do + GitlabCiYamlProcessor.new(config) + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: type parameter should be build, test, deploy") + end + + it "returns errors if job type is not a defined type" do + config = YAML.dump({types: ["build", "test"], rspec: {script: "test", type: "acceptance", allow_failure: "string"}}) + expect do + GitlabCiYamlProcessor.new(config) + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: type parameter should be build, test") + end + + it "returns errors if types is not an array" do + config = YAML.dump({types: "test", rspec: {script: "test"}}) + expect do + GitlabCiYamlProcessor.new(config) + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "types should be an array of strings") + end + + it "returns errors if types is not an array of strings" do + config = YAML.dump({types: [true, "test"], rspec: {script: "test"}}) + expect do + GitlabCiYamlProcessor.new(config) + end.to raise_error(GitlabCiYamlProcessor::ValidationError, "types should be an array of strings") + end end end
\ No newline at end of file |