-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugins: Test harness, test fixture, docs, and local-type example #356
Merged
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b089042
Rename train-gem-fixture to train-test-fixture
clintoncwolfe 2a38731
Update test fixture plugin to support platform forcing and basic conn…
clintoncwolfe 7451be7
First draft of docs and examples
clintoncwolfe 7d9e779
train-test-fixture feature complete
clintoncwolfe 2f472ee
Top-level files for train-local-rot13
clintoncwolfe 2a906a9
Unit tests pass
clintoncwolfe e057109
Add fixture files
clintoncwolfe 9a03772
Another bonkers plugin helper.
clintoncwolfe 5807deb
Passing functional tests
clintoncwolfe ffa3590
Enable using Train project rubocop config
clintoncwolfe d9c6816
Linting
clintoncwolfe 1910356
PR feedback
clintoncwolfe f2af2fb
Correct unit test expected value
clintoncwolfe c2727ad
Add plugin transport doc info.
jquick 4c8072f
Fix feedback.
jquick d1f3c07
Fix lint issues. And disable UTF-8 force since its forced on ruby 2.0.
jquick 53f56ec
Fix ruby 2.2 heredoc format.
jquick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,11 +77,11 @@ Required. Use the `name` call to register your plugin. Pass a String, which sho | |
|
||
#### `option` DSL method | ||
|
||
TODO | ||
The option method is used to register new information into your transport options hash. This hash contains all the information your transport will need for its connection and runtime support. These options calls are a good place to pull in defaults or information from environment variables. | ||
|
||
#### @options Instance Variable | ||
|
||
TODO | ||
This variable includes any options you passed in from the DSL method when defining a transport. It will also merge in any options passed from the URL definition for your transport (schema, host, etc). | ||
|
||
#### `connection` abstract method | ||
|
||
|
@@ -93,28 +93,57 @@ The your Connection class must inherit from `Train::Plugins::Transports::BaseCon | |
|
||
#### initialize | ||
|
||
TODO | ||
Not required but is a good place to set option defaults for options that were passed with the transport URL. Example: | ||
|
||
```Ruby | ||
def initialize(options) | ||
# Override for cli region from url host | ||
# aws://region/my-profile | ||
options[:region] = options[:host] if options.key?(:host) | ||
super(options) | ||
end | ||
``` | ||
|
||
#### run_command_via_connection | ||
|
||
TODO | ||
If your transport is OS based and has the option to read a file you can set this method. It is expected to return a `Train::File::Remote::*` class here to be used upstream in InSpec. Currently the file resource is restricted to Unix and Windows platforms. Caching is enabled by default for this method. | ||
|
||
#### file_via_connection | ||
|
||
TODO | ||
If your transport is OS based and has the option to run a command you can set this method. It is expected to return a `CommandResult` class here to be used upstream in InSpec. Currently the command resource is restricted to Unix and Windows platforms. Caching is enabled by default for this method. | ||
|
||
#### API Access Methods | ||
|
||
TODO | ||
When working with API's it's often helpful to create methods to return client information or API objects. These are then accessed upstream in InSpec. Here is an example of a API method you may have: | ||
|
||
```Ruby | ||
def aws_client(klass) | ||
return klass.new unless cache_enabled?(:api_call) | ||
@cache[:api_call][klass.to_s.to_sym] ||= klass.new | ||
end | ||
``` | ||
|
||
This will return a class and cache the client object accordingly if caching is enabled. You can call this from a inspec resource by calling `inspec.backend.aws_client(AWS::TEST::CLASS)`. | ||
|
||
#### local? | ||
|
||
TODO | ||
This flag helps Train decide what detection to use for OS based platforms. This should be set to `true` if your transport target resides in the same instance you are running train from. This setting is not needed for API transports or transports who do not use platform detection. | ||
|
||
#### platform | ||
|
||
`platform` is called when InSpec is trying to detect the platform (OS family, etc). We recommend that you implement platform in a separate Module, and include it. | ||
|
||
### Platform Detection | ||
|
||
TODO | ||
Platform detection is used if you do not specify a platform method for your transport. Currently it is only used for OS (Unix, Windows) platforms. The detection system will run a series of commands on your target to try and determine what platform it is. This information can be found here [OS Specifications](https://github.com/inspec/train/blob/master/lib/train/platforms/detect/specifications/os.rb). | ||
|
||
When using a API or a fixed platform for your transport its suggested you skip the detection process and specify a direct platform. Here is an example: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
```Ruby | ||
def platform | ||
Train::Platforms.name('Aws').in_family('cloud') | ||
force_platform!('Aws', | ||
release: '1.2', | ||
) | ||
end | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love the anthropomorphism, but might go with
that do not use
here.