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

tests for integration classes #145

Closed
wants to merge 22 commits into from
Closed
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
1 change: 1 addition & 0 deletions manifests/integrations/apache.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
$password = undef,
$tags = []
) inherits datadog_agent::params {
include datadog_agent

validate_string($url)
validate_array($tags)
Expand Down
1 change: 1 addition & 0 deletions manifests/integrations/docker.pp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
$url = 'unix://var/run/docker.sock',
$tags = [],
) inherits datadog_agent::params {
include datadog_agent

file { "${datadog_agent::params::conf_dir}/docker.yaml":
ensure => file,
Expand Down
1 change: 1 addition & 0 deletions manifests/integrations/elasticsearch.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
class datadog_agent::integrations::elasticsearch(
$url = 'http://localhost:9200'
) inherits datadog_agent::params {
include datadog_agent

file { "${datadog_agent::params::conf_dir}/elastic.yaml":
ensure => file,
Expand Down
1 change: 1 addition & 0 deletions manifests/integrations/haproxy.pp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
$creds = {},
$url = "http://${::ipaddress}:8080",
) inherits datadog_agent::params {
include datadog_agent

file {
"${datadog_agent::params::conf_dir}/haproxy.yaml":
Expand Down
1 change: 1 addition & 0 deletions manifests/integrations/http_check.pp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
$tags = [],
$contact = [],
) inherits datadog_agent::params {
include datadog_agent

file { "${datadog_agent::params::conf_dir}/http_check.yaml":
ensure => file,
Expand Down
1 change: 1 addition & 0 deletions manifests/integrations/jenkins.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
class datadog_agent::integrations::jenkins(
$path = '/var/lib/jenkins'
) inherits datadog_agent::params {
include datadog_agent

file { "${datadog_agent::params::conf_dir}/jenkins.yaml":
ensure => file,
Expand Down
1 change: 1 addition & 0 deletions manifests/integrations/marathon.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
$marathon_timeout = 5,
$url = 'http://localhost:8080'
) inherits datadog_agent::params {
include datadog_agent

file { "${datadog_agent::params::conf_dir}/marathon.yaml":
ensure => file,
Expand Down
1 change: 1 addition & 0 deletions manifests/integrations/mesos.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
$mesos_timeout = 5,
$url = 'http://localhost:5050'
) inherits datadog_agent::params {
include datadog_agent

file { "${datadog_agent::params::conf_dir}/mesos.yaml":
ensure => file,
Expand Down
1 change: 1 addition & 0 deletions manifests/integrations/mongo.pp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
class datadog_agent::integrations::mongo(
$servers = [{'host' => 'localhost', 'port' => '27017'}]
) inherits datadog_agent::params {
include datadog_agent

validate_array($servers)

Expand Down
1 change: 1 addition & 0 deletions manifests/integrations/mysql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
$replication = '0',
$galera_cluster = '0'
) inherits datadog_agent::params {
include datadog_agent

validate_array($tags)

Expand Down
1 change: 1 addition & 0 deletions manifests/integrations/nginx.pp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
class datadog_agent::integrations::nginx(
$instances = [],
) inherits datadog_agent::params {
include datadog_agent

validate_array($instances)

Expand Down
1 change: 1 addition & 0 deletions manifests/integrations/ntp.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
class datadog_agent::integrations::ntp(
$offset_threshold = 60,
) inherits datadog_agent::params {
include datadog_agent

file { "${datadog_agent::params::conf_dir}/ntp.yaml":
ensure => file,
Expand Down
1 change: 1 addition & 0 deletions manifests/integrations/postgres.pp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
$tags = [],
$tables = []
) inherits datadog_agent::params {
include datadog_agent

validate_array($tags)
validate_array($tables)
Expand Down
1 change: 1 addition & 0 deletions manifests/integrations/process.pp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
class datadog_agent::integrations::process(
$processes = [],
) inherits datadog_agent::params {
include datadog_agent

validate_array( $processes )

Expand Down
1 change: 1 addition & 0 deletions manifests/integrations/rabbitmq.pp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
$queues = undef,
$vhosts = undef,
) inherits datadog_agent::params {
include datadog_agent

file { "${datadog_agent::params::conf_dir}/rabbitmq.yaml":
ensure => file,
Expand Down
1 change: 1 addition & 0 deletions manifests/integrations/redis.pp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
$keys = [],
$warn_on_missing_keys = true,
) inherits datadog_agent::params {
include datadog_agent

validate_re($port, '^\d+$')
validate_array($tags)
Expand Down
4 changes: 3 additions & 1 deletion manifests/integrations/solr.pp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
$java_bin_path = undef,
$trust_store_path = undef,
$trust_store_password = undef,
$tags = {})inherits datadog_agent::params {
$tags = {},
) inherits datadog_agent::params {
include datadog_agent

file { "${datadog_agent::params::conf_dir}/solr.yaml":
ensure => file,
Expand Down
5 changes: 4 additions & 1 deletion manifests/integrations/tomcat.pp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@
$java_bin_path = undef,
$trust_store_path = undef,
$trust_store_password = undef,
$tags = {}) inherits datadog_agent::params {
$tags = {},
) inherits datadog_agent::params {
include datadog_agent


file { "${datadog_agent::params::conf_dir}/tomcat.yaml":
ensure => file,
Expand Down
1 change: 1 addition & 0 deletions manifests/integrations/varnish.pp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
$varnishstat = '/usr/bin/varnishstat',
$tags = [],
) inherits datadog_agent::params {
include datadog_agent

file { "${datadog_agent::params::conf_dir}/varnish.yaml":
ensure => file,
Expand Down
1 change: 1 addition & 0 deletions manifests/integrations/zk.pp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
class datadog_agent::integrations::zk (
$servers = [{'host' => 'localhost', 'port' => '2181'}]
) inherits datadog_agent::params {
include datadog_agent

validate_array($servers)

Expand Down
85 changes: 85 additions & 0 deletions spec/classes/datadog_agent_integrations_apache_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
require 'spec_helper'

describe 'datadog_agent::integrations::apache' do
let(:facts) {{
operatingsystem: 'Ubuntu',
}}
let(:conf_dir) { '/etc/dd-agent/conf.d' }
let(:dd_user) { 'dd-agent' }
let(:dd_group) { 'root' }
let(:dd_package) { 'datadog-agent' }
let(:dd_service) { 'datadog-agent' }
let(:conf_file) { "#{conf_dir}/apache.yaml" }

it { should compile.with_all_deps }
it { should contain_file(conf_file).with(
owner: dd_user,
group: dd_group,
mode: '0600',
)}
it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") }
it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") }

context 'with default parameters' do
it { should contain_file(conf_file).with_content(%r{apache_status_url: http://localhost/server-status\?auto}) }
it { should contain_file(conf_file).without_content(/tags:/) }
it { should contain_file(conf_file).without_content(/apache_user:/) }
it { should contain_file(conf_file).without_content(/apache_password:/) }
end

context 'with parameters set' do
let(:params) {{
url: 'http://foobar',
username: 'userfoo',
password: 'passfoo',
tags: %w{foo bar baz},
}}
it { should contain_file(conf_file).with_content(%r{apache_status_url: http://foobar}) }
it { should contain_file(conf_file).with_content(/apache_user: userfoo/) }
it { should contain_file(conf_file).with_content(/apache_password: passfoo/) }
end

context 'with tags parameter single value' do
let(:params) {{
tags: 'foo',
}}
it { should_not compile }

skip "this is currently unimplemented behavior" do
it { should contain_file(conf_file).with_content(/tags:\s+- foo\s*?[^-]/m) }
end
end

context 'with tags parameter array' do
let(:params) {{
tags: %w{ foo bar baz },
}}
it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- bar\s+- baz\s*?[^-]/m) }
end

context 'with tags parameter empty values' do
context 'mixed in with other tags' do
let(:params) {{
tags: [ 'foo', '', 'baz' ]
}}

it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- baz\s*?[^-]/m) }
end

context 'single element array of an empty string' do
let(:params) {{
tags: [''],
}}

skip("undefined behavior")
end

context 'single value empty string' do
let(:params) {{
tags: '',
}}

skip("doubly undefined behavior")
end
end
end
74 changes: 74 additions & 0 deletions spec/classes/datadog_agent_integrations_docker_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
require 'spec_helper'

describe 'datadog_agent::integrations::docker' do
let(:facts) {{
operatingsystem: 'Ubuntu',
}}
let(:conf_dir) { '/etc/dd-agent/conf.d' }
let(:dd_user) { 'dd-agent' }
let(:dd_group) { 'root' }
let(:dd_package) { 'datadog-agent' }
let(:dd_service) { 'datadog-agent' }
let(:conf_file) { "#{conf_dir}/docker.yaml" }

it { should compile.with_all_deps }
it { should contain_file(conf_file).with(
owner: dd_user,
group: dd_group,
mode: '0644',
)}
it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") }
it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") }

context 'with default parameters' do
it { should contain_file(conf_file).with_content(%r{url: unix://var/run/docker.sock}) }
it { should contain_file(conf_file).with_content(/new_tag_names: true/) }
it { should contain_file(conf_file).without_content(/tags: /) }
end

context 'with parameters set' do
let(:params) {{
url: 'unix://foo/bar/baz.sock',
new_tag_names: false,
}}
it { should contain_file(conf_file).with_content(%r{url: unix://foo/bar/baz.sock}) }
it { should contain_file(conf_file).with_content(/new_tag_names: false/) }
end

context 'with tags parameter array' do
let(:params) {{
tags: %w{ foo bar baz },
}}
it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- bar\s+- baz\s*?[^-]/m) }
end

context 'with tags parameter with an empty tag' do
end

context 'with tags parameter empty values' do
context 'mixed in with other tags' do
let(:params) {{
tags: [ 'foo', '', 'baz' ]
}}

it { should contain_file(conf_file).with_content(/tags:\s+- foo\s+- baz\s*?[^-]/m) }
end

context 'single element array of an empty string' do
let(:params) {{
tags: [''],
}}

skip("undefined behavior")
end

context 'single value empty string' do
let(:params) {{
tags: '',
}}

skip("doubly undefined behavior")
end
end

end
35 changes: 35 additions & 0 deletions spec/classes/datadog_agent_integrations_elasticsearch_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'spec_helper'

describe 'datadog_agent::integrations::elasticsearch' do
let(:facts) {{
operatingsystem: 'Ubuntu',
}}
let(:conf_dir) { '/etc/dd-agent/conf.d' }
let(:dd_user) { 'dd-agent' }
let(:dd_group) { 'root' }
let(:dd_package) { 'datadog-agent' }
let(:dd_service) { 'datadog-agent' }
let(:conf_file) { "#{conf_dir}/elastic.yaml" }

it { should compile.with_all_deps }
it { should contain_file(conf_file).with(
owner: dd_user,
group: dd_group,
mode: '0644',
)}

it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") }
it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") }

context 'with default parameters' do
it { should contain_file(conf_file).with_content(%r{url: http://localhost:9200}) }
end

context 'with parameters set' do
let(:params) {{
url: 'http://foo:4242',
}}
it { should contain_file(conf_file).with_content(%r{http://foo:4242}) }
end

end
Loading