Skip to content

Commit

Permalink
Merge pull request #165 from bsnape/is_offline_bug
Browse files Browse the repository at this point in the history
Fix for is_offline? bug reporting all nodes as being offline
  • Loading branch information
arangamani committed Apr 3, 2015
2 parents 6170812 + e0f99c2 commit 36e88f5
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/jenkins_api_client/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def index(node_name)
define_method("is_#{meth_suffix}?") do |node_name|
@logger.info "Obtaining '#{meth_suffix}' property of '#{node_name}'"
response_json = @client.api_get_request("/computer")
resp = response_json["computer"][index(node_name)]["#{meth_suffix}"]
resp = response_json["computer"][index(node_name)]["#{meth_suffix}"].to_s
resp =~ /False/i ? false : true
end
end
Expand Down
62 changes: 62 additions & 0 deletions spec/unit_tests/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,30 @@
"displayName" => "slave"
]
}
@offline_slave = {
"computer" => [
"displayName" => "slave",
"offline" => true,
]
}
@online_slave = {
"computer" => [
"displayName" => "slave",
"offline" => false,
]
}
@offline_slave_in_string = {
"computer" => [
"displayName" => "slave",
"offline" => "true",
]
}
@online_slave_in_string = {
"computer" => [
"displayName" => "slave",
"offline" => "false",
]
}
computer_sample_xml_filename = '../fixtures/files/computer_sample.xml'
@sample_computer_xml = File.read(
File.expand_path(computer_sample_xml_filename , __FILE__)
Expand Down Expand Up @@ -160,6 +184,44 @@
end
end

describe 'is_offline?' do
it "returns true if the node is offline" do
@client.should_receive(
:api_get_request
).twice.and_return(
@offline_slave
)
@node.method("is_offline?").call("slave").should be_true
end

it "returns false if the node is online" do
@client.should_receive(
:api_get_request
).twice.and_return(
@online_slave
)
@node.method("is_offline?").call("slave").should be_false
end

it "returns false if the node is online and have a string value on its attr" do
@client.should_receive(
:api_get_request
).twice.and_return(
@offline_slave_in_string
)
@node.method("is_offline?").call("slave").should be_true
end

it "returns false if the node is online and have a string value on its attr" do
@client.should_receive(
:api_get_request
).twice.and_return(
@online_slave_in_string
)
@node.method("is_offline?").call("slave").should be_false
end
end

describe "NodeAttributes" do
node_attributes = JenkinsApi::Client::Node::NODE_ATTRIBUTES
node_attributes.each do |attribute|
Expand Down

0 comments on commit 36e88f5

Please sign in to comment.