File tree Expand file tree Collapse file tree
lib/octocatalog-diff/cli/options
spec/octocatalog-diff/tests/cli/options Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ # Specify a timeout for retrieving a catalog from a Puppet master / Puppet server.
4+ # This timeout is specified in seconds.
5+ # @param parser [OptionParser object] The OptionParser argument
6+ # @param options [Hash] Options hash being constructed; this is modified in this method.
7+ OctocatalogDiff ::Cli ::Options ::Option . newoption ( :puppet_master_timeout ) do
8+ has_weight 329
9+
10+ def parse ( parser , options )
11+ OctocatalogDiff ::Cli ::Options . option_globally_or_per_branch (
12+ parser : parser ,
13+ options : options ,
14+ cli_name : 'puppet-master-timeout' ,
15+ option_name : 'puppet_master_timeout' ,
16+ desc : 'Puppet Master catalog retrieval timeout in seconds' ,
17+ validator : -> ( x ) { x . to_i > 0 || raise ( ArgumentError , 'Specify timeout as a integer greater than 0' ) } ,
18+ translator : -> ( x ) { x . to_i }
19+ )
20+ end
21+ end
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ require_relative '../options_helper'
4+
5+ describe OctocatalogDiff ::Cli ::Options do
6+ describe '#opt_puppet_master_timeout' do
7+ it 'should handle --puppet-master-timeout with timeout as a string' do
8+ result = run_optparse ( [ '--puppet-master-timeout' , '20' ] )
9+ expect ( result [ :to_puppet_master_timeout ] ) . to eq ( 20 )
10+ expect ( result [ :from_puppet_master_timeout ] ) . to eq ( 20 )
11+ end
12+
13+ it 'should raise error if --puppet-master-timeout == 0' do
14+ expect do
15+ run_optparse ( [ '--puppet-master-timeout' , '0' ] )
16+ end . to raise_error ( ArgumentError , 'Specify timeout as a integer greater than 0' )
17+ end
18+
19+ it 'should raise error if --puppet-master-timeout evaluates to 0' do
20+ expect do
21+ run_optparse ( [ '--puppet-master-timeout' , 'chickens' ] )
22+ end . to raise_error ( ArgumentError , 'Specify timeout as a integer greater than 0' )
23+ end
24+
25+ it 'should handle --to-puppet-master-timeout' do
26+ result = run_optparse ( [ '--to-puppet-master-timeout' , '3' ] )
27+ expect ( result [ :to_puppet_master_timeout ] ) . to eq ( 3 )
28+ end
29+
30+ it 'should handle --from-puppet-master-timeout' do
31+ result = run_optparse ( [ '--from-puppet-master-timeout' , '3' ] )
32+ expect ( result [ :from_puppet_master_timeout ] ) . to eq ( 3 )
33+ end
34+ end
35+ end
You can’t perform that action at this time.
0 commit comments