diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index 792fcc607..1f8f5f1ae 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -4,16 +4,14 @@ include_context 'jenkins' context 'default parameters' do - it 'works with no errors' do - pp = <<-EOS - class {'jenkins': - cli_remoting_free => true, - cli => true, - } - EOS + pp = <<-EOS + class {'jenkins': + cli_remoting_free => true, + cli => true, + } + EOS - apply2(pp) - end + apply2(pp) describe port(8080) do it { @@ -66,16 +64,14 @@ class {'jenkins': end # default parameters context 'executors' do - it 'works with no errors' do - pp = <<-EOS - class {'jenkins': - executors => 42, - cli_remoting_free => true, - } - EOS + pp = <<-EOS + class {'jenkins': + executors => 42, + cli_remoting_free => true, + } + EOS - apply2(pp) - end + apply2(pp) describe port(8080) do # jenkins should already have been running so we shouldn't have to @@ -94,16 +90,14 @@ class {'jenkins': end # executors context 'slaveagentport' do - it 'works with no errors' do - pp = <<-EOS - class {'jenkins': - slaveagentport => 7777, - cli_remoting_free => true, - } - EOS - - apply2(pp) - end + pp = <<-EOS + class {'jenkins': + slaveagentport => 7777, + cli_remoting_free => true, + } + EOS + + apply2(pp) describe port(8080) do # jenkins should already have been running so we shouldn't have to diff --git a/spec/acceptance/plugin_spec.rb b/spec/acceptance/plugin_spec.rb index 32eda0331..d6c53809a 100644 --- a/spec/acceptance/plugin_spec.rb +++ b/spec/acceptance/plugin_spec.rb @@ -39,20 +39,18 @@ end context 'default parameters' do - it 'works with no errors' do - pp = <<-EOS - class {'jenkins': - cli_remoting_free => true, - } + pp = <<-EOS + class {'jenkins': + cli_remoting_free => true, + } - jenkins::plugin {'git-plugin': - name => 'git', - version => '2.3.4', - } - EOS + jenkins::plugin {'git-plugin': + name => 'git', + version => '2.3.4', + } + EOS - apply2(pp) - end + apply2(pp) it_behaves_like 'has_git_plugin' end @@ -70,7 +68,9 @@ class {'jenkins': version => '2.3.4', } EOS - apply2(pp) + + apply(pp, catch_failures: true) + apply(pp, catch_changes: true) end context 'downgrade' do @@ -80,17 +80,20 @@ class {'jenkins': package{'unzip': ensure => present } - class {'jenkins': - cli_remoting_free => true, - purge_plugins => true, - } + class {'jenkins': + cli_remoting_free => true, + purge_plugins => true, + } + + jenkins::plugin {'git-plugin': + name => 'git', + version => '1.0', + } + EOS + + apply(pp, catch_failures: true) + apply(pp, catch_changes: true) - jenkins::plugin {'git-plugin': - name => 'git', - version => '1.0', - } - EOS - apply2(pp) # Find the version of the installed git plugin git_version = shell("unzip -p #{$pdir}/git.hpi META-INF/MANIFEST.MF | sed 's/Plugin-Version: \\\(.*\\\)/\\1/;tx;d;:x'").stdout.strip git_version.should eq('1.0') @@ -116,7 +119,8 @@ class {'jenkins': } EOS - apply2(pp) + apply(pp, catch_failures: true) + apply(pp, catch_changes: true) end it_behaves_like 'has_git_plugin' @@ -144,7 +148,8 @@ class {'jenkins': } EOS - apply2(pp) + apply(pp, catch_failures: true) + apply(pp, catch_changes: true) end it_behaves_like 'has_git_plugin' diff --git a/spec/acceptance/slave_spec.rb b/spec/acceptance/slave_spec.rb index cbe8bfdcc..5e468061d 100644 --- a/spec/acceptance/slave_spec.rb +++ b/spec/acceptance/slave_spec.rb @@ -4,13 +4,11 @@ include_context 'jenkins' context 'default parameters' do - it 'works with no errors' do - pp = <<-EOS - include ::jenkins::slave - EOS + pp = <<-EOS + include ::jenkins::slave + EOS - apply2(pp) - end + apply2(pp) if $systemd describe file('/etc/systemd/system/jenkins-slave.service') do @@ -60,16 +58,14 @@ end context 'ui_user/ui_pass' do - it 'works with no errors' do - pp = <<-EOS - class { ::jenkins::slave: - ui_user => 'imauser', - ui_pass => 'imapass', - } - EOS + pp = <<-EOS + class { ::jenkins::slave: + ui_user => 'imauser', + ui_pass => 'imapass', + } + EOS - apply2(pp) - end + apply2(pp) describe process('java') do its(:user) { is_expected.to eq 'jenkins-slave' } @@ -81,15 +77,13 @@ class { ::jenkins::slave: context 'disable_clients_unique_id' do context 'true' do - it 'works with no errors' do - pp = <<-EOS - class { ::jenkins::slave: - disable_clients_unique_id => true, - } - EOS - - apply2(pp) - end + pp = <<-EOS + class { ::jenkins::slave: + disable_clients_unique_id => true, + } + EOS + + apply2(pp) describe process('java') do its(:user) { is_expected.to eq 'jenkins-slave' } @@ -98,15 +92,13 @@ class { ::jenkins::slave: end # true context 'false' do - it 'works with no errors' do - pp = <<-EOS - class { ::jenkins::slave: - disable_clients_unique_id => false, - } - EOS - - apply2(pp) - end + pp = <<-EOS + class { ::jenkins::slave: + disable_clients_unique_id => false, + } + EOS + + apply2(pp) describe process('java') do its(:user) { is_expected.to eq 'jenkins-slave' } @@ -117,15 +109,13 @@ class { ::jenkins::slave: context 'disable_ssl_verification' do context 'true' do - it 'works with no errors' do - pp = <<-EOS - class { ::jenkins::slave: - disable_ssl_verification => true, - } - EOS - - apply2(pp) - end + pp = <<-EOS + class { ::jenkins::slave: + disable_ssl_verification => true, + } + EOS + + apply2(pp) describe process('java') do its(:user) { is_expected.to eq 'jenkins-slave' } @@ -134,15 +124,13 @@ class { ::jenkins::slave: end # true context 'false' do - it 'works with no errors' do - pp = <<-EOS - class { ::jenkins::slave: - disable_ssl_verification => false, - } - EOS - - apply2(pp) - end + pp = <<-EOS + class { ::jenkins::slave: + disable_ssl_verification => false, + } + EOS + + apply2(pp) describe process('java') do its(:user) { is_expected.to eq 'jenkins-slave' } @@ -153,15 +141,13 @@ class { ::jenkins::slave: context 'delete_existing_clients' do context 'true' do - it 'works with no errors' do - pp = <<-EOS - class { ::jenkins::slave: - delete_existing_clients => true, - } - EOS - - apply2(pp) - end + pp = <<-EOS + class { ::jenkins::slave: + delete_existing_clients => true, + } + EOS + + apply2(pp) describe process('java') do its(:user) { is_expected.to eq 'jenkins-slave' } @@ -170,15 +156,13 @@ class { ::jenkins::slave: end # true context 'false' do - it 'works with no errors' do - pp = <<-EOS - class { ::jenkins::slave: - delete_existing_clients => false, - } - EOS - - apply2(pp) - end + pp = <<-EOS + class { ::jenkins::slave: + delete_existing_clients => false, + } + EOS + + apply2(pp) describe process('java') do its(:user) { is_expected.to eq 'jenkins-slave' } @@ -189,15 +173,13 @@ class { ::jenkins::slave: context 'labels' do context 'single label in string' do - it 'works with no errors' do - pp = <<-EOS - class { ::jenkins::slave: - labels => 'foo', - } - EOS - - apply2(pp) - end + pp = <<-EOS + class { ::jenkins::slave: + labels => 'foo', + } + EOS + + apply2(pp) describe process('java') do its(:user) { is_expected.to eq 'jenkins-slave' } @@ -206,15 +188,13 @@ class { ::jenkins::slave: end context 'multiple labels in string' do - it 'works with no errors' do - pp = <<-EOS - class { ::jenkins::slave: - labels => 'foo bar baz', - } - EOS - - apply2(pp) - end + pp = <<-EOS + class { ::jenkins::slave: + labels => 'foo bar baz', + } + EOS + + apply2(pp) describe process('java') do its(:user) { is_expected.to eq 'jenkins-slave' } @@ -223,15 +203,13 @@ class { ::jenkins::slave: end context 'multiple labels in array' do - it 'works with no errors' do - pp = <<-EOS - class { ::jenkins::slave: - labels => ['foo', 'bar', 'baz'], - } - EOS - - apply2(pp) - end + pp = <<-EOS + class { ::jenkins::slave: + labels => ['foo', 'bar', 'baz'], + } + EOS + + apply2(pp) describe process('java') do its(:user) { is_expected.to eq 'jenkins-slave' } @@ -244,15 +222,13 @@ class { ::jenkins::slave: tool_locations = 'Python-2.7:/usr/bin/python2.7 Java-1.8:/usr/bin/java' context tool_locations do - it 'works with no errors' do - pp = <<-EOS - class { ::jenkins::slave: - tool_locations => '#{tool_locations}', - } - EOS - - apply2(pp) - end + pp = <<-EOS + class { ::jenkins::slave: + tool_locations => '#{tool_locations}', + } + EOS + + apply2(pp) describe process('java') do its(:user) { is_expected.to eq 'jenkins-slave' } @@ -266,15 +242,13 @@ class { ::jenkins::slave: tunnel = 'localhost:9000' context tunnel do - it 'works with no errors' do - pp = <<-EOS - class { ::jenkins::slave: - tunnel => '#{tunnel}', - } - EOS - - apply2(pp) - end + pp = <<-EOS + class { ::jenkins::slave: + tunnel => '#{tunnel}', + } + EOS + + apply2(pp) describe process('java') do its(:user) { is_expected.to eq 'jenkins-slave' } diff --git a/spec/acceptance/xtypes/jenkins_credentials_spec.rb b/spec/acceptance/xtypes/jenkins_credentials_spec.rb index 754ef0455..40e6944e2 100644 --- a/spec/acceptance/xtypes/jenkins_credentials_spec.rb +++ b/spec/acceptance/xtypes/jenkins_credentials_spec.rb @@ -6,7 +6,7 @@ context 'ensure =>' do context 'present' do context 'UsernamePasswordCredentialsImpl' do - it 'works with no errors' do + it 'works with no errors and idempotently' do pp = base_manifest + <<-EOS jenkins_credentials { '9b07d668-a87e-4877-9407-ae05056e32ac': ensure => 'present', @@ -19,7 +19,8 @@ } EOS - apply2(pp) + apply(pp, catch_failures: true) + apply(pp, catch_changes: true) end describe file('/var/lib/jenkins/credentials.xml') do @@ -31,7 +32,7 @@ end context 'ConduitCredentialsImpl' do - it 'works with no errors' do + it 'works with no errors and idempotently' do pending('puppet_helper.groovy implementation missing, see https://github.com/jenkinsci/puppet-jenkins/issues/753') pp = base_manifest + <<-EOS jenkins_credentials { '002224bd-60cb-49f3-a314-d0f73f82233d': @@ -44,8 +45,10 @@ } EOS - apply2(pp) + apply(pp, catch_failures: true) + apply(pp, catch_changes: true) end + # XXX need to properly compare the XML doc # trying to match anything other than the id this way might match other # credentials @@ -58,7 +61,7 @@ end context 'BasicSSHUserPrivateKey' do - it 'works with no errors' do + it 'works with no errors and idempotently' do pp = base_manifest + <<-EOS jenkins::plugin { 'ssh-credentials': } @@ -74,7 +77,8 @@ } EOS - apply2(pp) + apply(pp, catch_failures: true) + apply(pp, catch_changes: true) end describe file('/var/lib/jenkins/credentials.xml') do @@ -86,7 +90,7 @@ end context 'StringCredentialsImpl' do - it 'works with no errors' do + it 'works with no errors and idempotently' do pp = base_manifest + <<-EOS jenkins::plugin { 'plain-credentials': pin => true, @@ -102,7 +106,8 @@ } EOS - apply2(pp) + apply(pp, catch_failures: true) + apply(pp, catch_changes: true) end describe file('/var/lib/jenkins/credentials.xml') do @@ -114,7 +119,7 @@ end context 'FileCredentialsImpl' do - it 'works with no errors' do + it 'works with no errors and idempotently' do pp = base_manifest + <<-EOS jenkins::plugin { 'plain-credentials': pin => true, @@ -131,7 +136,8 @@ } EOS - apply2(pp) + apply(pp, catch_failures: true) + apply(pp, catch_changes: true) end describe file('/var/lib/jenkins/credentials.xml') do @@ -143,7 +149,7 @@ end context 'AWSCredentialsImpl' do - it 'works with no errors' do + it 'works with no errors and idempotently' do pending('jenkins plugin tests are not consistently failing or succeeding: https://github.com/voxpupuli/puppet-jenkins/issues/839') pp = base_manifest + <<-EOS jenkins::plugin { [ @@ -165,7 +171,8 @@ } EOS - apply2(pp) + apply(pp, catch_failures: true) + apply(pp, catch_changes: true) end describe file('/var/lib/jenkins/credentials.xml') do @@ -180,7 +187,7 @@ end context 'GitLabApiTokenImpl' do - it 'works with no errors' do + it 'works with no errors and idempotently' do pending('jenkins plugin tests are not consistently failing or succeeding: https://github.com/voxpupuli/puppet-jenkins/issues/839') pp = base_manifest + <<-EOS package { 'git': } @@ -210,7 +217,8 @@ } EOS - apply2(pp) + apply(pp, catch_failures: true) + apply(pp, catch_changes: true) end describe file('/var/lib/jenkins/credentials.xml') do @@ -225,7 +233,7 @@ end context 'GoogleRobotPrivateKeyCredentials with json_key' do - it 'works with no errors' do + it 'works with no errors and idempotently' do pending('jenkins plugin tests are not consistently failing or succeeding: https://github.com/voxpupuli/puppet-jenkins/issues/839') pp = base_manifest + <<-EOS jenkins::plugin { [ @@ -247,7 +255,8 @@ } EOS - apply2(pp) + apply(pp, catch_failures: true) + apply(pp, catch_changes: true) end describe file('/var/lib/jenkins/credentials.xml') do @@ -262,7 +271,7 @@ end context 'GoogleRobotPrivateKeyCredentials with email_address and p12_key' do - it 'works with no errors' do + it 'works with no errors and idempotently' do pending('jenkins plugin tests are not consistently failing or succeeding: https://github.com/voxpupuli/puppet-jenkins/issues/839') pp = base_manifest + <<-EOS jenkins::plugin { [ @@ -280,7 +289,8 @@ } EOS - apply2(pp) + apply(pp, catch_failures: true) + apply(pp, catch_changes: true) end describe file('/var/lib/jenkins/credentials.xml') do @@ -295,7 +305,7 @@ end context 'BrowserStackCredentials' do - it 'works with no errors' do + it 'works with no errors and idempotently' do pending('jenkins plugin tests are not consistently failing or succeeding: https://github.com/voxpupuli/puppet-jenkins/issues/839') pp = base_manifest + <<-EOS jenkins::plugin { [ @@ -316,7 +326,8 @@ } EOS - apply2(pp) + apply(pp, catch_failures: true) + apply(pp, catch_changes: true) end describe file('/var/lib/jenkins/credentials.xml') do @@ -333,7 +344,7 @@ context 'absent' do context 'StringCredentialsImpl' do - it 'works with no errors' do + it 'works with no errors and idempotently' do pp = base_manifest + <<-EOS jenkins::plugin { 'plain-credentials': } @@ -347,7 +358,8 @@ } EOS - apply2(pp) + apply(pp, catch_failures: true) + apply(pp, catch_changes: true) end describe file('/var/lib/jenkins/credentials.xml') do @@ -359,7 +371,7 @@ end context 'FileCredentialsImpl' do - it 'works with no errors' do + it 'works with no errors and idempotently' do pp = base_manifest + <<-EOS jenkins::plugin { 'plain-credentials': pin => true, @@ -376,7 +388,8 @@ } EOS - apply2(pp) + apply(pp, catch_failures: true) + apply(pp, catch_changes: true) end describe file('/var/lib/jenkins/credentials.xml') do diff --git a/spec/acceptance/xtypes/jenkins_job_spec.rb b/spec/acceptance/xtypes/jenkins_job_spec.rb index 61e1a3f01..52df6f751 100644 --- a/spec/acceptance/xtypes/jenkins_job_spec.rb +++ b/spec/acceptance/xtypes/jenkins_job_spec.rb @@ -81,14 +81,15 @@ end # 'present' do context 'absent' do - it 'works with no errors' do + it 'works with no errors and idempotently' do pp = base_manifest + <<-EOS jenkins_job { 'foo': ensure => absent, } EOS - apply2(pp) + apply(pp, catch_failures: true) + apply(pp, catch_changes: true) end describe file('/var/lib/jenkins/jobs/foo/config.xml') do @@ -151,14 +152,15 @@ end # create context 'delete' do - it 'works with no errors' do + it 'works with no errors and idempotently' do pp = manifest + <<-EOS jenkins_job { 'foo': ensure => absent } jenkins_job { 'foo/bar': ensure => absent } jenkins_job { 'foo/bar/baz': ensure => absent } EOS - apply2(pp) + apply(pp, catch_failures: true) + apply(pp, catch_changes: true) end %w[ diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index cbe5c9750..4cb1a4568 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -62,8 +62,12 @@ def apply(pp, options = {}) # Run it twice and test for idempotency def apply2(pp) - apply(pp, catch_failures: true) - apply(pp, catch_changes: true) + it 'works with no error' do + apply_manifest(pp, catch_failures: true) + end + it 'works idempotently' do + apply_manifest(pp, catch_changes: true) + end end # probe stolen from: