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

Fix rendering of nested hash inside array #96

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions spec/defines/virtualhost_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
context 'with deeply nested component options' do
let(:params) { { components: { 'comp1' => { 'type' => 'muc', 'options' => { 'bo' => true, 'arr' => %w[one two], 'str' => 'string' } } } } }

it {

Check failure on line 115 in spec/defines/virtualhost_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

prosody::virtualhost on os debian-11-x86_64 with deeply nested component options is expected to contain File[/etc/prosody/conf.avail/mockvirtualhost.cfg.lua] with content =~ /^Component "comp1" "muc"$/, content =~ /^ bo = true;$/, content =~ /^ arr = { "one"; "two" };$/ and content =~ /^ str = "string";$/ Failure/Error: is_expected.to contain_file(path_avail). \ with_content(%r{^Component "comp1" "muc"$}). \ with_content(%r{^ bo = true;$}). \ with_content(%r{^ arr = { "one"; "two" };$}). \ with_content(%r{^ str = "string";$}) expected that the catalogue would contain File[/etc/prosody/conf.avail/mockvirtualhost.cfg.lua] with content set to /^ arr = { "one"; "two" };$/ but it is set to "VirtualHost \"mockvirtualhost\"\n enabled = true\n\n\n\n------ Components ------\n-- You can specify components to add hosts that provide special services,\n-- like multi-user conferences, and transports.\n-- For more information on components, see http://prosody.im/doc/components\n\n\nComponent \"comp1\" \"muc\"\n arr = {\n \"one\"; \"two\"\n};\n bo = true;\n str = \"string\";\n" Diff: @@ -1,17 +1,33 @@ -(?-mix:^ arr = { "one"; "two" };$) +VirtualHost "mockvirtualhost" + enabled = true + + + +------ Components ------ +-- You can specify components to add hosts that provide special services, +-- like multi-user conferences, and transports. +-- For more information on components, see http://prosody.im/doc/components + + +Component "comp1" "muc" + arr = { + "one"; "two" +}; + bo = true; + str = "string";

Check failure on line 115 in spec/defines/virtualhost_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 8 (Ruby 3.2)

prosody::virtualhost on os ubuntu-20.04-x86_64 with deeply nested component options is expected to contain File[/etc/prosody/conf.avail/mockvirtualhost.cfg.lua] with content =~ /^Component "comp1" "muc"$/, content =~ /^ bo = true;$/, content =~ /^ arr = { "one"; "two" };$/ and content =~ /^ str = "string";$/ Failure/Error: is_expected.to contain_file(path_avail). \ with_content(%r{^Component "comp1" "muc"$}). \ with_content(%r{^ bo = true;$}). \ with_content(%r{^ arr = { "one"; "two" };$}). \ with_content(%r{^ str = "string";$}) expected that the catalogue would contain File[/etc/prosody/conf.avail/mockvirtualhost.cfg.lua] with content set to /^ arr = { "one"; "two" };$/ but it is set to "VirtualHost \"mockvirtualhost\"\n enabled = true\n\n\n\n------ Components ------\n-- You can specify components to add hosts that provide special services,\n-- like multi-user conferences, and transports.\n-- For more information on components, see http://prosody.im/doc/components\n\n\nComponent \"comp1\" \"muc\"\n arr = {\n \"one\"; \"two\"\n};\n bo = true;\n str = \"string\";\n" Diff: @@ -1,17 +1,33 @@ -(?-mix:^ arr = { "one"; "two" };$) +VirtualHost "mockvirtualhost" + enabled = true + + + +------ Components ------ +-- You can specify components to add hosts that provide special services, +-- like multi-user conferences, and transports. +-- For more information on components, see http://prosody.im/doc/components + + +Component "comp1" "muc" + arr = { + "one"; "two" +}; + bo = true; + str = "string";

Check failure on line 115 in spec/defines/virtualhost_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

prosody::virtualhost on os ubuntu-20.04-x86_64 with deeply nested component options is expected to contain File[/etc/prosody/conf.avail/mockvirtualhost.cfg.lua] with content =~ /^Component "comp1" "muc"$/, content =~ /^ bo = true;$/, content =~ /^ arr = { "one"; "two" };$/ and content =~ /^ str = "string";$/ Failure/Error: is_expected.to contain_file(path_avail). \ with_content(%r{^Component "comp1" "muc"$}). \ with_content(%r{^ bo = true;$}). \ with_content(%r{^ arr = { "one"; "two" };$}). \ with_content(%r{^ str = "string";$}) expected that the catalogue would contain File[/etc/prosody/conf.avail/mockvirtualhost.cfg.lua] with content set to /^ arr = { "one"; "two" };$/ but it is set to "VirtualHost \"mockvirtualhost\"\n enabled = true\n\n\n\n------ Components ------\n-- You can specify components to add hosts that provide special services,\n-- like multi-user conferences, and transports.\n-- For more information on components, see http://prosody.im/doc/components\n\n\nComponent \"comp1\" \"muc\"\n arr = {\n \"one\"; \"two\"\n};\n bo = true;\n str = \"string\";\n" Diff: @@ -1,17 +1,33 @@ -(?-mix:^ arr = { "one"; "two" };$) +VirtualHost "mockvirtualhost" + enabled = true + + + +------ Components ------ +-- You can specify components to add hosts that provide special services, +-- like multi-user conferences, and transports. +-- For more information on components, see http://prosody.im/doc/components + + +Component "comp1" "muc" + arr = { + "one"; "two" +}; + bo = true; + str = "string";

Check failure on line 115 in spec/defines/virtualhost_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / 7 (Ruby 2.7)

prosody::virtualhost on os debian-11-x86_64 with deeply nested component options is expected to contain File[/etc/prosody/conf.avail/mockvirtualhost.cfg.lua] with content =~ /^Component "comp1" "muc"$/, content =~ /^ bo = true;$/, content =~ /^ arr = { "one"; "two" };$/ and content =~ /^ str = "string";$/ Failure/Error: is_expected.to contain_file(path_avail). \ with_content(%r{^Component "comp1" "muc"$}). \ with_content(%r{^ bo = true;$}). \ with_content(%r{^ arr = { "one"; "two" };$}). \ with_content(%r{^ str = "string";$}) expected that the catalogue would contain File[/etc/prosody/conf.avail/mockvirtualhost.cfg.lua] with content set to /^ arr = { "one"; "two" };$/ but it is set to "VirtualHost \"mockvirtualhost\"\n enabled = true\n\n\n\n------ Components ------\n-- You can specify components to add hosts that provide special services,\n-- like multi-user conferences, and transports.\n-- For more information on components, see http://prosody.im/doc/components\n\n\nComponent \"comp1\" \"muc\"\n arr = {\n \"one\"; \"two\"\n};\n bo = true;\n str = \"string\";\n" Diff: @@ -1,17 +1,33 @@ -(?-mix:^ arr = { "one"; "two" };$) +VirtualHost "mockvirtualhost" + enabled = true + + + +------ Components ------ +-- You can specify components to add hosts that provide special services, +-- like multi-user conferences, and transports. +-- For more information on components, see http://prosody.im/doc/components + + +Component "comp1" "muc" + arr = { + "one"; "two" +}; + bo = true; + str = "string";
is_expected.to contain_file(path_avail). \
with_content(%r{^Component "comp1" "muc"$}). \
with_content(%r{^ bo = true;$}). \
Expand All @@ -121,6 +121,15 @@
}
end

context 'with nested array and hash custom options' do
let(:params) { { custom_options: { external_services: [{ 'type' => 'turns', 'algorithm' => 'turn' }] } } }

it {
is_expected.to contain_file(path_avail). \
with_content(%r#^external_services = {\n {\n type = "turns";\n algorithm = "turn";\n }\n}#)
}
end

context 'with disco items' do
let(:params) { { disco_items: %w[foo bar] } }

Expand Down
2 changes: 1 addition & 1 deletion templates/prosody.cfg.erb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ s2s_secure_domains = {
def print_recursive(object, indentation = 0)
case object
when Array
'{ "' + object.join('"; "') + '" }'
"{\n" + ' ' * (indentation + 2) + object.map {|v| print_recursive(v, indentation + 2)}.join('; ') + "\n" + (' ' * indentation) + '}'
when Hash
"{\n" + ' ' * (indentation + 2) + object.map {|k,v| "#{k} = " + print_recursive(v, indentation + 2)}.join(";\n" + ' ' * (indentation + 2)) + ";\n" + (' ' * indentation) + '}'
when TrueClass, FalseClass
Expand Down
2 changes: 1 addition & 1 deletion templates/virtualhost.cfg.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ VirtualHost "<%= @name %>"
def print_recursive(object, indentation = 0)
case object
when Array
'{ "' + object.join('"; "') + '" }'
"{\n" + ' ' * (indentation + 2) + object.map {|v| print_recursive(v, indentation + 2)}.join('; ') + "\n" + (' ' * indentation) + '}'
when Hash
"{\n" + ' ' * (indentation + 2) + object.map {|k,v| "#{k} = " + print_recursive(v, indentation + 2)}.join(";\n" + ' ' * (indentation + 2)) + ";\n" + (' ' * indentation) + '}'
when TrueClass, FalseClass
Expand Down
Loading