Skip to content

Commit

Permalink
Merge pull request #141 from cynipe/fix-typo
Browse files Browse the repository at this point in the history
create_dump_slave -> create_dumb_slave
  • Loading branch information
arangamani committed Jun 20, 2014
2 parents 9ab1d0f + 5dfc79e commit f7ea5cf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 21 deletions.
17 changes: 11 additions & 6 deletions lib/jenkins_api_client/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def to_s

# Creates a new node with the specified parameters
#
# @param [Hash] params parameters for creating a dump slave
# @param [Hash] params parameters for creating a dumb slave
# * +:name+ name of the slave
# * +:description+ description of the new slave
# * +:executors+ number of executors
Expand All @@ -118,23 +118,23 @@ def to_s
# * +:private_key_file+ Private key file of master
# * +:credentials_id+ Id for credential in Jenkins
#
# @example Create a Dump Slave
# create_dump_slave(
# @example Create a Dumb Slave
# create_dumb_slave(
# :name => "slave1",
# :slave_host => "10.10.10.10",
# :private_key_file => "/root/.ssh/id_rsa",
# :executors => 10,
# :labels => "slave, ruby"
# )
#
def create_dump_slave(params)
def create_dumb_slave(params)
unless params[:name] && params[:slave_host] && params[:private_key_file]
raise ArgumentError, "Name, slave host, and private key file are" +
" required for creating a slave."
end

@logger.info "Creating a dump slave '#{params[:name]}'"
@logger.debug "Creating a dump slave with params: #{params.inspect}"
@logger.info "Creating a dumb slave '#{params[:name]}'"
@logger.debug "Creating a dumb slave with params: #{params.inspect}"
default_params = {
:description => "Automatically created through jenkins_api_client",
:executors => 2,
Expand Down Expand Up @@ -182,6 +182,11 @@ def create_dump_slave(params)
@client.api_post_request("/computer/doCreateItem", post_params)
end

def create_dump_slave(params)
@logger.warn '[DEPRECATED] Please use create_dumb_slave instead.'
create_dumb_slave(params)
end

# Deletes the specified node
#
# @param [String] node_name Name of the node to delete
Expand Down
18 changes: 9 additions & 9 deletions spec/func_tests/node_spec.rb.pending
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe JenkinsApi::Client::Node do
puts e.message
end

@client.node.create_dump_slave(
@client.node.create_dumb_slave(
:name => "slave",
:slave_host => "10.0.0.1",
:private_key_file => "/root/.ssh/id_rsa"
Expand All @@ -43,12 +43,12 @@ describe JenkinsApi::Client::Node do
end
end

describe "#create_dump_slave" do
describe "#create_dumb_slave" do

def test_and_validate(params)
name = params[:name]
@valid_post_responses.should include(
@client.node.create_dump_slave(params).to_i
@client.node.create_dumb_slave(params).to_i
)
@client.node.list(name).include?(name).should be_true
@valid_post_responses.should include(
Expand Down Expand Up @@ -79,7 +79,7 @@ describe JenkinsApi::Client::Node do
:private_key_file => "/root/.ssh/id_rsa"
}
expect(
lambda{ @client.node.create_dump_slave(params) }
lambda{ @client.node.create_dumb_slave(params) }
).to raise_error(ArgumentError)
end
it "fails if slave_host is missing" do
Expand All @@ -88,7 +88,7 @@ describe JenkinsApi::Client::Node do
:private_key_file => "/root/.ssh/id_rsa"
}
expect(
lambda{ @client.node.create_dump_slave(params) }
lambda{ @client.node.create_dumb_slave(params) }
).to raise_error(ArgumentError)
end
it "fails if private_key_file is missing" do
Expand All @@ -97,7 +97,7 @@ describe JenkinsApi::Client::Node do
:slave_host => "10.10.10.10"
}
expect(
lambda{ @client.node.create_dump_slave(params) }
lambda{ @client.node.create_dumb_slave(params) }
).to raise_error(ArgumentError)
end
it "fails if the slave already exists in Jenkins" do
Expand All @@ -107,10 +107,10 @@ describe JenkinsApi::Client::Node do
:private_key_file => "/root/.ssh/id_rsa"
}
@valid_post_responses.should include(
@client.node.create_dump_slave(params).to_i
@client.node.create_dumb_slave(params).to_i
)
expect(
lambda{ @client.node.create_dump_slave(params) }
lambda{ @client.node.create_dumb_slave(params) }
).to raise_error(JenkinsApi::Exceptions::NodeAlreadyExists)
@valid_post_responses.should include(
@client.node.delete(params[:name]).to_i
Expand All @@ -126,7 +126,7 @@ describe JenkinsApi::Client::Node do
:private_key_file => "/root/.ssh/id_rsa"
}
@valid_post_responses.should include(
@client.node.create_dump_slave(params).to_i
@client.node.create_dumb_slave(params).to_i
)
@valid_post_responses.should include(
@client.node.delete(params[:name]).to_i
Expand Down
24 changes: 18 additions & 6 deletions spec/unit_tests/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
end
end

describe "#create_dump_slave" do
it "creates a dump slave by accepting required params" do
describe "#create_dumb_slave" do
it "creates a dumb slave by accepting required params" do
@client.should_receive(:api_post_request).and_return("302")
@node.create_dump_slave(
@node.create_dumb_slave(
:name => "test_slave",
:slave_host => "10.10.10.10",
:private_key_file => "/root/.ssh/id_rsa"
Expand All @@ -42,7 +42,7 @@
it "fails if name is not given" do
expect(
lambda{
@node.create_dump_slave(
@node.create_dumb_slave(
:slave_host => "10.10.10.10",
:private_key_file => "/root/.ssh/id_rsa"
)
Expand All @@ -52,7 +52,7 @@
it "fails if slave_host is not given" do
expect(
lambda{
@node.create_dump_slave(
@node.create_dumb_slave(
:name => "test_slave",
:private_key_file => "/root/.ssh/id_rsa"
)
Expand All @@ -62,7 +62,7 @@
it "fails if private_key_file is not given" do
expect(
lambda{
@node.create_dump_slave(
@node.create_dumb_slave(
:name => "test_slave",
:slave_host => "10.10.10.10"
)
Expand All @@ -71,6 +71,18 @@
end
end

describe "#create_dump_slave" do

it "just delegates to #create_dumb_slave" do
@node.should_receive(:create_dumb_slave)
@node.create_dump_slave(
:name => "test_slave",
:slave_host => "10.10.10.10",
:private_key_file => "/root/.ssh/id_rsa"
)
end

end
describe "#delete" do
it "gets the node name and deletes if exists" do
slave_name = "slave"
Expand Down

0 comments on commit f7ea5cf

Please sign in to comment.