Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for is_offline? bug reporting all nodes as being offline #165

Merged
merged 5 commits into from
Apr 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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