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

Fixes #28176 - Add http-proxy to hammer #454

Merged
merged 1 commit into from
Nov 21, 2019
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
4 changes: 4 additions & 0 deletions lib/hammer_cli_foreman.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ def self.exception_handler_class
'HammerCLIForeman::Hostgroup', 'hammer_cli_foreman/hostgroup'
)

HammerCLI::MainCommand.lazy_subcommand('http-proxy', _("Manipulate http proxies"),
'HammerCLIForeman::HttpProxy', 'hammer_cli_foreman/http_proxy'
)

HammerCLI::MainCommand.lazy_subcommand('location', _("Manipulate locations"),
'HammerCLIForeman::Location', 'hammer_cli_foreman/location'
)
Expand Down
49 changes: 49 additions & 0 deletions lib/hammer_cli_foreman/http_proxy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module HammerCLIForeman

class HttpProxy < HammerCLIForeman::Command

resource :http_proxies

class ListCommand < HammerCLIForeman::ListCommand

output do
field :id, _("Id")
field :name, _("Name")
end

build_options
end

class InfoCommand < HammerCLIForeman::InfoCommand
output ListCommand.output_definition do
field :username, _("Username")
field :url, _("URL")
end

build_options
end

class CreateCommand < HammerCLIForeman::CreateCommand
success_message _("Http proxy created.")
failure_message _("Could not create the http proxy")

build_options
end

class DeleteCommand < HammerCLIForeman::DeleteCommand
success_message _("Http proxy deleted.")
failure_message _("Could not delete the http proxy")

build_options
end

class UpdateCommand < HammerCLIForeman::UpdateCommand
success_message _("Http proxy updated.")
failure_message _("Could not update the http proxy")

build_options
end

autoload_subcommands
end
end
69 changes: 69 additions & 0 deletions test/functional/http_proxy_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
require File.join(File.dirname(__FILE__), 'test_helper')

describe 'httpproxy' do
let(:http_proxy) do
{
:id => 1,
:name => 'proxy1',
:url => 'http://proxy.example.com',
:username => 'user'
}
end

it 'list a http proxy' do
api_expects(:http_proxies, :index, 'List').with_params(
'page' => 1, 'per_page' => 1000
).returns(index_response([http_proxy]))

output = IndexMatcher.new([
['ID', 'NAME'],
['1', 'proxy1']
])
expected_result = success_result(output)

result = run_cmd(%w(http-proxy list))
assert_cmd(expected_result, result)
end

it 'updates an http proxy' do
params = ['--id', http_proxy[:id],
'--password', 'katello']
api_expects(:http_proxies, :update, params)
.returns(http_proxy)

expected_result = success_result("Http proxy updated.\n")

result = run_cmd(%w(http-proxy update --id 1 --password katello))
assert_cmd(expected_result, result)
end

it 'shows info on an http proxy' do
params = ['--id', http_proxy[:id]]
api_expects(:http_proxies, :show, params)
.returns(http_proxy)
expected_result = success_result("Id: 1\nName: proxy1\nUsername: user\nURL: http://proxy.example.com\n\n")
result = run_cmd(%w(http-proxy info --id 1))
assert_cmd(expected_result, result)
end

it 'creates an http proxy' do
params = ['--url', http_proxy[:key],
'--name', http_proxy[:name],
'--password', 'foreman',
'--username', http_proxy[:username]]
api_expects(:http_proxies, :create, params)
.returns(http_proxy)

expected_result = success_result("Http proxy created.\n")

result = run_cmd(%w(http-proxy create --url "http://proxy.example.com" --name proxy1 --username user --password foreman))
assert_cmd(expected_result, result)
end

it 'deletes an http proxy' do
expected_result = success_result("Http proxy deleted.\n")

result = run_cmd(%w(http-proxy delete --id 1))
assert_cmd(expected_result, result)
end
end