Skip to content

Commit

Permalink
Fix errors while reviewing PR
Browse files Browse the repository at this point in the history
- we don't need mutex_m as we have a newer version of minitest
  • Loading branch information
robertcheramy committed Jan 9, 2025
1 parent edb782b commit b248ab8
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 19 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
- input/ssh: change input.debug to dump all characters and include sent commands. (@robertcheramy)
- cumulus: remove ANSI Escape codes and fix prompt issues. The prompt is more specific now (@alchemyx, @robertcheramy)
- model unit tests: the tests are automated and simpler to use (@ytti, @robertcheramy)
- device2yaml.rb: moved to extras, commands can be specified from the command line or from a file (no cmdsets provided anymore) (@robertcheramy)
- device2yaml.rb: moved to extra/, commands can be specified from the command line or from a file (no cmdsets provided anymore) (@robertcheramy)

### Fixed
- tplink: send 'enable' before the enable password. Fixes #3271 (@robertcheramy)
Expand Down
4 changes: 2 additions & 2 deletions docs/DeviceSimulation.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ editors automatically remove trailing spaces, so we code them with \x20.

Although a YAML file could be written by hand, this is quite a tedious task to
catch all the extra codes and code them into YAML. This can be automated with
the Ruby script [extras/device2yaml.rb](/extras/device2yaml.rb).
the Ruby script [extra/device2yaml.rb](/extra/device2yaml.rb).

`device2yaml.rb` needs Ruby and the gem
[net-ssh](https://rubygems.org/gems/net-ssh/) to run. On Debian, you can install
them with `sudo apt install ruby-net-ssh`.

Run `extras/device2yaml.rb`, the online help tells you the options.
Run `extra/device2yaml.rb`, the online help tells you the options.
```
oxidized$ extra/device2yaml.rb
Missing a host to connect to...
Expand Down
2 changes: 1 addition & 1 deletion docs/Issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ sudo apt install git ruby-net-ssh
```
git clone [email protected]:<your github user>/oxidized.git
```
- run the extras/device2yaml.rb script (you’ll be provided with the command to
- run the `extra/device2yaml.rb` script (you’ll be provided with the command to
run) from the repository root:

```
Expand Down
2 changes: 1 addition & 1 deletion docs/ModelUnitTests.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Model Unit Tests
Oxidized includes automated unit tests for its model, which require very little
Oxidized includes automated unit tests for its models, which require very little
effort to use. There are three different unit tests for models:
- [Device Simulation](ModelUnitTests.md#device-simulation)
- [Device Prompt](ModelUnitTests.md#device-prompt)
Expand Down
1 change: 0 additions & 1 deletion oxidized.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ Gem::Specification.new do |s|
s.add_development_dependency 'git', '~> 2'
s.add_development_dependency 'minitest', '~> 5.25.4'
s.add_development_dependency 'mocha', '~> 2.1'
s.add_development_dependency 'mutex_m'
s.add_development_dependency 'pry', '~> 0.15.0'
s.add_development_dependency 'rake', '~> 13.0'
s.add_development_dependency 'rubocop', '~> 1.69.0'
Expand Down
64 changes: 52 additions & 12 deletions spec/model/atoms.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Automatic Trivial Oxidized Model Spec - ATOMS
# Tries to simplify model testing for the simple/common case
# Simple model testing for the simple/common case
class ATOMS
DIRECTORY = File.join(File.dirname(__FILE__), 'data').freeze
class ATOMSError < StandardError; end
Expand Down Expand Up @@ -28,6 +28,7 @@ def self.get(klass, glob)
end
end

# Abstract Class for loading test data
class Test
class TestError < ATOMSError; end
attr_reader :model, :desc, :type
Expand Down Expand Up @@ -69,11 +70,11 @@ def load_file(type = nil)
#
# The files are stored under ATOMS::DIRECTORY (spec/model/data) and follow the
# naming convention:
# - YAML Simulation: model:description:simulation.yaml
# - Expected Output: model:description:output.txt
# - YAML Simulation File: model:description:simulation.yaml
# - Expected Output: model:description:output.txt
#
# "description" is the name of the test case and is generally formatted as
# #hardware_#software or #model_#hardware_#software_#description.
# #hardware_#software or #model_#hardware_#information.
#
# The test is skipped if one of the files is missing.
class TestOutput < Test
Expand All @@ -98,16 +99,14 @@ def generate(result_engine)
end
end

# Support class for loading prompts to test as part of the model unit tests.
# Extends ATOMS::Test to support tests that pass or must fail
#
# The prompts are loaded from files stored under
# ATOMS::DIRECTORY (spec/model/data) and follow the naming convention:
# - model:description:prompt.yaml
#
# "description" is generally named 'generic', as all prompts for a model
# can be stored into as single YAML file.
# The tests are read from a YAML file, which contains two attributes:
# - pass: data for tests that should pass
# - fail: data for tests that should fail
#
# The test is skipped if the YAML file could not be loaded.
# Each attribute contains a list of the data to test. These lists are stored
# in the instance variables @data['pass'] and @data['fail']
class TestPassFail < Test
GLOB = false # this is not an actual test, but a parent for prompt/secret
attr_reader :data
Expand All @@ -128,6 +127,26 @@ def fail
end
end

# Support class for loading prompts to test against the models.
#
# The prompts are loaded from files stored in the directory specified by
# ATOMS::DIRECTORY (spec/model/data) and follow the naming convention:
# model:description:prompt.yaml
#
# "description" is generally named 'generic', as all prompts for a model
# can be stored in a single YAML file.
#
# The test is skipped if the YAML file cannot be loaded.
#
# The tests are read from a YAML file, which contains three attributes:
# - pass: regexps that should pass
# - pass_with_expect: regexps that should pass after the expect commands
# have been run
# - fail: regexps that should fail (without expect commands)
#
# Each attribute contains a list of the regexps to test. These lists are
# stored in the instance variables @data['pass'], @data['pass_with_expect'],
# and @data['fail'].
class TestPrompt < TestPassFail
GLOB = '*:prompt.yaml'.freeze
def initialize(model, desc, type = 'prompt')
Expand All @@ -141,6 +160,27 @@ def pass_with_expect
end
end

# Support class for loading strings used to test the secret feature of the
# models.
#
# The test data is loaded from YAML files stored in the directory specified by
# ATOMS::DIRECTORY (spec/model/data) and follows the naming convention:
# model:description:secret.yaml
#
# "description" is the name of the test case and is generally formatted as
# #hardware_#software or #model_#hardware_#information. It must match the
# name of the corresponding YAML simulation file.
#
# The test is skipped if the YAML file cannot be loaded.
#
# The YAML file contains two attributes, each with a list of strings that
# should be present or absent in the output of the model when the secret
# feature is active:
# - pass: strings that should be present (replaced by secret)
# - fail: strings that should be absent (removed by secret)
#
# These lists are stored in the instance variable @data['pass'] and
# @data['fail'].
class TestSecret < TestPassFail
GLOB = '*:secret.yaml'.freeze
attr_reader :output_test
Expand Down
3 changes: 2 additions & 1 deletion spec/model/atoms_generate.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require_relative 'model_helper'

# FIXME: refactor result generation/init_model_helper so that we don't need to run it inside test
# We use empty tests because we need the mock / stub feature of minitest/mocha
# to simulate SSH in order to generate the output
describe('') do
it('') do
ATOMS.get(ATOMS::TestOutput, '*:simulation.yaml').each do |test|
Expand Down

0 comments on commit b248ab8

Please sign in to comment.