Skip to content

Commit

Permalink
merging
Browse files Browse the repository at this point in the history
  • Loading branch information
sepulworld committed Jul 23, 2016
2 parents 9c21add + a582e75 commit 73be9e9
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 44 deletions.
4 changes: 3 additions & 1 deletion bin/aptly-cli
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ $debug = false
global_option('-c', '--config FILE', 'Path to YAML config file') do |config_file|
$config_file = config_file
end

global_option('--no-config', 'Don\'t try to read YAML config file') do |config_file|
$config_file = nil
end
global_option('-s', '--server SERVER', 'Host name or IP address of Aptly API server') do |server|
$server = server
end
Expand Down
27 changes: 16 additions & 11 deletions lib/aptly_load.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,23 @@ def configure(opts = {})

# Configure through yaml file
def configure_with(path_to_yaml_file)
begin
config = YAML.load(IO.read(path_to_yaml_file))
rescue Errno::ENOENT
@log.warn(
"YAML configuration file couldn\'t be found at " \
"#{path_to_yaml_file}. Using defaults.")
return @config
rescue Psych::SyntaxError
@log.warn(
'YAML configuration file contains invalid syntax. Using defaults.')
return @config
if path_to_yaml_file
begin
config = YAML.load(IO.read(path_to_yaml_file))
rescue Errno::ENOENT
@log.warn(
"YAML configuration file couldn\'t be found at " \
"#{path_to_yaml_file}. Using defaults.")
return @config
rescue Psych::SyntaxError
@log.warn(
'YAML configuration file contains invalid syntax. Using defaults.')
return @config
end
else
config = {}
end

configure(config)
end
end
Expand Down
12 changes: 6 additions & 6 deletions test/test_aptly_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def password(_prompt)

describe AptlyCli::AptlyCommand do
it 'has a default config' do
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
cmd = AptlyCli::AptlyCommand.new(config)
cmd.config[:proto].must_equal 'http'
cmd.config[:server].must_equal '127.0.0.1'
Expand All @@ -26,7 +26,7 @@ def password(_prompt)

it 'accepts empty options and no config changes' do
options = Options.new
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
cmd = AptlyCli::AptlyCommand.new(config, options)
cmd.config[:proto].must_equal 'http'
cmd.config[:server].must_equal '127.0.0.1'
Expand All @@ -40,7 +40,7 @@ def password(_prompt)
options.username = 'me'
options.password = 'secret'
options.debug = true
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
cmd = AptlyCli::AptlyCommand.new(config, options)
cmd.config[:server].must_equal 'my-server'
cmd.config[:port].must_equal 9000
Expand All @@ -52,15 +52,15 @@ def password(_prompt)
it 'can process an option with \'${PROMPT}\' in it' do
options = Options.new
options.username = '${PROMPT}'
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
cmd = AptlyCli::AptlyCommand.new(config, options)
cmd.config[:username].must_equal 'zane'
end

it 'can process an option with \'${PROMPT_PASSWORD}\' in it' do
options = Options.new
options.username = '${PROMPT_PASSWORD}'
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
cmd = AptlyCli::AptlyCommand.new(config, options)
cmd.config[:username].must_equal 'secret'
end
Expand All @@ -80,7 +80,7 @@ def password(_prompt)
nil,
['Aptly API server at 127.0.0.1:8082', 'marc', 'secret'])
Keyring.stub :new, keyring do
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
cmd = AptlyCli::AptlyCommand.new(config, options)
cmd.config[:username].must_equal 'marc'
cmd.config[:password].must_equal 'secret'
Expand Down
8 changes: 4 additions & 4 deletions test/test_aptly_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require 'aptly_cli'

def post_test_file(location)
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
file_api_setup = AptlyCli::AptlyFile.new(config)
file_api_setup.file_post(
file_uri: location.to_s,
Expand All @@ -27,7 +27,7 @@ def post_test_file(location)
end

describe 'API GET files' do
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
let(:file_api) { AptlyCli::AptlyFile.new(config) }
post_test_file('/testdirfile')

Expand All @@ -43,7 +43,7 @@ def test_file_get_no_file_uri
end

describe 'API DELETE files' do
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
let(:file_api) { AptlyCli::AptlyFile.new(config) }
post_test_file('/testdirfiledelete')

Expand All @@ -55,7 +55,7 @@ def test_file_delete


describe "API POST package files" do
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
let(:api_file) { AptlyCli::AptlyFile.new(config) }
let(:data_for_not_found) { api_file.file_get('test_package_not_here') }

Expand Down
4 changes: 2 additions & 2 deletions test/test_aptly_misc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_config_password_check
end

describe 'API Get graph' do
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
let(:misc_api) { AptlyCli::AptlyMisc.new(config) }

def test_graph_request_for_SVG_returns_200
Expand All @@ -36,7 +36,7 @@ def test_graph_request_for_PNG_returns_200
end

describe 'API Get Version' do
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
let(:misc_api) { AptlyCli::AptlyMisc.new(config) }

def test_version_returns_valid
Expand Down
2 changes: 1 addition & 1 deletion test/test_aptly_package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
end

describe "API List Package" do
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
let(:package_api) { AptlyCli::AptlyPackage.new(config) }

def test_package_show
Expand Down
8 changes: 4 additions & 4 deletions test/test_aptly_publish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
end

describe 'API List Publish' do
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
let(:publish_api) { AptlyCli::AptlyPublish.new(config) }
let(:snapshot_api) { AptlyCli::AptlySnapshot.new(config) }

Expand Down Expand Up @@ -40,7 +40,7 @@ def test_publish_list
end

describe 'API Drop Publish' do
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
let(:publish_api) { AptlyCli::AptlyPublish.new(config) }
let(:snapshot_api) { AptlyCli::AptlySnapshot.new(config) }

Expand All @@ -60,7 +60,7 @@ def test_publish_drop
end

describe 'API Publish Repo' do
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
let(:publish_api) { AptlyCli::AptlyPublish.new(config) }
let(:snapshot_api) { AptlyCli::AptlySnapshot.new(config) }

Expand All @@ -80,7 +80,7 @@ def test_publish_snapshot
end

describe 'API Update Publish Point' do
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
let(:publish_api) { AptlyCli::AptlyPublish.new(config) }
let(:snapshot_api) { AptlyCli::AptlySnapshot.new(config) }

Expand Down
15 changes: 7 additions & 8 deletions test/test_aptly_repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
end

describe 'API Upload to Repo' do
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
let(:repo_api) { AptlyCli::AptlyRepo.new(config) }
let(:file_api) { AptlyCli::AptlyFile.new(config) }

Expand Down Expand Up @@ -45,7 +45,7 @@ def test_repo_upload_fail_response
end

describe 'API Create Repo' do
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
let(:repo_api) { AptlyCli::AptlyRepo.new(config) }

def test_repo_creation
Expand All @@ -61,7 +61,7 @@ def test_repo_creation
end

describe 'API Show Repo' do
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
let(:repo_api) { AptlyCli::AptlyRepo.new(config) }

def test_repo_show
Expand Down Expand Up @@ -94,7 +94,7 @@ def test_repo_show_with_no_name
end

describe 'API Package Query Repo' do
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
let(:repo_api) { AptlyCli::AptlyRepo.new(config) }
let(:file_api) { AptlyCli::AptlyFile.new(config) }

Expand Down Expand Up @@ -173,7 +173,7 @@ def test_package_query_with_no_name
end

describe 'API List Repo' do
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
let(:repo_api) { AptlyCli::AptlyRepo.new(config) }

def test_list_repo_http_response
Expand All @@ -182,7 +182,7 @@ def test_list_repo_http_response
end

describe 'API Edit Repo' do
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
let(:repo_api) { AptlyCli::AptlyRepo.new(config) }

def test_repo_edit_default_distribution
Expand All @@ -203,7 +203,7 @@ def test_repo_edit_default_distribution
end

describe 'API Delete Repo' do
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
let(:repo_api) { AptlyCli::AptlyRepo.new(config) }

def test_repo_delete
Expand All @@ -215,5 +215,4 @@ def test_repo_delete
force: true).to_s, '{}'
end
end

end
14 changes: 7 additions & 7 deletions test/test_aptly_snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
end

describe 'API Delete Snapshot' do
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
let(:snapshot_api) { AptlyCli::AptlySnapshot.new(config) }
let(:publish_api) { AptlyCli::AptlyPublish.new(config) }

Expand Down Expand Up @@ -51,7 +51,7 @@ def test_that_snapshot_delete_returns_200
end

describe 'API Create and List Snapshot' do
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
let(:snapshot_api) { AptlyCli::AptlySnapshot.new(config) }

def test_snapshot_create
Expand All @@ -78,7 +78,7 @@ def test_that_snapshot_list_returns_results
end

describe 'API Update Snapshot' do
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
let(:snapshot_api) { AptlyCli::AptlySnapshot.new(config) }

def test_snapshot_update_name
Expand Down Expand Up @@ -124,7 +124,7 @@ def test_failed_snapshot_show_snapshot_returns_404
end

describe 'API Search Snapshot' do
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
let(:snapshot_api) { AptlyCli::AptlySnapshot.new(config) }

def test_snapshot_search_for_all_with_details
Expand All @@ -151,7 +151,7 @@ def test_snapshot_search_for_specific_package
end

describe 'API Diff Snapshot' do
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
let(:snapshot_api) { AptlyCli::AptlySnapshot.new(config) }

def test_snapshot_diff
Expand All @@ -168,7 +168,7 @@ def test_snapshot_diff
end

describe 'API Show Snapshot' do
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
let(:snapshot_api) { AptlyCli::AptlySnapshot.new(config) }

def test_snapshot_show
Expand All @@ -181,7 +181,7 @@ def test_snapshot_show
end

describe 'API Create Snapshot from Package Refs' do
config = AptlyCli::AptlyLoad.new.configure_with('/no/config')
config = AptlyCli::AptlyLoad.new.configure_with(nil)
let(:snapshot_api) { AptlyCli::AptlySnapshot.new(config) }

def test_snapshot_create_ref
Expand Down

0 comments on commit 73be9e9

Please sign in to comment.