From cf77e56118b67717563d89abdc6cfec3133cb0fc Mon Sep 17 00:00:00 2001 From: Christoph Hartmann Date: Thu, 3 Sep 2015 17:33:19 +0200 Subject: [PATCH] add unit test for bond resource --- test/helper.rb | 28 ++++++++++++++++++++++++- test/unit/mock/bond0 | 37 +++++++++++++++++++++++++++++++++ test/unit/resource_bond_test.rb | 34 ++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 test/unit/mock/bond0 create mode 100644 test/unit/resource_bond_test.rb diff --git a/test/helper.rb b/test/helper.rb index e7c86f879..aba203f9c 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -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 diff --git a/test/unit/mock/bond0 b/test/unit/mock/bond0 new file mode 100644 index 000000000..17720559c --- /dev/null +++ b/test/unit/mock/bond0 @@ -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 diff --git a/test/unit/resource_bond_test.rb b/test/unit/resource_bond_test.rb new file mode 100644 index 000000000..bcee693fe --- /dev/null +++ b/test/unit/resource_bond_test.rb @@ -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