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 tcp_check for multi instances #851

Merged
merged 2 commits into from
Mar 24, 2025
Merged
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
6 changes: 3 additions & 3 deletions manifests/integrations/tcp_check.pp
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@
# }]
# }
class datadog_agent::integrations::tcp_check (
String $check_name,
String $host,
String $port,
Optional[String] $check_name = undef,
Optional[String] $host = undef,
Optional[String] $port = undef,
Integer $timeout = 10,
Optional[Integer] $threshold = undef,
Optional[Integer] $window = undef,
Expand Down
39 changes: 39 additions & 0 deletions spec/classes/datadog_agent_integrations_tcp_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,45 @@

skip('doubly undefined behavior')
end

context 'with multiple instances' do
let(:params) do
{
instances: [
{
check_name: 'foo.bar.baz',
host: 'foo.bar.baz',
port: '80',
timeout: 123,
threshold: 456,
window: 789,
collect_response_time: true,
},
{
check_name: 'baz.bar.foo',
host: 'baz.bar.foo',
port: '8080',
timeout: 456,
tags: ['foo', 'bar', 'baz']

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Quality Violation

Suggested change
tags: ['foo', 'bar', 'baz']
tags: %w[foo bar baz]
Consider using the %w syntax instead (...read more)

The rule "Prefer %w to the literal array syntax" is a Ruby style guideline that encourages the use of %w notation instead of the traditional array syntax when defining arrays of strings. This rule is part of the Ruby community's efforts to promote readability and simplicity in Ruby code.

This rule is important because it helps to keep the code concise and easy to read. The %w notation allows you to define an array of strings without having to use quotes and commas. This can make the code cleaner and easier to understand, especially when dealing with large arrays.

To follow this rule, replace the traditional array syntax with the %w notation. For example, instead of writing ['foo', 'bar', 'baz'], you should write %w[foo bar baz]. This will create the same array, but in a more readable and concise way. By following this rule, you can help to make your Ruby code cleaner and easier to understand.

View in Datadog  Leave us feedback  Documentation

},
]
}
end

it { is_expected.to contain_file(conf_file).with_content(%r{name: foo.bar.baz}) }
it { is_expected.to contain_file(conf_file).with_content(%r{host: foo.bar.baz}) }
it { is_expected.to contain_file(conf_file).with_content(%r{port: 80}) }
it { is_expected.to contain_file(conf_file).with_content(%r{timeout: 123}) }
it { is_expected.to contain_file(conf_file).with_content(%r{threshold: 456}) }
it { is_expected.to contain_file(conf_file).with_content(%r{window: 789}) }
it { is_expected.to contain_file(conf_file).with_content(%r{collect_response_time: true}) }

it { is_expected.to contain_file(conf_file).with_content(%r{name: baz.bar.foo}) }
it { is_expected.to contain_file(conf_file).with_content(%r{host: baz.bar.foo}) }
it { is_expected.to contain_file(conf_file).with_content(%r{port: 8080}) }
it { is_expected.to contain_file(conf_file).with_content(%r{timeout: 456}) }
it { is_expected.to contain_file(conf_file).with_content(%r{tags:\s+- foo\s+- bar\s+- baz\s*?[^-]}m) }
end
end
end
end
Expand Down
Loading