mirror of
https://github.com/inspec/inspec
synced 2024-11-26 22:50:36 +00:00
add bridge test for linux
This commit is contained in:
parent
90cf62d88e
commit
b2ed180885
3 changed files with 37 additions and 0 deletions
|
@ -56,6 +56,16 @@ class MockLoader
|
||||||
path = ::File.join(scriptpath, '/unit/mock/files', x)
|
path = ::File.join(scriptpath, '/unit/mock/files', x)
|
||||||
local.file(path)
|
local.file(path)
|
||||||
}
|
}
|
||||||
|
mockdir = lambda { |x|
|
||||||
|
md = Object.new
|
||||||
|
md.class.module_eval { attr_accessor :isDir }
|
||||||
|
md.isDir = x
|
||||||
|
def md.directory?
|
||||||
|
@isDir
|
||||||
|
end
|
||||||
|
md
|
||||||
|
}
|
||||||
|
|
||||||
mock.files = {
|
mock.files = {
|
||||||
'/proc/net/bonding/bond0' => mockfile.call('bond0'),
|
'/proc/net/bonding/bond0' => mockfile.call('bond0'),
|
||||||
'/etc/ssh/ssh_config' => mockfile.call('ssh_config'),
|
'/etc/ssh/ssh_config' => mockfile.call('ssh_config'),
|
||||||
|
@ -72,6 +82,7 @@ class MockLoader
|
||||||
'kitchen.yml' => mockfile.call('kitchen.yml'),
|
'kitchen.yml' => mockfile.call('kitchen.yml'),
|
||||||
'example.csv' => mockfile.call('example.csv'),
|
'example.csv' => mockfile.call('example.csv'),
|
||||||
'policyfile.lock.json' => mockfile.call('policyfile.lock.json'),
|
'policyfile.lock.json' => mockfile.call('policyfile.lock.json'),
|
||||||
|
'/sys/class/net/br0/bridge' => mockdir.call(true),
|
||||||
}
|
}
|
||||||
|
|
||||||
# create all mock commands
|
# create all mock commands
|
||||||
|
@ -148,6 +159,8 @@ class MockLoader
|
||||||
'9e80f048a1af5a0f6ab8a465e46ea5ed5ba6587e9b5e54a7a0c0a1a02bb6f663' => cmd.call('find-net-interface'),
|
'9e80f048a1af5a0f6ab8a465e46ea5ed5ba6587e9b5e54a7a0c0a1a02bb6f663' => cmd.call('find-net-interface'),
|
||||||
'c33821dece09c8b334e03a5bb9daefdf622007f73af4932605e758506584ec3f' => empty.call,
|
'c33821dece09c8b334e03a5bb9daefdf622007f73af4932605e758506584ec3f' => empty.call,
|
||||||
'Get-NetAdapter | Select-Object -Property Name, InterfaceDescription, Status, State, MacAddress, LinkSpeed, ReceiveLinkSpeed, TransmitLinkSpeed, Virtual | ConvertTo-Json' => cmd.call('Get-NetAdapter'),
|
'Get-NetAdapter | Select-Object -Property Name, InterfaceDescription, Status, State, MacAddress, LinkSpeed, ReceiveLinkSpeed, TransmitLinkSpeed, Virtual | ConvertTo-Json' => cmd.call('Get-NetAdapter'),
|
||||||
|
# bridge
|
||||||
|
'ls -1 /sys/class/net/br0/brif/' => cmd.call('ls-sys-class-net-br'),
|
||||||
}
|
}
|
||||||
|
|
||||||
# set os emulation
|
# set os emulation
|
||||||
|
|
2
test/unit/mock/cmd/ls-sys-class-net-br
Normal file
2
test/unit/mock/cmd/ls-sys-class-net-br
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
eth1
|
||||||
|
eth2
|
22
test/unit/resource_bridge_test.rb
Normal file
22
test/unit/resource_bridge_test.rb
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
# encoding: utf-8
|
||||||
|
# author: Christoph Hartmann
|
||||||
|
# author: Dominik Richter
|
||||||
|
|
||||||
|
require 'helper'
|
||||||
|
require 'vulcano/resource'
|
||||||
|
|
||||||
|
describe 'Vulcano::Resources::Bridge' do
|
||||||
|
|
||||||
|
it 'check linux bridge' do
|
||||||
|
resource = MockLoader.new(:ubuntu1404).load_resource('bridge', 'br0')
|
||||||
|
_(resource.exists?).must_equal true
|
||||||
|
|
||||||
|
# check network interfaced attached to bridge
|
||||||
|
_(resource.has_interface?('eth0')).must_equal false
|
||||||
|
_(resource.has_interface?('eth1')).must_equal true
|
||||||
|
_(resource.has_interface?('eth2')).must_equal true
|
||||||
|
|
||||||
|
# get associated interfaces
|
||||||
|
_(resource.interfaces).must_equal %w{eth1 eth2}
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue