-
Notifications
You must be signed in to change notification settings - Fork 936
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow using regexp for model_map and group_map keys
Use case is that the source returns string which has unrelated and variant data but the actual model is included somewhere in this data For example source could have space separated list of tags and one of these tags could be model name. Eg 'procurve switch'.
- Loading branch information
Showing
4 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require_relative '../spec_helper' | ||
require 'oxidized/source/source' | ||
|
||
describe Oxidized::Source do | ||
describe '#map_model' do | ||
before(:each) do | ||
Asetus.any_instance.expects(:load) | ||
Asetus.any_instance.expects(:create).returns(false) | ||
|
||
# Set :home_dir to make sure the OXIDIZED_HOME environment variable is not used | ||
Oxidized::Config.load({ home_dir: '/cfg_path/' }) | ||
yaml = %( | ||
juniper: junos | ||
!ruby/regexp /procurve/: procurve | ||
) | ||
Oxidized.config.model_map = YAML.unsafe_load(yaml) | ||
@source = Oxidized::Source::Source.new | ||
end | ||
|
||
it 'returns map value for existing string key' do | ||
_(@source.map_model('juniper')).must_equal 'junos' | ||
end | ||
|
||
it 'returns its argument for non-existing string key' do | ||
_(@source.map_model('ios')).must_equal 'ios' | ||
end | ||
|
||
it 'returns map value for existing regexp key' do | ||
_(@source.map_model('foo procurve1234 bar')).must_equal 'procurve' | ||
end | ||
end | ||
end |