diff --git a/spec/model/arubainstant_spec.rb b/spec/model/arubainstant_spec.rb index 95a505502..55ef09685 100644 --- a/spec/model/arubainstant_spec.rb +++ b/spec/model/arubainstant_spec.rb @@ -5,8 +5,7 @@ it 'removes secrets' do Oxidized.config.vars.remove_secret = true - test = ATOMS::TestOutput.new('arubainstant', 'IAP515_8.10.0.6_VWLC') - cfg = MockSsh.get_result(self, test).to_cfg + cfg = MockSsh.get_result(self, 'IAP515_8.10.0.6_VWLC').to_cfg _(cfg).wont_match(/AAAAAAAAAABBBBBBBBBBCCCCCCCCCC/) _(cfg).must_match(/snmp-server host 10.10.42.12 version 2c inform/) diff --git a/spec/model/garderos_spec.rb b/spec/model/garderos_spec.rb index 4a0918268..58381a17e 100644 --- a/spec/model/garderos_spec.rb +++ b/spec/model/garderos_spec.rb @@ -3,7 +3,7 @@ describe 'model/Garderos' do before(:each) do init_model_helper - @node = MockSsh.get_node('garderos') + @node = MockSsh.get_node end it 'matches different prompts' do diff --git a/spec/model/ios_spec.rb b/spec/model/ios_spec.rb index 6363372ac..03d4e53c5 100644 --- a/spec/model/ios_spec.rb +++ b/spec/model/ios_spec.rb @@ -5,8 +5,7 @@ it 'removes secrets' do Oxidized.config.vars.remove_secret = true - test = ATOMS::TestOutput.new('ios', 'C9200L-24P-4G_17.09.04a') - cfg = MockSsh.get_result(self, test).to_cfg + cfg = MockSsh.get_result(self, 'C9200L-24P-4G_17.09.04a').to_cfg _(cfg).wont_match(/SECRET/) _(cfg).wont_match(/public/) @@ -15,8 +14,7 @@ it 'removes secrets from IOS-XE WLCs' do Oxidized.config.vars.remove_secret = true - test = ATOMS::TestOutput.new('ios', 'C9800-L-F-K9_17.06.05') - cfg = MockSsh.get_result(self, test).to_cfg + cfg = MockSsh.get_result(self, 'C9800-L-F-K9_17.06.05').to_cfg _(cfg).wont_match(/SECRET_REMOVED/) _(cfg).wont_match(/REMOVED_SECRET/) diff --git a/spec/model/model_helper.rb b/spec/model/model_helper.rb index c60d38fd0..91075d72b 100644 --- a/spec/model/model_helper.rb +++ b/spec/model/model_helper.rb @@ -35,15 +35,22 @@ def result2file(result, filename) # Class to Simulate Net::SSH::Connection::Session class MockSsh - def self.get_node(model) + def self.caller_model + File.basename(caller_locations[1].path).split('_').first + end + + def self.get_node(model = nil) + model ||= caller_model Oxidized::Node.new(name: 'example.com', input: 'ssh', model: model) end - def self.get_result(context, test) + def self.get_result(context, test_or_desc) + test = test_or_desc + test = ATOMS::TestOutput.new(caller_model, test_or_desc) if test_or_desc.is_a?(String) @node = get_node(test.model) - mockmodel = MockSsh.new(test) + mockmodel = MockSsh.new(test.simulation) Net::SSH.stubs(:start).returns mockmodel status, result = @node.run context._(status).must_equal :success # rubocop:disable Minitest/GlobalExpectations @@ -51,9 +58,8 @@ def self.get_result(context, test) end # Takes a yaml file with the data used to simulate the model - def initialize(test) + def initialize(model) @commands = {} - model = test.simulation model['commands'].each do |key, value| @commands[key + "\n"] = interpolate_yaml(value) end