Skip to content

Commit

Permalink
Merge pull request #32 from m0dular/SUP-3557-class_spec_tests
Browse files Browse the repository at this point in the history
(SUP-3557) Add spec tests for the main class
  • Loading branch information
m0dular authored Aug 15, 2022
2 parents a55d3d8 + eb459a3 commit 7fe8b8b
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 19 deletions.
1 change: 1 addition & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
fixtures:
forge_modules:
archive: "puppet/archive"
yumrepo: "puppetlabs/yumrepo_core"
repositories:
facts: 'https://github.com/puppetlabs/puppetlabs-facts'
puppet_agent: 'https://github.com/puppetlabs/puppetlabs-puppet_agent'
Expand Down
27 changes: 11 additions & 16 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
# @param version
# Version of InfluxDB to install. Changing this is not recommended.
# @param archive_source
# URL containing an InfluxDB archive if not installing from a repository or false to disable installing from source. Defaults to version 2-2.1.1 on amd64 architechture.
# URL containing an InfluxDB archive if not installing from a repository or false to disable installing from source.
# Defaults to version 2-2.1.1 on amd64 architechture.
# @param use_ssl
# Whether to use http or https connections. Defaults to true (https).
# @param manage_ssl
Expand Down Expand Up @@ -105,14 +106,8 @@
package {'influxdb2':
ensure => $version,
require => Yumrepo[$repo_name],
before => Service['influxdb'],
}

service {'influxdb':
ensure => running,
enable => true,
require => Package['influxdb2'],
}

}
# If not managing the repo, install the package from archive source
elsif $archive_source {
Expand Down Expand Up @@ -145,6 +140,7 @@
source => $archive_source,
cleanup => true,
require => File['/etc/influxdb', '/opt/influxdb'],
before => Service['influxdb'],
}

group { 'influxdb':
Expand All @@ -163,22 +159,21 @@
mode => '0775',
notify => Service['influxdb'],
}

service {'influxdb':
ensure => running,
enable => true,
require => File['/opt/influxdb'],
}

}

# Otherwise, assume we have a source for the package
else {
package {'influxdb2':
ensure => installed,
ensure => installed,
before => Service['influxdb'],
}
}

service {'influxdb':
ensure => running,
enable => true,
}

if $use_ssl {
if $manage_ssl {
file {'/etc/influxdb/cert.pem':
Expand Down
6 changes: 3 additions & 3 deletions spec/acceptance/install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
it 'installs influxdb' do
pp = <<-MANIFEST
include influxdb
MANIFEST
MANIFEST

idempotent_apply(pp)
end

# Influxdb should be listening on port 8086 by default
describe port('8086') do
it { is_expected.to be_listening }
it 'is listening on port 8086' do
expect(run_shell('ss -Htln sport = :8086').stdout).to match(%r{LISTEN})
end
end
end
124 changes: 124 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
require 'spec_helper'

describe 'influxdb' do
let(:facts) { { os: { family: 'RedHat' }, identity: { user: 'root' } } }

on_supported_os.each do |os, os_facts|
context "on #{os}" do
let(:facts) { os_facts }

it { is_expected.to compile }
end
end

context 'when using default parameters' do
let(:params) { { host: 'localhost' } }

it {
is_expected.to contain_class('influxdb').with(
host: 'localhost',
port: 8086,
use_ssl: true,
initial_org: 'puppetlabs',
token: nil,
token_file: '/root/.influxdb_token',
)

is_expected.to contain_service('influxdb').with_ensure('running')
is_expected.to contain_package('influxdb2').with_ensure('2.1.1')

['/etc/influxdb/cert.pem', '/etc/influxdb/ca.pem', '/etc/influxdb/key.pem'].each do |file|
is_expected.to contain_file(file)
end

is_expected.to contain_influxdb_setup('localhost').with(
ensure: 'present',
token_file: '/root/.influxdb_token',
bucket: 'puppet_data',
org: 'puppetlabs',
username: 'admin',
password: RSpec::Puppet::Sensitive.new('puppetlabs'),
)

['/etc/systemd/system/influxdb.service.d', '/etc/systemd/system/influxdb.service.d/override.conf'].each do |file|
is_expected.to contain_file(file)
end
}
end

context 'when not using ssl' do
let(:params) { { host: 'localhost', use_ssl: false } }

it {
is_expected.to contain_class('influxdb').with(use_ssl: false)

is_expected.not_to contain_file('/etc/influxdb/cert.pem')
is_expected.not_to contain_file('/etc/influxdb/ca.pem')
is_expected.not_to contain_file('/etc/influxdb/key.pem')
}
end

context 'when using a repository' do
let(:params) { { host: 'localhost' } }

it {
is_expected.to contain_yumrepo('influxdb2').with(
ensure: 'present',
descr: 'influxdb2',
name: 'influxdb2',
baseurl: 'https://repos.influxdata.com/rhel/$releasever/$basearch/stable',
gpgkey: 'https://repos.influxdata.com/influxdb2.key https://repos.influxdata.com/influxdb.key',
enabled: '1',
gpgcheck: '1',
target: '/etc/yum.repos.d/influxdb2.repo',
)

is_expected.not_to contain_archive('/tmp/influxdb.tar.gz')
}
end

context 'when using an archive source' do
let(:params) { { host: 'localhost', manage_repo: false } }

it {
is_expected.not_to contain_yumrepo('influxdb2')

['/etc/influxdb', '/opt/influxdb', '/etc/influxdb/scripts'].each do |file|
is_expected.to contain_file(file).with(
ensure: 'directory',
owner: 'root',
group: 'root',
)
end
is_expected.to contain_file('/var/lib/influxdb').with(
ensure: 'directory',
owner: 'influxdb',
group: 'influxdb',
)
is_expected.to contain_file('/var/lib/influxdb').that_requires(['User[influxdb]', 'Group[influxdb]'])

['/etc/influxdb/scripts/influxd-systemd-start.sh', '/etc/systemd/system/influxdb.service'].each do |file|
is_expected.to contain_file(file)
end

is_expected.to contain_user('influxdb')
is_expected.to contain_group('influxdb')

is_expected.to contain_archive('/tmp/influxdb.tar.gz').with(
source: 'https://dl.influxdata.com/influxdb/releases/influxdb2-2.1.1-linux-amd64.tar.gz',
)
is_expected.to contain_archive('/tmp/influxdb.tar.gz').that_requires(
['File[/etc/influxdb]', 'File[/opt/influxdb]'],
)
}
end

context 'when not using a repo or archive source' do
let(:params) { { host: 'localhost', manage_repo: false, archive_source: false } }

it {
is_expected.not_to contain_yumrepo('influxdb2')
is_expected.not_to contain_archive('/tmp/influxdb.tar.gz')
}
end
end

0 comments on commit 7fe8b8b

Please sign in to comment.