File tree Expand file tree Collapse file tree 4 files changed +71
-3
lines changed Expand file tree Collapse file tree 4 files changed +71
-3
lines changed Original file line number Diff line number Diff line change 22fixtures :
33 repositories :
44 apt : ' https://github.com/puppetlabs/puppetlabs-apt'
5+ stdlib : ' https://github.com/puppetlabs/puppetlabs-stdlib'
56 yumrepo_core : ' https://github.com/puppetlabs/puppetlabs-yumrepo_core'
Original file line number Diff line number Diff line change 11# @summary Install and configure Grafana Alloy
2+ #
3+ # @param config
4+ # The contents of the configuration file, if any
25class grafana_alloy (
6+ Optional[String[1]] $config = undef ,
37) {
48 require grafana_alloy::repo
59 package { 'alloy' : }
6- -> service { ' alloy' :
7- ensure => ' running' ,
8- enable => true ,
10+
11+ if $config {
12+ file { '/etc/alloy/config.alloy' :
13+ content => $config ,
14+ mode => ' 0640' ,
15+ owner => ' root' ,
16+ group => ' alloy' ,
17+ require => Package[' alloy' ],
18+ notify => Service[' alloy' ],
19+ }
20+ }
21+
22+ service { 'alloy' :
23+ ensure => ' running' ,
24+ enable => true ,
25+ require => Package[' alloy' ],
926 }
1027}
Original file line number Diff line number Diff line change 1212 end
1313 end
1414 end
15+
16+ describe 'with config' do
17+ it_behaves_like 'an idempotent resource' do
18+ let ( :config ) do
19+ <<-CONFIG
20+ prometheus.exporter.unix "default" {
21+ include_exporter_metrics = true
22+ }
23+
24+ prometheus.scrape "default" {
25+ targets = concat(
26+ prometheus.exporter.unix.default.targets,
27+ )
28+ forward_to = []
29+ }
30+ CONFIG
31+ end
32+ let ( :manifest ) do
33+ <<-PUPPET
34+ class { 'grafana_alloy':
35+ config => '#{ config } '
36+ }
37+ PUPPET
38+ end
39+ end
40+ end
1541end
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ require 'spec_helper'
4+
5+ describe 'grafana_alloy' do
6+ on_supported_os . each do |os , os_facts |
7+ context "on #{ os } " do
8+ let ( :facts ) { os_facts }
9+ let ( :params ) { { } }
10+
11+ context 'with default params' do
12+ it { is_expected . to compile . with_all_deps }
13+ it { is_expected . not_to contain_file ( '/etc/alloy/config.alloy' ) }
14+ end
15+
16+ context 'with all params' do
17+ let ( :params ) { super ( ) . merge ( config : 'my config' ) }
18+
19+ it { is_expected . to compile . with_all_deps }
20+ it { is_expected . to contain_file ( '/etc/alloy/config.alloy' ) . with_content ( 'my config' ) }
21+ end
22+ end
23+ end
24+ end
You can’t perform that action at this time.
0 commit comments