-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added spec test for setting ci address and list all j jobs name in je…
…nkins.
- Loading branch information
Showing
7 changed files
with
73 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
.bundle | ||
Gemfile.lock | ||
pkg/* | ||
doc/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rvm --create use ree-1.8.7@jenkins-remote-api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
Dir[File.dirname(__FILE__) + '/jenkins-remote-api/*.rb'].each {|file| require file } | ||
require 'mechanize' | ||
require 'libxml' | ||
Dir[File.dirname(__FILE__) + '/jenkins-remote-api/api/*.rb'].each {|file| require file } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Api | ||
class Jenkins | ||
include LibXML | ||
|
||
def self.set_ci_addr(url) | ||
@@ci_addr = url.end_with?("/") ? url : url + "/" | ||
end | ||
|
||
def self.ci_addr | ||
@@ci_addr | ||
end | ||
|
||
def self.list_all_job_names | ||
xml = "" | ||
Mechanize.new.get(ci_addr + "api/xml") do |page| | ||
xml = page.body | ||
end | ||
parser = LibXML::XML::Parser.string(xml) | ||
doc = parser.parse | ||
doc.find('//job').collect{|job| job.find_first('name').content } | ||
end | ||
end | ||
end | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,45 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper') | ||
|
||
describe Jenkins do | ||
it "should works as first spec" do | ||
Jenkins.first_spec_status.should == "hello world" | ||
describe Api::Jenkins do | ||
|
||
it "should set Jenkins ci address" do | ||
Api::Jenkins.set_ci_addr("http://some_ci_address:8080/") | ||
Api::Jenkins.ci_addr.should == "http://some_ci_address:8080/" | ||
end | ||
end | ||
|
||
it "should set Jenkins ci address end with slash" do | ||
Api::Jenkins.set_ci_addr("http://some_ci_address:8080") | ||
Api::Jenkins.ci_addr.should == "http://some_ci_address:8080/" | ||
end | ||
|
||
it "should get all job's names for specific ci" do | ||
ci_addr = "http://deadlock.netbeans.org/hudson/" | ||
Api::Jenkins.set_ci_addr(ci_addr) | ||
mechanize = mock("Mechanize") | ||
Mechanize.stub(:new).and_return(mechanize) | ||
xml = <<EOF | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<hudson> | ||
<assignedLabel/> | ||
<mode>NORMAL</mode> | ||
<nodeDescription>the master Hudson node</nodeDescription> | ||
<job> | ||
<name>analytics-server</name> | ||
<url> | ||
http://deadlock.netbeans.org/hudson/job/analytics-server/ | ||
</url> | ||
<color>disabled</color> | ||
</job> | ||
<job> | ||
<name>apitest</name> | ||
<url>http://deadlock.netbeans.org/hudson/job/apitest/</url> | ||
<color>blue</color> | ||
</job> | ||
</hudson> | ||
EOF | ||
result = mock("some xml ouput") | ||
result.stub(:body).and_return(xml) | ||
mechanize.should_receive(:get).with(ci_addr + "api/xml").and_yield(result) | ||
Api::Jenkins.list_all_job_names.should == ["analytics-server", "apitest"] | ||
end | ||
end |