Skip to content

Commit

Permalink
Puppet generator fixes (#46)
Browse files Browse the repository at this point in the history
* puppet code generator fixes

* fix unit tests
  • Loading branch information
andreas-stuerz authored Apr 3, 2023
1 parent 1a97e50 commit ce8926c
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 24 deletions.
3 changes: 2 additions & 1 deletion opnsense_cli/templates/code_generator/puppet/provider.rb.j2
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Puppet::Provider::{{ provider_class_name }}::{{ provider_class_name }} < P
{% for line in vars.translate_json_object_to_puppet_resource -%}
{{ line }}
{% endfor %}
ensure: 'present',
}
end

Expand All @@ -33,7 +34,7 @@ class Puppet::Provider::{{ provider_class_name }}::{{ provider_class_name }} < P
# @param [Hash<Symbol>] puppet_resource
# @return [Array<String>]
def _translate_puppet_resource_to_command_args(mode, id, puppet_resource)
args = [@group, @command, mode, id]
args = mode == 'create' ? [@group, @command, mode] : [@group, @command, mode, id]

{% for line in vars.translate_puppet_resource_to_command_args -%}
{{ line }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ RSpec.describe Puppet::Provider::{{ provider_class_name }}::{{ provider_class_na
{% for line in vars.ruby_hash -%}
{{ line }}
{% endfor %}
uuid: '731cb3ca-3b76-4177-b736-4381c6525f45',
ensure: 'present'
},
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ RSpec.describe 'the {{ provider_name }} type' do
it 'requires a title' do
expect {
Puppet::Type.type(:{{ provider_name }}).new({})
}.to raise_error(Puppet::Error, 'Title must be provided')
}.to raise_error(Puppet::Error, 'Title or name must be provided')
end

context 'example {{ vars.click_group }} {{ vars.click_command }} on opnsense.example.com' do
let(:{{ unit_under_test }}) do
Puppet::Type.type(:{{ provider_name }}).new(
name: 'example {{ vars.click_group }} {{ vars.click_command }}',
device: 'opnsense.example.com',
{% for line in vars.new_resource -%}
{{ line }}
Expand Down
20 changes: 10 additions & 10 deletions opnsense_cli/tests/commands/new/test_new_puppet.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,36 +188,36 @@ def _test_type_test_file_content(self, file_content):

self.assertIn(
" it 'accepts name' do\n"
" haproxy_{click_command}[:name] = 'a todo string'\n"
" expect(haproxy_{click_command}[:name]).to eq('a todo string')\n"
" haproxy_frontend[:name] = 'a todo string'\n"
" expect(haproxy_frontend[:name]).to eq('a todo string')\n"
" end\n\n",
file_content
)
self.assertIn(
" it 'accepts mode' do\n"
" haproxy_{click_command}[:mode] = 'a valid TODO choice'\n"
" expect(haproxy_{click_command}[:mode]).to eq('a valid TODO choice')\n"
" haproxy_frontend[:mode] = 'a valid TODO choice'\n"
" expect(haproxy_frontend[:mode]).to eq('a valid TODO choice')\n"
" end\n\n",
file_content
)
self.assertIn(
" it 'accepts ssl_enabled' do\n"
" haproxy_{click_command}[:ssl_enabled] = false\n"
" expect(haproxy_{click_command}[:ssl_enabled]).to eq(:false)\n"
" haproxy_frontend[:ssl_enabled] = false\n"
" expect(haproxy_frontend[:ssl_enabled]).to eq(:false)\n"
" end\n\n",
file_content
)
self.assertIn(
" it 'accepts ssl_bindoptions' do\n"
" haproxy_{click_command}[:ssl_bindoptions] = 'a valid TODO choice'\n"
" expect(haproxy_{click_command}[:ssl_bindoptions]).to eq('a valid TODO choice')\n"
" haproxy_frontend[:ssl_bindoptions] = ['valid_TODO_choice', 'another_valid_TODO_choice']\n"
" expect(haproxy_frontend[:ssl_bindoptions]).to eq(['valid_TODO_choice', 'another_valid_TODO_choice'])\n"
" end\n\n",
file_content
)
self.assertIn(
" it 'accepts ssl_certificates' do\n"
" haproxy_{click_command}[:ssl_certificates] = ['valid item1', 'valid item2']\n"
" expect(haproxy_{click_command}[:ssl_certificates]).to eq(['valid item1', 'valid item2'])\n"
" haproxy_frontend[:ssl_certificates] = ['valid item1', 'valid item2']\n"
" expect(haproxy_frontend[:ssl_certificates]).to eq(['valid item1', 'valid item2'])\n"
" end\n\n",
file_content
)
Expand Down
4 changes: 2 additions & 2 deletions opnsense_cli/types/puppet/puppet_boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class PuppetBoolean(PuppetCodeFragment):

TEMPLATE_TYPE_UNIT_TEST_accepts_parameter = '''
it 'accepts ${name}' do
${click_group}_{click_command}[:${name}] = false
expect(${click_group}_{click_command}[:${name}]).to eq(:false)
${click_group}_${click_command}[:${name}] = false
expect(${click_group}_${click_command}[:${name}]).to eq(:false)
end
'''

Expand Down
4 changes: 2 additions & 2 deletions opnsense_cli/types/puppet/puppet_choice.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class PuppetChoice(PuppetCodeFragment):

TEMPLATE_TYPE_UNIT_TEST_accepts_parameter = '''
it 'accepts ${name}' do
${click_group}_{click_command}[:${name}] = 'a valid TODO choice'
expect(${click_group}_{click_command}[:${name}]).to eq('a valid TODO choice')
${click_group}_${click_command}[:${name}] = 'a valid TODO choice'
expect(${click_group}_${click_command}[:${name}]).to eq('a valid TODO choice')
end
'''

Expand Down
4 changes: 2 additions & 2 deletions opnsense_cli/types/puppet/puppet_choice_multiple.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class PuppetChoiceMultiple(PuppetCodeFragment):

TEMPLATE_TYPE_UNIT_TEST_accepts_parameter = '''
it 'accepts ${name}' do
${click_group}_{click_command}[:${name}] = 'a valid TODO choice'
expect(${click_group}_{click_command}[:${name}]).to eq('a valid TODO choice')
${click_group}_${click_command}[:${name}] = ['valid_TODO_choice', 'another_valid_TODO_choice']
expect(${click_group}_${click_command}[:${name}]).to eq(['valid_TODO_choice', 'another_valid_TODO_choice'])
end
'''

Expand Down
4 changes: 2 additions & 2 deletions opnsense_cli/types/puppet/puppet_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class PuppetCsv(PuppetCodeFragment):

TEMPLATE_TYPE_UNIT_TEST_accepts_parameter = '''
it 'accepts ${name}' do
${click_group}_{click_command}[:${name}] = ['valid item1', 'valid item2']
expect(${click_group}_{click_command}[:${name}]).to eq(['valid item1', 'valid item2'])
${click_group}_${click_command}[:${name}] = ['valid item1', 'valid item2']
expect(${click_group}_${click_command}[:${name}]).to eq(['valid item1', 'valid item2'])
end
'''

Expand Down
4 changes: 2 additions & 2 deletions opnsense_cli/types/puppet/puppet_integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class PuppetInteger(PuppetCodeFragment):

TEMPLATE_TYPE_UNIT_TEST_accepts_parameter = '''
it 'accepts ${name}' do
${click_group}_{click_command}[:${name}] = 'a todo integer'
expect(${click_group}_{click_command}[:${name}]).to eq('a todo integer')
${click_group}_${click_command}[:${name}] = 'a todo integer'
expect(${click_group}_${click_command}[:${name}]).to eq('a todo integer')
end
'''

Expand Down
4 changes: 2 additions & 2 deletions opnsense_cli/types/puppet/puppet_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class PuppetString(PuppetCodeFragment):

TEMPLATE_TYPE_UNIT_TEST_accepts_parameter = '''
it 'accepts ${name}' do
${click_group}_{click_command}[:${name}] = 'a todo string'
expect(${click_group}_{click_command}[:${name}]).to eq('a todo string')
${click_group}_${click_command}[:${name}] = 'a todo string'
expect(${click_group}_${click_command}[:${name}]).to eq('a todo string')
end
'''

Expand Down

0 comments on commit ce8926c

Please sign in to comment.