From 9cd6f36a38eaabde540136a0004d020807bf3b2d Mon Sep 17 00:00:00 2001 From: Ben Snape Date: Wed, 7 Jan 2015 12:10:20 +0000 Subject: [PATCH 1/4] added unit tests that replicate incorrect #is_offline? behaviour --- spec/unit_tests/node_spec.rb | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/spec/unit_tests/node_spec.rb b/spec/unit_tests/node_spec.rb index b3a696dd..757b4b9a 100644 --- a/spec/unit_tests/node_spec.rb +++ b/spec/unit_tests/node_spec.rb @@ -12,6 +12,18 @@ "displayName" => "slave" ] } + @offline_slave = { + "computer" => [ + "displayName" => "slave", + "offline" => true, + ] + } + @online_slave = { + "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__) @@ -160,6 +172,26 @@ 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 + end + describe "NodeAttributes" do node_attributes = JenkinsApi::Client::Node::NODE_ATTRIBUTES node_attributes.each do |attribute| From 1aed6107ec1e029546a2e597d9091193037e000d Mon Sep 17 00:00:00 2001 From: Ben Snape Date: Wed, 7 Jan 2015 13:56:09 +0000 Subject: [PATCH 2/4] correctly returning the boolean values of node properties --- lib/jenkins_api_client/node.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/jenkins_api_client/node.rb b/lib/jenkins_api_client/node.rb index fc13b323..1caef042 100644 --- a/lib/jenkins_api_client/node.rb +++ b/lib/jenkins_api_client/node.rb @@ -255,8 +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 =~ /False/i ? false : true + response_json["computer"][index(node_name)]["#{meth_suffix}"] end end From f95b95cea81892dbd6bfd454d72420abb53006ed Mon Sep 17 00:00:00 2001 From: Steven Lu Date: Fri, 27 Mar 2015 11:37:56 -0700 Subject: [PATCH 3/4] Restoring node property methods to its original logic, but handles both bool and string case --- lib/jenkins_api_client/node.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/jenkins_api_client/node.rb b/lib/jenkins_api_client/node.rb index 1caef042..872fcd80 100644 --- a/lib/jenkins_api_client/node.rb +++ b/lib/jenkins_api_client/node.rb @@ -255,7 +255,8 @@ 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") - 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 From c233856e0d9e444f791946aee99f78376e56e5d3 Mon Sep 17 00:00:00 2001 From: Steven Lu Date: Fri, 27 Mar 2015 13:48:49 -0700 Subject: [PATCH 4/4] Add test for is_offline? in string value --- spec/unit_tests/node_spec.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/spec/unit_tests/node_spec.rb b/spec/unit_tests/node_spec.rb index 757b4b9a..f62252cd 100644 --- a/spec/unit_tests/node_spec.rb +++ b/spec/unit_tests/node_spec.rb @@ -24,6 +24,18 @@ "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__) @@ -190,6 +202,24 @@ ) @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