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 rspec tests #837

Draft
wants to merge 8 commits into
base: xenon8/puppet-8-upgrade
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions .rubocop
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
--ignore-unrecognized-cops
--autocorrect
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require:
AllCops:
NewCops: enable
DisplayCopNames: true
TargetRubyVersion: '2.6'
TargetRubyVersion: '3.3'
Include:
- "**/*.rb"
Exclude:
Expand Down
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ group :development do
gem "voxpupuli-puppet-lint-plugins", '~> 4.0', require: false
gem "dependency_checker", '= 0.3.0', require: false
else
gem "facterdb", '~> 2.1', require: false
gem "facterdb", '~> 3.4.0', require: false
gem "test-kitchen", '~> 3.7.0'
gem "rubocop", '~> 1.50.0', require: false
gem "rubocop-rspec", '= 2.19.0', require: false
gem "rspec-puppet-facts", '~> 4.0', require: false
gem "rspec-puppet-facts", '~> 5.2.0', require: false
gem "rubocop-performance", '= 1.16.0', require: false
gem "librarian-puppet", '~> 5.0'
gem "io-console", '= 0.7.2', require: false
Expand Down
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ GEM
facter (4.10.0)
hocon (~> 1.3)
thor (>= 1.0.1, < 1.3)
facterdb (2.1.0)
facterdb (3.4.0)
facter (< 5.0.0)
jgrep (~> 1.5, >= 1.5.4)
faraday (2.12.2)
Expand Down Expand Up @@ -366,10 +366,10 @@ GEM
rspec-support (~> 3.13.0)
rspec-puppet (5.0.0)
rspec (~> 3.0)
rspec-puppet-facts (4.0.0)
rspec-puppet-facts (5.2.0)
deep_merge (~> 1.2)
facter (< 5)
facterdb (~> 2.1)
facterdb (~> 3.1)
puppet (>= 7, < 9)
rspec-support (3.13.2)
rsync (1.0.9)
Expand Down Expand Up @@ -526,7 +526,7 @@ DEPENDENCIES
bcrypt_pbkdf (= 1.0.1)
deep_merge (~> 1.2.2)
dependency_checker (~> 1.0.0)
facterdb (~> 2.1)
facterdb (~> 3.4.0)
io-console (= 0.7.2)
json (= 2.6.3)
kitchen-docker (~> 3.0.0)
Expand All @@ -545,7 +545,7 @@ DEPENDENCIES
puppetlabs_spec_helper (~> 8.0)
rb-readline (= 0.5.5)
rexml (~> 3.4.0)
rspec-puppet-facts (~> 4.0)
rspec-puppet-facts (~> 5.2.0)
rubocop (~> 1.50.0)
rubocop-performance (= 1.16.0)
rubocop-rspec (= 2.19.0)
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/reports/datadog_reports.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def process
msg_title: event_title,
event_type: 'config_management.run',
event_object: @msg_host,
alert_type: alert_type,
alert_type:,
priority: event_priority,
source_type_name: 'puppet',
tags: dog_tags),
Expand Down
16 changes: 3 additions & 13 deletions manifests/integrations/disk.pp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@
# excluded_disk_re => '/dev/sd[e-z]*'
# }
class datadog_agent::integrations::disk (
String $use_mount = 'no',
Optional[String] $all_partitions = undef,
Optional[String] $tag_by_filesystem = undef,
Optional[Boolean] $use_mount = undef,
Optional[Boolean] $all_partitions = undef,
Optional[Boolean] $tag_by_filesystem = undef,
Optional[Array[String]] $filesystem_exclude = undef,
Optional[Array[String]] $device_exclude = undef,
Optional[Array[String]] $mountpoint_exclude = undef,
Expand All @@ -85,16 +85,6 @@
) inherits datadog_agent::params {
require datadog_agent

# check that $all_partitions is either no or yes
if $all_partitions !~ '^(no|yes)$' {
fail('all_partitions must be either no or yes')
}

# check that $use_mount is either no or yes
if $use_mount !~ '^(no|yes)$' {
fail('use_mount must be either no or yes')
}

$legacy_dst = "${datadog_agent::params::legacy_conf_dir}/disk.yaml"
if $datadog_agent::_agent_major_version > 5 {
$dst_dir = "${datadog_agent::params::conf_dir}/disk.d"
Expand Down
57 changes: 31 additions & 26 deletions spec/classes/datadog_agent_integrations_disk_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@
context 'supported agents' do
let(:pre_condition) { "class {'::datadog_agent': agent_major_version => #{agent_major_version}}" }

conf_file = if agent_major_version == 5
'/etc/dd-agent/conf.d/disk.yaml'
else
"#{CONF_DIR}/disk.d/conf.yaml"
end
let(:yaml_conf) do
<<-HEREDOC
### MANAGED BY PUPPET

init_config:

instances:
- use_mount: false
HEREDOC
end

conf_file = "#{CONF_DIR}/disk.d/conf.yaml"

it { is_expected.to compile.with_all_deps }
it {
is_expected.to contain_file(conf_file).with_content(
%r{\s+use_mount:\s+no[\r]*$},
).with(
is_expected.to contain_file(conf_file).with_content(yaml_conf).with(
owner: DD_USER,
group: DD_GROUP,
mode: PERMISSIONS_PROTECTED_FILE,
Expand All @@ -39,13 +44,13 @@
context 'we handle strings and arrays the same' do
let(:params) do
{
use_mount: 'yes',
use_mount: true,
excluded_filesystems: ['tmpfs', 'dev'],
excluded_disks: '/dev/sda1',
excluded_disk_re: '/dev/sdb.*',
excluded_mountpoint_re: '/mnt/other.*',
all_partitions: 'yes',
tag_by_filesystem: 'no',
all_partitions: true,
tag_by_filesystem: false,
}
end
let(:yaml_conf) do
Expand All @@ -55,16 +60,16 @@
init_config:

instances:
- use_mount: yes
- use_mount: true
excluded_filesystems:
- tmpfs
- dev
excluded_disks:
- /dev/sda1
excluded_disk_re: /dev/sdb.*
excluded_mountpoint_re: /mnt/other.*
all_partitions: yes
tag_by_filesystem: no
all_partitions: true
tag_by_filesystem: false
HEREDOC
end

Expand All @@ -74,15 +79,15 @@
context 'we handle new disk configuration option' do
let(:params) do
{
use_mount: 'yes',
use_mount: true,
filesystem_blacklist: ['tmpfs', 'dev'],
device_blacklist: ['/dev/sda1'],
mountpoint_blacklist: ['/mnt/foo'],
filesystem_whitelist: ['ext4', 'hdfs', 'reiserfs'],
device_whitelist: ['/dev/sdc1', '/dev/sdc2', '/dev/sdd2'],
mountpoint_whitelist: ['/mnt/logs', '/mnt/builds'],
all_partitions: 'yes',
tag_by_filesystem: 'no',
all_partitions: true,
tag_by_filesystem: false,
}
end
let(:yaml_conf) do
Expand All @@ -92,7 +97,7 @@
init_config:

instances:
- use_mount: yes
- use_mount: true
file_system_blacklist:
- tmpfs
- dev
Expand All @@ -111,8 +116,8 @@
mount_point_whitelist:
- /mnt/logs
- /mnt/builds
all_partitions: yes
tag_by_filesystem: no
all_partitions: true
tag_by_filesystem: false
HEREDOC
end

Expand All @@ -122,15 +127,15 @@
context 'agent_version >= 7.24.0 disk configuration option' do
let(:params) do
{
use_mount: 'yes',
use_mount: true,
filesystem_exclude: ['tmpfs', 'dev'],
device_exclude: ['/dev/sda1'],
mountpoint_exclude: ['/mnt/foo'],
filesystem_include: ['ext4', 'hdfs', 'reiserfs'],
device_include: ['/dev/sdc1', '/dev/sdc2', '/dev/sdd2'],
mountpoint_include: ['/mnt/logs', '/mnt/builds'],
all_partitions: 'yes',
tag_by_filesystem: 'no',
all_partitions: true,
tag_by_filesystem: false,
}
end
let(:yaml_conf) do
Expand All @@ -140,7 +145,7 @@
init_config:

instances:
- use_mount: yes
- use_mount: true
file_system_exclude:
- tmpfs
- dev
Expand All @@ -159,8 +164,8 @@
mount_point_include:
- /mnt/logs
- /mnt/builds
all_partitions: yes
tag_by_filesystem: no
all_partitions: true
tag_by_filesystem: false
HEREDOC
end

Expand Down
15 changes: 15 additions & 0 deletions spec/classes/datadog_agent_reports_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
'major' => getosmajor(operatingsystem),
'full' => getosrelease(operatingsystem),
},
'distro' => {
'codename' => getoscodename(operatingsystem),
}
Comment on lines +31 to +33

Choose a reason for hiding this comment

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

Code Quality Violation

Consider using symbols instead of string hash keys (...read more)

In Ruby, it is a best practice to use symbols instead of strings as hash keys. This rule emphasizes that it's more efficient and idiomatic to use symbols for this purpose. Symbols are immutable and unique, which makes them ideal for identifying things, whereas strings are mutable and can create multiple objects for the same sequence of characters.

The importance of this rule lies in the performance and memory usage of your Ruby application. Using symbols as hash keys reduces memory usage because they are stored in memory only once during a Ruby process. This can make a significant difference in the efficiency of your application, especially when dealing with large data sets.

To ensure you're following good coding practices, always use symbols for hash keys unless there's a specific reason to use a string. A simple refactoring from values = { 'foo' => 42, 'bar' => 99, 'baz' => 123 } to values = { foo: 42, bar: 99, baz: 123 } will make your code compliant with this rule. This not only improves your code's performance but also makes it more readable and consistent with Ruby's conventions.

View in Datadog  Leave us feedback  Documentation

},
}
end
Expand Down Expand Up @@ -95,6 +98,9 @@
'major' => '8',
'full' => '8.1',
},
'distro' => {
'codename' => 'jessie',
}
Comment on lines +101 to +103

Choose a reason for hiding this comment

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

Code Quality Violation

Consider using symbols instead of string hash keys (...read more)

In Ruby, it is a best practice to use symbols instead of strings as hash keys. This rule emphasizes that it's more efficient and idiomatic to use symbols for this purpose. Symbols are immutable and unique, which makes them ideal for identifying things, whereas strings are mutable and can create multiple objects for the same sequence of characters.

The importance of this rule lies in the performance and memory usage of your Ruby application. Using symbols as hash keys reduces memory usage because they are stored in memory only once during a Ruby process. This can make a significant difference in the efficiency of your application, especially when dealing with large data sets.

To ensure you're following good coding practices, always use symbols for hash keys unless there's a specific reason to use a string. A simple refactoring from values = { 'foo' => 42, 'bar' => 99, 'baz' => 123 } to values = { foo: 42, bar: 99, baz: 123 } will make your code compliant with this rule. This not only improves your code's performance but also makes it more readable and consistent with Ruby's conventions.

View in Datadog  Leave us feedback  Documentation

},
}
end
Expand Down Expand Up @@ -144,6 +150,9 @@
'major' => '8',
'full' => '8.1',
},
'distro' => {
'codename' => 'jessie',
}
Comment on lines +153 to +155

Choose a reason for hiding this comment

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

Code Quality Violation

Consider using symbols instead of string hash keys (...read more)

In Ruby, it is a best practice to use symbols instead of strings as hash keys. This rule emphasizes that it's more efficient and idiomatic to use symbols for this purpose. Symbols are immutable and unique, which makes them ideal for identifying things, whereas strings are mutable and can create multiple objects for the same sequence of characters.

The importance of this rule lies in the performance and memory usage of your Ruby application. Using symbols as hash keys reduces memory usage because they are stored in memory only once during a Ruby process. This can make a significant difference in the efficiency of your application, especially when dealing with large data sets.

To ensure you're following good coding practices, always use symbols for hash keys unless there's a specific reason to use a string. A simple refactoring from values = { 'foo' => 42, 'bar' => 99, 'baz' => 123 } to values = { foo: 42, bar: 99, baz: 123 } will make your code compliant with this rule. This not only improves your code's performance but also makes it more readable and consistent with Ruby's conventions.

View in Datadog  Leave us feedback  Documentation

},
}
end
Expand Down Expand Up @@ -188,6 +197,9 @@
'major' => '8',
'full' => '8.1',
},
'distro' => {
'codename' => 'jessie',
}
Comment on lines +200 to +202

Choose a reason for hiding this comment

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

Code Quality Violation

Consider using symbols instead of string hash keys (...read more)

In Ruby, it is a best practice to use symbols instead of strings as hash keys. This rule emphasizes that it's more efficient and idiomatic to use symbols for this purpose. Symbols are immutable and unique, which makes them ideal for identifying things, whereas strings are mutable and can create multiple objects for the same sequence of characters.

The importance of this rule lies in the performance and memory usage of your Ruby application. Using symbols as hash keys reduces memory usage because they are stored in memory only once during a Ruby process. This can make a significant difference in the efficiency of your application, especially when dealing with large data sets.

To ensure you're following good coding practices, always use symbols for hash keys unless there's a specific reason to use a string. A simple refactoring from values = { 'foo' => 42, 'bar' => 99, 'baz' => 123 } to values = { foo: 42, bar: 99, baz: 123 } will make your code compliant with this rule. This not only improves your code's performance but also makes it more readable and consistent with Ruby's conventions.

View in Datadog  Leave us feedback  Documentation

},
}
end
Expand Down Expand Up @@ -234,6 +246,9 @@
'major' => '8',
'full' => '8.1',
},
'distro' => {
'codename' => 'jessie',
}
Comment on lines +249 to +251

Choose a reason for hiding this comment

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

Code Quality Violation

Consider using symbols instead of string hash keys (...read more)

In Ruby, it is a best practice to use symbols instead of strings as hash keys. This rule emphasizes that it's more efficient and idiomatic to use symbols for this purpose. Symbols are immutable and unique, which makes them ideal for identifying things, whereas strings are mutable and can create multiple objects for the same sequence of characters.

The importance of this rule lies in the performance and memory usage of your Ruby application. Using symbols as hash keys reduces memory usage because they are stored in memory only once during a Ruby process. This can make a significant difference in the efficiency of your application, especially when dealing with large data sets.

To ensure you're following good coding practices, always use symbols for hash keys unless there's a specific reason to use a string. A simple refactoring from values = { 'foo' => 42, 'bar' => 99, 'baz' => 123 } to values = { foo: 42, bar: 99, baz: 123 } will make your code compliant with this rule. This not only improves your code's performance but also makes it more readable and consistent with Ruby's conventions.

View in Datadog  Leave us feedback  Documentation

},
}
end
Expand Down
12 changes: 12 additions & 0 deletions spec/classes/datadog_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
'major' => '3',
'full' => '3.0',
},
'distro' => {
'codename' => 'nexenta',
}
Comment on lines +17 to +19

Choose a reason for hiding this comment

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

Code Quality Violation

Consider using symbols instead of string hash keys (...read more)

In Ruby, it is a best practice to use symbols instead of strings as hash keys. This rule emphasizes that it's more efficient and idiomatic to use symbols for this purpose. Symbols are immutable and unique, which makes them ideal for identifying things, whereas strings are mutable and can create multiple objects for the same sequence of characters.

The importance of this rule lies in the performance and memory usage of your Ruby application. Using symbols as hash keys reduces memory usage because they are stored in memory only once during a Ruby process. This can make a significant difference in the efficiency of your application, especially when dealing with large data sets.

To ensure you're following good coding practices, always use symbols for hash keys unless there's a specific reason to use a string. A simple refactoring from values = { 'foo' => 42, 'bar' => 99, 'baz' => 123 } to values = { foo: 42, bar: 99, baz: 123 } will make your code compliant with this rule. This not only improves your code's performance but also makes it more readable and consistent with Ruby's conventions.

View in Datadog  Leave us feedback  Documentation

},
}
end
Expand Down Expand Up @@ -68,6 +71,9 @@
'major' => '14',
'full' => '14.04',
},
'distro' => {
'codename' => 'trusty',
},
Comment on lines +48 to +50

Choose a reason for hiding this comment

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

Code Quality Violation

Consider using symbols instead of string hash keys (...read more)

In Ruby, it is a best practice to use symbols instead of strings as hash keys. This rule emphasizes that it's more efficient and idiomatic to use symbols for this purpose. Symbols are immutable and unique, which makes them ideal for identifying things, whereas strings are mutable and can create multiple objects for the same sequence of characters.

The importance of this rule lies in the performance and memory usage of your Ruby application. Using symbols as hash keys reduces memory usage because they are stored in memory only once during a Ruby process. This can make a significant difference in the efficiency of your application, especially when dealing with large data sets.

To ensure you're following good coding practices, always use symbols for hash keys unless there's a specific reason to use a string. A simple refactoring from values = { 'foo' => 42, 'bar' => 99, 'baz' => 123 } to values = { foo: 42, bar: 99, baz: 123 } will make your code compliant with this rule. This not only improves your code's performance but also makes it more readable and consistent with Ruby's conventions.

View in Datadog  Leave us feedback  Documentation

},
}
end
Expand All @@ -94,6 +100,9 @@
'major' => '14',
'full' => '14.04',
},
'distro' => {
'codename' => 'trusty',
},
Comment on lines +77 to +79

Choose a reason for hiding this comment

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

Code Quality Violation

Consider using symbols instead of string hash keys (...read more)

In Ruby, it is a best practice to use symbols instead of strings as hash keys. This rule emphasizes that it's more efficient and idiomatic to use symbols for this purpose. Symbols are immutable and unique, which makes them ideal for identifying things, whereas strings are mutable and can create multiple objects for the same sequence of characters.

The importance of this rule lies in the performance and memory usage of your Ruby application. Using symbols as hash keys reduces memory usage because they are stored in memory only once during a Ruby process. This can make a significant difference in the efficiency of your application, especially when dealing with large data sets.

To ensure you're following good coding practices, always use symbols for hash keys unless there's a specific reason to use a string. A simple refactoring from values = { 'foo' => 42, 'bar' => 99, 'baz' => 123 } to values = { foo: 42, bar: 99, baz: 123 } will make your code compliant with this rule. This not only improves your code's performance but also makes it more readable and consistent with Ruby's conventions.

View in Datadog  Leave us feedback  Documentation

},
}
end
Expand All @@ -120,6 +129,9 @@
'major' => '14',
'full' => '14.04',
},
'distro' => {
'codename' => 'trusty',
},
Comment on lines +106 to +108

Choose a reason for hiding this comment

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

Code Quality Violation

Consider using symbols instead of string hash keys (...read more)

In Ruby, it is a best practice to use symbols instead of strings as hash keys. This rule emphasizes that it's more efficient and idiomatic to use symbols for this purpose. Symbols are immutable and unique, which makes them ideal for identifying things, whereas strings are mutable and can create multiple objects for the same sequence of characters.

The importance of this rule lies in the performance and memory usage of your Ruby application. Using symbols as hash keys reduces memory usage because they are stored in memory only once during a Ruby process. This can make a significant difference in the efficiency of your application, especially when dealing with large data sets.

To ensure you're following good coding practices, always use symbols for hash keys unless there's a specific reason to use a string. A simple refactoring from values = { 'foo' => 42, 'bar' => 99, 'baz' => 123 } to values = { foo: 42, bar: 99, baz: 123 } will make your code compliant with this rule. This not only improves your code's performance but also makes it more readable and consistent with Ruby's conventions.

View in Datadog  Leave us feedback  Documentation

},
}
end
Expand Down
Loading
Loading