Skip to content

Commit

Permalink
improve acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoblitt committed Jul 6, 2023
1 parent 597bde3 commit d8424cf
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 21 deletions.
45 changes: 40 additions & 5 deletions examples/connection.pp
Original file line number Diff line number Diff line change
@@ -1,16 +1,51 @@
nm::connection { 'test':
nm::connection { 'test1':
content => {
'connection' => {
'id' => 'test',
'type' => 'ethernet',
'interface-name' => 'test',
'id' => 'test1',
'type' => 'dummy',
'interface-name' => 'dummy1',
},
'ipv4' => {
'address1' => '10.10.10.10/24',
'method' => 'manual',
},
'ipv6' => {
'method' => 'disable',
'method' => 'ignore',
},
},
}

nm::connection { 'test2':
content => {
'connection' => {
'id' => 'test2',
'type' => 'dummy',
'interface-name' => 'dummy2',
},
'ipv4' => {
'address1' => '10.20.20.20/24',
'method' => 'manual',
},
'ipv6' => {
'method' => 'ignore',
},
},
}

nm::connection { 'test3':
# lint:ignore:strict_indent
content => @(NM),
[connection]
id=test3
type=dummy
interface-name=dummy3

[ipv4]
address1=10.30.30.30/24
method=manual

[ipv6]
method=ignore
| NM
# lint:endignore
}
10 changes: 9 additions & 1 deletion examples/connection_absent.pp
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
nm::connection { 'test':
nm::connection { 'test1':
ensure => 'absent',
}

nm::connection { 'test2':
ensure => 'absent',
}

nm::connection { 'test3':
ensure => 'absent',
}
94 changes: 88 additions & 6 deletions spec/acceptance/connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

require 'spec_helper_acceptance'

# rubocop:disable RSpec/RepeatedExampleGroupBody
describe 'nm::connection' do
context 'connection' do
include_examples 'the example', 'connection.pp'

it_behaves_like 'an idempotent resource'

describe file('/etc/NetworkManager/system-connections/test.nmconnection') do
describe file('/etc/NetworkManager/system-connections/test1.nmconnection') do
it { is_expected.to be_file }
it { is_expected.to be_owned_by 'root' }
it { is_expected.to be_grouped_into 'root' }
Expand All @@ -19,28 +20,109 @@
# THIS FILE IS CONTROLLED BY PUPPET
[connection]
id=test
type=ethernet
interface-name=test
id=test1
type=dummy
interface-name=dummy1
[ipv4]
address1=10.10.10.10/24
method=manual
[ipv6]
method=disable
method=ignore
CONTENT
end
end

describe interface('dummy1') do
it { is_expected.to have_ipv4_address('10.10.10.10/24') }
end

describe file('/etc/NetworkManager/system-connections/test2.nmconnection') do
it { is_expected.to be_file }
it { is_expected.to be_owned_by 'root' }
it { is_expected.to be_grouped_into 'root' }
it { is_expected.to be_mode '600' } # serverspec does not like a leading 0

its(:content) do
is_expected.to match <<~CONTENT
# THIS FILE IS CONTROLLED BY PUPPET
[connection]
id=test2
type=dummy
interface-name=dummy2
[ipv4]
address1=10.20.20.20/24
method=manual
[ipv6]
method=ignore
CONTENT
end
end

describe interface('dummy2') do
it { is_expected.to have_ipv4_address('10.20.20.20/24') }
end

describe file('/etc/NetworkManager/system-connections/test3.nmconnection') do
it { is_expected.to be_file }
it { is_expected.to be_owned_by 'root' }
it { is_expected.to be_grouped_into 'root' }
it { is_expected.to be_mode '600' } # serverspec does not like a leading 0

its(:content) do
is_expected.to match <<~CONTENT
[connection]
id=test3
type=dummy
interface-name=dummy3
[ipv4]
address1=10.30.30.30/24
method=manual
[ipv6]
method=ignore
CONTENT
end
end

describe interface('dummy3') do
it { is_expected.to have_ipv4_address('10.30.30.30/24') }
end
end

context 'connection absent' do
include_examples 'the example', 'connection_absent.pp'

it_behaves_like 'an idempotent resource'

describe file('/etc/NetworkManager/system-connections/test.nmconnection') do
describe file('/etc/NetworkManager/system-connections/test1.nmconnection') do
it { is_expected.not_to exist }
end

describe interface('dummy1') do
it { is_expected.not_to exist }
end

describe file('/etc/NetworkManager/system-connections/test2.nmconnection') do
it { is_expected.not_to exist }
end

describe interface('dummy2') do
it { is_expected.not_to exist }
end

describe file('/etc/NetworkManager/system-connections/test3.nmconnection') do
it { is_expected.not_to exist }
end

describe interface('dummy3') do
it { is_expected.not_to exist }
end
end
end
# rubocop:enable RSpec/RepeatedExampleGroupBody
9 changes: 0 additions & 9 deletions spec/support/acceptance/setup.rb

This file was deleted.

0 comments on commit d8424cf

Please sign in to comment.