- it {
- if [:present, 'present', :absent, 'absent'].include? param_hash[:ensure]
- should contain_apt__params
- end
- }
-
- it {
- if [:present, 'present'].include? param_hash[:ensure]
- should_not contain_exec("apt::key #{param_hash[:key]} absent")
- should contain_exec("apt::key #{param_hash[:key]} present")
- should contain_exec(digest).with({
- "path" => "/bin:/usr/bin",
- "unless" => "/usr/bin/apt-key list | /bin/grep '#{param_hash[:key]}'"
- })
- elsif [:absent, 'absent'].include? param_hash[:ensure]
- should_not contain_exec("apt::key #{param_hash[:key]} present")
- should contain_exec("apt::key #{param_hash[:key]} absent").with({
- "path" => "/bin:/usr/bin",
- "onlyif" => "apt-key list | grep '#{param_hash[:key]}'",
- "command" => "apt-key del '#{param_hash[:key]}'"
- })
- else
- expect { should raise_error(Puppet::Error) }
+ it 'contains the apt_key with refresh => true' do
+ is_expected.to contain_apt_key(title).with(
+ ensure: 'present',
+ refresh: true,
+ )
+ end
+ end
+
+ describe 'set a bunch of things!' do
+ let :params do
+ {
+ content: 'GPG key content',
+ source: 'http://apt.puppetlabs.com/pubkey.gpg',
+ server: 'pgp.mit.edu',
+ options: 'debug',
+ }
+ end
+
+ it 'contains the apt_key' do
+ 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
+ end
+
+ context 'when domain with dash' do
+ let(:params) do
+ {
+ server: 'p-gp.m-it.edu',
+ }
+ end
+
+ it 'contains the apt_key' do
+ is_expected.to contain_apt_key(title).with(id: title,
+ server: 'p-gp.m-it.edu')
+ end
+ end
+
+ context 'with url' do
+ let :params do
+ {
+ server: 'hkp://pgp.mit.edu',
+ }
+ end
+
+ it 'contains the apt_key' do
+ is_expected.to contain_apt_key(title).with(id: title,
+ server: 'hkp://pgp.mit.edu')
+ end
+ end
+ context 'when url with port number' do
+ let :params do
+ {
+ server: 'hkp://pgp.mit.edu:80',
+ }
+ end
+
+ it 'contains the apt_key' do
+ is_expected.to contain_apt_key(title).with(id: title,
+ server: 'hkp://pgp.mit.edu:80')
+ end
+ end
+ end
+
+ describe 'validation' do
+ context 'when domain begin with dash' do
+ let(:params) do
+ {
+ server: '-pgp.mit.edu',
+ }
+ end
+
+ it 'fails' do
+ is_expected .to raise_error(%r{expects a match})
+ end
+ end
+
+ context 'when domain begin with dot' do
+ let(:params) do
+ {
+ server: '.pgp.mit.edu',
+ }
+ end
+
+ it 'fails' do
+ is_expected .to raise_error(%r{expects a match})
+ end
+ end
+
+ context 'when domain end with dot' do
+ let(:params) do
+ {
+ server: 'pgp.mit.edu.',
+ }
+ end
+
+ it 'fails' do
+ is_expected .to raise_error(%r{expects a match})
+ end
+ end
+ context 'when character url exceeded' do
+ let :params do
+ {
+ server: 'hkp://pgpiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii.mit.edu',
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a match})
+ end
+ end
+ context 'with incorrect port number url' do
+ let :params do
+ {
+ server: 'hkp://pgp.mit.edu:8008080',
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a match})
+ end
+ end
+ context 'with incorrect protocol for url' do
+ let :params do
+ {
+ server: 'abc://pgp.mit.edu:80',
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a match})
+ end
+ end
+ context 'with missing port number url' do
+ let :params do
+ {
+ server: 'hkp://pgp.mit.edu:',
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a match})
+ end
+ end
+ context 'with url ending with a dot' do
+ let :params do
+ {
+ server: 'hkp://pgp.mit.edu.',
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a match})
+ end
+ end
+ context 'when url begins with a dash' do
+ let(:params) do
+ {
+ server: 'hkp://-pgp.mit.edu',
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a match})
+ end
+ end
+ context 'with invalid key' do
+ let :title do
+ 'Out of rum. Why? Why are we out of rum?'
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a match})
+ end
+ end
+
+ context 'with invalid source' do
+ let :params do
+ {
+ source: 'afp://puppetlabs.com/key.gpg',
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{evaluating a Resource})
+ end
+ end
+
+ context 'with invalid content' do
+ let :params do
+ {
+ content: [],
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a})
+ end
+ end
+
+ context 'with invalid server' do
+ let :params do
+ {
+ server: 'two bottles of rum',
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a match})
+ end
+ end
+
+ context 'with invalid options' do
+ let :params do
+ {
+ options: {},
+ }
+ end
+
+ it 'fails' do
+ is_expected.to raise_error(%r{expects a})
+ end
+ end
+
+ context 'with invalid ensure' do
+ ['foo', 'aabsent', 'absenta', 'apresent', 'presenta', 'refresh', 'arefreshed', 'refresheda'].each do |param|
+ let :params do
+ {
+ ensure: param,
+ }