require 'spec_helper'
+GPG_KEY_ID = '6F6B15509CF8E59E6E469F327F438280EF8D349F'.freeze
+
+title_key_example = { id: GPG_KEY_ID,
+ ensure: 'present',
+ source: nil,
+ server: 'keyserver.ubuntu.com',
+ content: nil,
+ options: nil }
+
+def default_apt_key_example(title)
+ { id: title,
+ ensure: 'present',
+ source: nil,
+ server: 'keyserver.ubuntu.com',
+ content: nil,
+ options: nil }
+end
+
+def bunch_things_apt_key_example(title, params)
+ { id: title,
+ ensure: 'present',
+ source: 'http://apt.puppetlabs.com/pubkey.gpg',
+ server: 'pgp.mit.edu',
+ content: params[:content],
+ options: 'debug' }
+end
+
+def absent_apt_key(title)
+ { id: title,
+ ensure: 'absent',
+ source: nil,
+ server: 'keyserver.ubuntu.com',
+ content: nil,
+ keyserver: nil }
+end
+
describe 'apt::key' do
let :pre_condition do
'class { "apt": }'
}
end
- GPG_KEY_ID = '6F6B15509CF8E59E6E469F327F438280EF8D349F'.freeze
-
let :title do
GPG_KEY_ID
end
describe 'normal operation' do
describe 'default options' do
it 'contains the apt_key' do
- is_expected.to contain_apt_key(title).with(id: title,
- ensure: 'present',
- source: nil,
- server: 'keyserver.ubuntu.com',
- content: nil,
- options: nil)
+ is_expected.to contain_apt_key(title).with(default_apt_key_example(title))
end
it 'contains the apt_key present anchor' do
is_expected.to contain_anchor("apt_key #{title} present")
end
it 'contains the apt_key' do
- is_expected.to contain_apt_key(title).with(id: GPG_KEY_ID,
- ensure: 'present',
- source: nil,
- server: 'keyserver.ubuntu.com',
- content: nil,
- options: nil)
+ is_expected.to contain_apt_key(title).with(title_key_example)
end
it 'contains the apt_key present anchor' do
is_expected.to contain_anchor("apt_key #{GPG_KEY_ID} present")
end
it 'contains the apt_key' do
- is_expected.to contain_apt_key(title).with(id: title,
- ensure: 'absent',
- source: nil,
- server: 'keyserver.ubuntu.com',
- content: nil,
- keyserver: nil)
+ is_expected.to contain_apt_key(title).with(absent_apt_key(title))
end
it 'contains the apt_key absent anchor' do
is_expected.to contain_anchor("apt_key #{title} absent")
end
it 'contains the apt_key' do
- is_expected.to contain_apt_key(title).with(id: title,
- ensure: 'present',
- source: 'http://apt.puppetlabs.com/pubkey.gpg',
- server: 'pgp.mit.edu',
- content: params[:content],
- options: 'debug')
+ is_expected.to contain_apt_key(title).with(bunch_things_apt_key_example(title, params))
end
it 'contains the apt_key present anchor' do
is_expected.to contain_anchor("apt_key #{title} present")
end
it 'fails' do
- expect { subject.call } .to raise_error(%r{expects a match})
+ is_expected .to raise_error(%r{expects a match})
end
end
end
it 'fails' do
- expect { subject.call } .to raise_error(%r{expects a match})
+ is_expected .to raise_error(%r{expects a match})
end
end
end
it 'fails' do
- expect { subject.call } .to raise_error(%r{expects a match})
+ is_expected .to raise_error(%r{expects a match})
end
end
context 'exceed character url' do
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{expects a match})
+ is_expected.to raise_error(%r{expects a match})
end
end
context 'incorrect port number url' do
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{expects a match})
+ is_expected.to raise_error(%r{expects a match})
end
end
context 'incorrect protocol for url' do
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{expects a match})
+ is_expected.to raise_error(%r{expects a match})
end
end
context 'missing port number url' do
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{expects a match})
+ is_expected.to raise_error(%r{expects a match})
end
end
context 'url ending with a dot' do
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{expects a match})
+ is_expected.to raise_error(%r{expects a match})
end
end
context 'url begin with a dash' do
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{expects a match})
+ is_expected.to raise_error(%r{expects a match})
end
end
context 'invalid key' do
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{expects a match})
+ is_expected.to raise_error(%r{expects a match})
end
end
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{expects a match})
+ is_expected.to raise_error(%r{expects a match})
end
end
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{expects a})
+ is_expected.to raise_error(%r{expects a})
end
end
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{expects a match})
+ is_expected.to raise_error(%r{expects a match})
end
end
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{expects a})
+ is_expected.to raise_error(%r{expects a})
end
end
end
it 'fails' do
- expect { subject.call }.to raise_error(%r{for Enum\['absent', 'present'\], got})
+ is_expected.to raise_error(%r{for Enum\['absent', 'present'\], got})
end
end
end
- describe 'duplication' do
- context 'two apt::key resources for same key, different titles' do
- let :pre_condition do
- "class { 'apt': }
- apt::key { 'duplicate': id => '#{title}', }"
- end
+ describe 'duplication - two apt::key resources for same key, different titles' do
+ let :pre_condition do
+ "class { 'apt': }
+ apt::key { 'duplicate': id => '#{title}', }"
+ end
- it 'contains two apt::key resources' do
- is_expected.to contain_apt__key('duplicate').with(id: title,
- ensure: 'present')
- is_expected.to contain_apt__key(title).with(id: title,
- ensure: 'present')
- end
+ it 'contains two apt::key resource - duplicate' do
+ is_expected.to contain_apt__key('duplicate').with(id: title,
+ ensure: 'present')
+ end
+ it 'contains two apt::key resource - title' do
+ is_expected.to contain_apt__key(title).with(id: title,
+ ensure: 'present')
+ end
- it 'contains only a single apt_key' do
- is_expected.to contain_apt_key('duplicate').with(id: title,
- ensure: 'present',
- source: nil,
- server: 'keyserver.ubuntu.com',
- content: nil,
- options: nil)
- is_expected.not_to contain_apt_key(title)
- end
+ it 'contains only a single apt_key - duplicate' do
+ is_expected.to contain_apt_key('duplicate').with(default_apt_key_example(title))
end
+ it 'contains only a single apt_key - no title' do
+ is_expected.not_to contain_apt_key(title)
+ end
+ end
- context 'two apt::key resources, different ensure' do
- let :pre_condition do
- "class { 'apt': }
- apt::key { 'duplicate': id => '#{title}', ensure => 'absent', }"
- end
+ describe 'duplication - two apt::key resources, different ensure' do
+ let :pre_condition do
+ "class { 'apt': }
+ apt::key { 'duplicate': id => '#{title}', ensure => 'absent', }"
+ end
- it 'informs the user of the impossibility' do
- expect { subject.call }.to raise_error(%r{already ensured as absent})
- end
+ it 'informs the user of the impossibility' do
+ is_expected.to raise_error(%r{already ensured as absent})
end
end
end