From a1f73ef0402c0b869c0dcf4f9593527a7bceb75f Mon Sep 17 00:00:00 2001
From: Takashi Kajinami <tkajinam@redhat.com>
Date: Sat, 9 Jul 2022 12:16:05 +0900
Subject: [PATCH] Add acceptance tests for config management resources

Change-Id: Id133526308d84a45ba234b8dbef392aff784ade5
---
 ...i_apache_spec.rb => 10_basic_aodh_spec.rb} |   0
 spec/acceptance/99_aodh_config_spec.rb        | 101 ++++++++++++++++++
 2 files changed, 101 insertions(+)
 rename spec/acceptance/{aodh_wsgi_apache_spec.rb => 10_basic_aodh_spec.rb} (100%)
 create mode 100644 spec/acceptance/99_aodh_config_spec.rb

diff --git a/spec/acceptance/aodh_wsgi_apache_spec.rb b/spec/acceptance/10_basic_aodh_spec.rb
similarity index 100%
rename from spec/acceptance/aodh_wsgi_apache_spec.rb
rename to spec/acceptance/10_basic_aodh_spec.rb
diff --git a/spec/acceptance/99_aodh_config_spec.rb b/spec/acceptance/99_aodh_config_spec.rb
new file mode 100644
index 00000000..1d590ac5
--- /dev/null
+++ b/spec/acceptance/99_aodh_config_spec.rb
@@ -0,0 +1,101 @@
+require 'spec_helper_acceptance'
+
+describe 'basic aodh_config resource' do
+
+  context 'default parameters' do
+
+    it 'should work with no errors' do
+      pp= <<-EOS
+      Exec { logoutput => 'on_failure' }
+
+      File <||> -> Aodh_config <||>
+      File <||> -> Aodh_api_paste_ini <||>
+
+      file { '/etc/aodh' :
+        ensure => directory,
+      }
+      file { '/etc/aodh/aodh.conf' :
+        ensure => file,
+      }
+      file { '/etc/aodh/api-paste.ini' :
+        ensure => file,
+      }
+
+      aodh_config { 'DEFAULT/thisshouldexist' :
+        value => 'foo',
+      }
+
+      aodh_config { 'DEFAULT/thisshouldnotexist' :
+        value => '<SERVICE DEFAULT>',
+      }
+
+      aodh_config { 'DEFAULT/thisshouldexist2' :
+        value             => '<SERVICE DEFAULT>',
+        ensure_absent_val => 'toto',
+      }
+
+      aodh_config { 'DEFAULT/thisshouldnotexist2' :
+        value             => 'toto',
+        ensure_absent_val => 'toto',
+      }
+
+      aodh_config { 'DEFAULT/thisshouldexist3' :
+        value => ['foo', 'bar'],
+      }
+
+      aodh_api_paste_ini { 'DEFAULT/thisshouldexist' :
+        value => 'foo',
+      }
+
+      aodh_api_paste_ini { 'DEFAULT/thisshouldnotexist' :
+        value => '<SERVICE DEFAULT>',
+      }
+
+      aodh_api_paste_ini { 'DEFAULT/thisshouldexist2' :
+        value             => '<SERVICE DEFAULT>',
+        ensure_absent_val => 'toto',
+      }
+
+      aodh_api_paste_ini { 'DEFAULT/thisshouldnotexist2' :
+        value             => 'toto',
+        ensure_absent_val => 'toto',
+      }
+
+      aodh_api_paste_ini { 'DEFAULT/thisshouldexist3' :
+        value             => 'foo',
+        key_val_separator => ':'
+      }
+      EOS
+
+
+      # Run it twice and test for idempotency
+      apply_manifest(pp, :catch_failures => true)
+      apply_manifest(pp, :catch_changes => true)
+    end
+
+    describe file('/etc/aodh/aodh.conf') do
+      it { is_expected.to exist }
+      it { is_expected.to contain('thisshouldexist=foo') }
+      it { is_expected.to contain('thisshouldexist2=<SERVICE DEFAULT>') }
+      it { is_expected.to contain('thisshouldexist3=foo') }
+      it { is_expected.to contain('thisshouldexist3=bar') }
+
+      describe '#content' do
+        subject { super().content }
+        it { is_expected.to_not match /thisshouldnotexist/ }
+      end
+    end
+
+    describe file('/etc/aodh/api-paste.ini') do
+      it { is_expected.to exist }
+      it { is_expected.to contain('thisshouldexist=foo') }
+      it { is_expected.to contain('thisshouldexist2=<SERVICE DEFAULT>') }
+      it { is_expected.to contain('thisshouldexist3:foo') }
+
+      describe '#content' do
+        subject { super().content }
+        it { is_expected.to_not match /thisshouldnotexist/ }
+      end
+    end
+  end
+end