Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix: branches with dots.

  • Loading branch information...
commit 4f2c1b02afa657cd21c8d157fd3efa4ead54e94a 1 parent e6c78f3
@abangratz abangratz authored
Showing with 101 additions and 84 deletions.
  1. +1 −1  lib/kraken-build/jenkins-api.rb
  2. +100 −83 spec/lib/jenkins_api_spec.rb
View
2  lib/kraken-build/jenkins-api.rb
@@ -21,7 +21,7 @@ def get_jobs(options = {})
end
def create_job(job, options = {})
- repo, branch_name = job.split('.')
+ repo, branch_name = job.split('.', 2)
job_config = create_job_configuration(repo, branch_name)
options.merge!(
:body => job_config,
View
183 spec/lib/jenkins_api_spec.rb
@@ -2,118 +2,135 @@
describe JenkinsApi do
- context "configurations" do
- before(:each) do
- JenkinsApi.instance_variable_set(:@default_options, {})
- end
+ context "configurations" do
+ before(:each) do
+ JenkinsApi.instance_variable_set(:@default_options, {})
+ end
- it "uses no basic_auth when username and password are not prived" do
- api = JenkinsApi.new
- api.class.default_options[:basic_auth].should be(nil)
- end
+ it "uses no basic_auth when username and password are not prived" do
+ api = JenkinsApi.new
+ api.class.default_options[:basic_auth].should be(nil)
+ end
- it "uses basic_auth when username and password prived" do
- options = {:username => 'user', :password => 'password'}
- api = JenkinsApi.new(options)
+ it "uses basic_auth when username and password prived" do
+ options = {:username => 'user', :password => 'password'}
+ api = JenkinsApi.new(options)
- api.class.default_options[:basic_auth][:username].should == options[:username]
- api.class.default_options[:basic_auth][:password].should == options[:password]
- end
+ api.class.default_options[:basic_auth][:username].should == options[:username]
+ api.class.default_options[:basic_auth][:password].should == options[:password]
+ end
- it "uses a port when provided" do
- options = {:host => "host", :port => '1337'}
- api = JenkinsApi.new(options)
+ it "uses a port when provided" do
+ options = {:host => "host", :port => '1337'}
+ api = JenkinsApi.new(options)
- api.class.default_options[:base_uri].should == 'http://host:1337'
- end
+ api.class.default_options[:base_uri].should == 'http://host:1337'
+ end
- end
+ end
- context "when interacting with Jenkins" do
- before(:each) do
- @api = JenkinsApi.new
- end
+ context "when interacting with Jenkins" do
+ before(:each) do
+ @api = JenkinsApi.new
+ end
- it "#get_jobs returns an array of jobs" do
- j = []
- j << {"name" => "Foo"}
- j << {"name" => "Bar"}
+ it "#get_jobs returns an array of jobs" do
+ j = []
+ j << {"name" => "Foo"}
+ j << {"name" => "Bar"}
- results = {"jobs" => j}
+ results = {"jobs" => j}
- @api.class.should_receive(:get).and_return(results)
+ @api.class.should_receive(:get).and_return(results)
- jobs = @api.get_jobs
+ jobs = @api.get_jobs
- jobs.should include "Foo"
- jobs.should include "Bar"
- end
+ jobs.should include "Foo"
+ jobs.should include "Bar"
+ end
- it "#remove_job returns true if a job was deleted successfully" do
- job_name = "foo.test_branch"
+ it "#remove_job returns true if a job was deleted successfully" do
+ job_name = "foo.test_branch"
- @api.class.should_receive(:post).with("/job/#{CGI.escape(job_name)}/doDelete").and_return(true)
+ @api.class.should_receive(:post).with("/job/#{CGI.escape(job_name)}/doDelete").and_return(true)
- @api.remove_job(job_name)
- end
+ @api.remove_job(job_name)
+ end
- it "#build_job returns true and triggers a build for a job" do
- @api.class.should_receive(:get).with("/job/FooJob/build").and_return(true)
+ it "#build_job returns true and triggers a build for a job" do
+ @api.class.should_receive(:get).with("/job/FooJob/build").and_return(true)
- @api.build_job("FooJob")
- end
+ @api.build_job("FooJob")
+ end
- it "#get_job_configuration returns the xml configuration for a job" do
- a = <<XML
+ it "#get_job_configuration returns the xml configuration for a job" do
+ a = <<-XML
<xml>foo</xml>
-XML
- xml = double()
- xml.should_receive(:body).and_return(a)
+ XML
+ xml = double()
+ xml.should_receive(:body).and_return(a)
- @api.class.should_receive(:get).with("/job/FooJob/config.xml", {}).and_return(xml)
+ @api.class.should_receive(:get).with("/job/FooJob/config.xml", {}).and_return(xml)
- @api.get_job_configuration("FooJob").should be(a)
- end
+ @api.get_job_configuration("FooJob").should be(a)
+ end
- it "#create_job_configuration returns a valid job configuration" do
- xml = <<XML
+ it "#create_job_configuration returns a valid job configuration" do
+ xml = <<-XML
<xml><branches><hudson.plugins.git.BranchSpec><name>master</name></hudson.plugins.git.BranchSpec></branches></xml>
-XML
- xml.should_receive(:body).and_return(xml)
- @api.class.should_receive(:get).with('/job/foobar.master/config.xml', {}).and_return(xml)
- @api.create_job_configuration('foobar', 'feature').should =~ /feature/
- end
- end
+ XML
+ xml.should_receive(:body).and_return(xml)
+ @api.class.should_receive(:get).with('/job/foobar.master/config.xml', {}).and_return(xml)
+ @api.create_job_configuration('foobar', 'feature').should =~ /feature/
+ end
+ end
- context "#create_job returns true on the create a job" do
- before(:each) do
- @api = JenkinsApi.new
- end
- it "creates a new job with a given xml configuration" do
+ context "#create_job" do
+ let(:api) { JenkinsApi.new }
+ it "creates a new job with a given xml configuration" do
- a = <<XML
+ a = <<-XML
<xml>foo</xml>
-XML
-
- repo = "FooRepo"
- branch = "master"
- job = "#{repo}.#{branch}"
-
- job = "FooRepo.master"
-
- @api.should_receive(:create_job_configuration).with(repo, branch).and_return(a)
-
- @api.class.should_receive(:post).with("/createItem/api/xml?name=#{job}", {
- :body => a,
- :format => :xml,
- :headers => {"content-type"=>"application/xml" }})
-
- @api.create_job("FooRepo.master")
- end
- end
+ XML
+
+ repo = "FooRepo"
+ branch = "master"
+ job = "#{repo}.#{branch}"
+ api.should_receive(:create_job_configuration).with(repo, branch).and_return(a)
+ api.class.should_receive(:post).with("/createItem/api/xml?name=#{job}",
+ {
+ :body => a,
+ :format => :xml,
+ :headers => {"content-type"=>"application/xml" }
+ })
+
+ api.create_job("FooRepo.master")
+ end
+
+ it "creates a valid job from branches including dots" do
+ a = <<-XML
+<xml>foo</xml>
+ XML
+
+ repo = "FooRepo"
+ branch = "master"
+ repo = "FooRepo"
+ branch = "master.with.dots"
+ job = "#{repo}.#{branch}"
+ api.should_receive(:create_job_configuration).with(repo, branch).and_return(a)
+ api.class.should_receive(:post).with("/createItem/api/xml?name=#{job}",
+ {
+ :body => a,
+ :format => :xml,
+ :headers => {"content-type"=>"application/xml" }
+ })
+
+ api.create_job("FooRepo.master.with.dots")
+ end
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.