Skip to content

Commit

Permalink
add validation tests for default arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyBen committed Dec 19, 2023
1 parent 203c588 commit 836b2ce
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/bashly/config_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ def assert_arg(key, value)
if value['default'].is_a? Array
assert value['repeatable'], "#{key}.default array does not make sense without nub`repeatable`"
end

if value['repeatable'] && value['default']
assert value['default'].is_a?(Array), "#{key}.default must be an array when using nub`repeatable`"
end
end

def assert_flag(key, value)
Expand Down Expand Up @@ -159,6 +163,10 @@ def assert_flag(key, value)
if value['default'].is_a? Array
assert value['repeatable'], "#{key}.default array does not make sense without nub`repeatable`"
end

if value['repeatable'] && value['default']
assert value['default'].is_a?(Array), "#{key}.default must be an array when using nub`repeatable`"
end
end

def assert_env_var(key, value)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#<Bashly::ConfigurationError: root.args[0].default array does not make sense without nub`repeatable`>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#<Bashly::ConfigurationError: root.args[0].default must be an array when using nub`repeatable`>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#<Bashly::ConfigurationError: root.flags[0].default array does not make sense without nub`repeatable`>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#<Bashly::ConfigurationError: root.flags[0].default must be an array when using nub`repeatable`>
36 changes: 36 additions & 0 deletions spec/fixtures/script/validations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@
args:
- name: --user

:arg_default_array_without_repeatable:
name: invalid
help: default cannot be an array without repeatable
args:
- name: path
default:
- spaced file
- other-file

:arg_default_string_with_repeatable:
name: invalid
help: default cannot be a string with repeatable
args:
- name: path
repeatable: true
default: spaced file

:arg_nested_name:
name: invalid
help: last nested arg does not have a name
Expand Down Expand Up @@ -257,6 +274,25 @@
- long: --role
default: admin

:flag_default_array_without_repeatable:
name: invalid
help: default cannot be an array without repeatable
flags:
- long: --path
arg: location
default:
- spaced file
- other-file

:flag_default_string_with_repeatable:
name: invalid
help: default cannot be a string with repeatable
flags:
- long: --path
arg: location
repeatable: true
default: spaced file

:flag_allowed_without_arg:
name: invalid
help: flag must have an arg when using allowed
Expand Down

0 comments on commit 836b2ce

Please sign in to comment.