mirror of
https://github.com/inspec/inspec
synced 2024-11-22 12:43:07 +00:00
add unit test for bond resource
This commit is contained in:
parent
7db6941219
commit
cf77e56118
3 changed files with 98 additions and 1 deletions
|
@ -1,4 +1,30 @@
|
|||
# encoding: utf-8
|
||||
|
||||
require 'minitest/autorun'
|
||||
require 'minitest/spec'
|
||||
|
||||
require 'vulcano/backend'
|
||||
|
||||
# loads a resource class and instantiates the class with the given arguments
|
||||
def loadResource (resource, *args)
|
||||
|
||||
# test mappings
|
||||
scriptpath = IO::File.realpath(IO::File.dirname(__FILE__))
|
||||
@mapping = {
|
||||
'/proc/net/bonding/bond0' => IO::File.join(scriptpath, '/unit/mock/bond0')
|
||||
}
|
||||
|
||||
# create mock backend
|
||||
conf = Vulcano::Backend.target_config({})
|
||||
backend_class = Vulcano::Backend.registry['mock']
|
||||
@backend = backend_class.new(conf, @mapping)
|
||||
|
||||
# load resource
|
||||
@rclass = Vulcano::Resource.registry[resource]
|
||||
|
||||
# merge arguments
|
||||
args = [@backend] | args
|
||||
|
||||
# initialize resource with backend and parameters
|
||||
@resource = @rclass.new(*args)
|
||||
|
||||
end
|
||||
|
|
37
test/unit/mock/bond0
Normal file
37
test/unit/mock/bond0
Normal file
|
@ -0,0 +1,37 @@
|
|||
Ethernet Channel Bonding Driver: v3.7.1 (April 27, 2011)
|
||||
|
||||
Bonding Mode: IEEE 802.3ad Dynamic link aggregation
|
||||
Transmit Hash Policy: layer3+4 (1)
|
||||
MII Status: up
|
||||
MII Polling Interval (ms): 100
|
||||
Up Delay (ms): 0
|
||||
Down Delay (ms): 0
|
||||
|
||||
802.3ad info
|
||||
LACP rate: fast
|
||||
Min links: 0
|
||||
Aggregator selection policy (ad_select): stable
|
||||
Active Aggregator Info:
|
||||
Aggregator ID: 1
|
||||
Number of ports: 1
|
||||
Actor Key: 9
|
||||
Partner Key: 29
|
||||
Partner Mac Address: 0d:4b:d1:26:32:0e
|
||||
|
||||
Slave Interface: eth0
|
||||
MII Status: up
|
||||
Speed: 100 Mbps
|
||||
Duplex: full
|
||||
Link Failure Count: 0
|
||||
Permanent HW addr: 2e:b7:8d:61:2c:51
|
||||
Aggregator ID: 1
|
||||
Slave queue ID: 0
|
||||
|
||||
Slave Interface: eth2
|
||||
MII Status: down
|
||||
Speed: Unknown
|
||||
Duplex: Unknown
|
||||
Link Failure Count: 0
|
||||
Permanent HW addr: 5a:57:54:66:38:64
|
||||
Aggregator ID: 2
|
||||
Slave queue ID: 0
|
34
test/unit/resource_bond_test.rb
Normal file
34
test/unit/resource_bond_test.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
# encoding: utf-8
|
||||
|
||||
require 'helper'
|
||||
require 'vulcano/resource'
|
||||
|
||||
describe 'Vulcano::Resources::Bond' do
|
||||
|
||||
describe 'parse bond config' do
|
||||
before do
|
||||
@resource = loadResource('bond', 'bond0')
|
||||
end
|
||||
|
||||
it 'bond must be available' do
|
||||
@resource.exists?.must_equal true
|
||||
end
|
||||
|
||||
it 'eth0 is part of bond' do
|
||||
_(@resource.has_interface?('eth0')).must_equal true
|
||||
_(@resource.has_interface?('eth1')).must_equal false
|
||||
_(@resource.has_interface?('eth2')).must_equal true
|
||||
end
|
||||
|
||||
it 'get all interfaces' do
|
||||
_(@resource.interfaces).must_equal ['eth0','eth2']
|
||||
end
|
||||
|
||||
it 'get proc content' do
|
||||
_(@resource.content).wont_equal nil
|
||||
_(@resource.content).wont_equal ''
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in a new issue